find Howto
info find vela zujimavych info
find . -name 'jak?b' najde v suc dir jak?b
find . -mtime -1 najde v suc dir subory ktory boli modifikovane v
predoslych 24 h (mtime, ctime, atime) modify (write) change (write+attrib set)
access (pristup read)
find . -ctime +8 -ctime -10 najde subory ktore boli menene v intervale (8;10) den
find . -name '*' -printf "%p\t%m\t%U\t%G\n" vytlaci menosuboru\tmode\tUID\tGUID
find / -user jakub najde vsetky subory usera jakub v /
find / -uid 500 \( -path '/home/jakub' -prune -or -print \) najde vsetky subory uid 500 ale nebude hladat v /home/jakub
Celkom cool script na zbalenie html suborov
#!/bin/sh
case $1 in
1)
find . -name '*.html' -exec gzip {} \;
for i in `find . -name '*.html.gz'`
do
echo $i
mv -f $i `echo $i | sed -e 's/\.html\.gz/\.ghtml/'`
done
;;
0)
for i in `find . -name '*.ghtml'`
do
mv -f $i `echo $i | sed -e 's/\.ghtml/\.html\.gz/'`
done
find . -name '*.html.gz' -exec gzip -d {} \;
;;
*)
echo "Usage: $0 {1,0}"
echo "Description: Gzip (gunzip) html files in current directory"
exit 0
;;
esac
Find and types
find . -type f -- all regular files
find . -type d -- all directories
find . -type l -- all symlinks
for more see man
Find and permissions
find . -perm -ug=x -- all what has x for user AND group
find . -perm +ug=x -- all what has x for user OR group
the above line can be written as
find . -perm -u=x -or -perm -g=x
Using OR in statements
the above for regular files notice that we have to write type twice
find . -type f -perm -u=x -or -type f -perm -g=x
the same goes for AND -a NOT -not etc.
Yet another funny example
#!/bin/sh
#this two are equal
#find / -type f -perm +ug=s -exec ls -l {} \;
#find / -type f -perm -4000 -exec ls -l '{}' ';' -or \
#-type f -perm -2000 -exec ls -l '{}' ';'
WHAT=$1
if [ -z $WHAT ] ;then
WHAT=/
fi
find $WHAT -type f -perm +ug=s -printf "%m " -exec ls -l {} \;
or watch this use in Makefiles - it deletes all regular files and symlinks in wd not of the selected names
clean:
find . -not \( -iname '*.pl' -or -iname '*.c' -or -iname '*.h' -or -iname 'makefile' -or -name '..' -or -name '.' -or -iname '*.sh' \) \( -type f -or -type l \) -maxdepth 1 -print -exec rm {} \;