Changes

Jump to navigation Jump to search
1,162 bytes added ,  08:59, 13 March 2009
adds find example with prune and shell redirection
arg_count=$#
for (( i=1; i <= $arg_count; i++ )); do
arg="$1" shift 1 if [ -z "$pattern" ]; then if [ "$arg" == "--" ]; then grepargs="$grepargs $arg" pattern="$1" shift 1 ((i++)) elif [ "${arg:0:1}" != "-" ]; then pattern="$arg" else grepargs="$grepargs $arg" fi else pathargs="$pathargs $arg" fi
done
echo "Finished fixing websites"
echo
</source>
 
Sometimes when using find, you end up with "Permission denied" errors that add noise to your output. There are a couple solutions for this. Use the '''prune''' option to skip entire trees that you should avoid (e.g. /proc). Use shell redirection to ignore remaining error messages (e.g. 2>/dev/null).
 
The following example searches all of my hard drive starting at / but skips over the backups directory I have in my external disk drive and also skips over the "process" directory. Any errors like files in /var that I do not have permission to see are discarded by redirecting STDERR to the bitbucket.
<source lang="bash">
find / -path /media/disk/backups -prune -o -path /proc -prune -o -type d -name soffice.cfg 2>/dev/null
/home/greg/.openoffice.org2/user/config/soffice.cfg
/home/greg/.openoffice/1.1.1/user/config/soffice.cfg
/home/greg/.openoffice.org/3/user/config/soffice.cfg
/home/greg/spidey2/.openoffice.org2/user/config/soffice.cfg
/home/greg/liberty/greg/.openoffice.org2/user/config/soffice.cfg
/home/greg/liberty/greg/.openoffice/1.1.1/user/config/soffice.cfg
/opt/openoffice.org/basis3.0/share/config/soffice.cfg
/usr/lib/openoffice/basis3.0/share/config/soffice.cfg
/proc
/media/disk/backups
</source>
4,558

edits

Navigation menu