Reputation: 11
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.
Upvotes: 1
Views: 50
Reputation: 85530
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.
Upvotes: 2