1

I need to write a bash-script which will find all files with name string.h on the computer and copy them to some folder. My code is here:

#!/bin/bash

sudo find / -type f -name "string.h" -exec cp {} $HOME/MyDocuments \;

But during the execution of the script, I get error-messages on my console terminal "permission denied". How I can avoid getting this message? Console terminal must be clear.

0

1 Answer 1

2

Suppress the error messages from stderr(2) to the NULL stream designated by /dev/null

sudo find / -type f -name "string.h" -exec cp "{}" $HOME/MyDocuments \; 2 > /dev/null

where the 2 in the above line stands for file descriptor.


I would personally recommend you to investigate the actual cause of the issue rather than suppressing it. Do the above only if you are absolutely sure that the errors are trivial.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.