find excluding whole or partial paths (like grep -v)

” | wc -l ” to show the number of files found

[root@titan ~]# find / -iname ‘*.tgz’ | wc -l

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “backups*” | wc -l

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “b*” | wc -l

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “x*” | wc -l

OR with -prune ( ignore a directory and the files under it )

find / -name “backup” -prune -o -name ‘.pdf’ -print

find / -path /backups -prune -o -iname *?.rpm?* find all your rpmnew and rpmsave files but ignore your backup directory

find / -name “.tgz” -print -o -path ‘/home’ -prune -print -o -path ‘/www’ -prune

find . -iname “.pdf” -print -o -path “Accounts” -prune

this works as well

find / -name “.tgz” -o -path ‘/home’ -prune -o -path ‘/www’ -prune -o -path ‘/backups’ -prune

‘/home’ excludes home and anything under it.

‘*/www’ excludes any path with www in it.

Find and Copy with xargs

find . -name *.log -print0 | xargs -I{} -0 cp -v {} /tmp/log-files

Find and Move with xargs

find /mnt/cloud_drive/tarballs/./* -size -14M -print0 | xargs -0 -I {} mv -iv {} /path/to/new/dir

Leave a Reply

Your email address will not be published. Required fields are marked *