AIX 5L Basics (Unit 13) – AIX Utilities – Part 1

find – search one or more directory structures for files
find path expression
find . -name filename – the period ‘.’ represents the current directory

The ‘exec’ option executes a command on each file found
find . -name ‘m*’ -exec ls -l {} \;

\; – end of the -exec command
{} – matched filenames
\ – have the shell ignore the wild card and let the find command interpret it

find . -name m\* -ok rm {} \;
? y
? n

-type f – ordinary file
-type d – directory

-size +n – larger than n
-size -n – smaller than n
-size n – equal to n blocks (1 block = 512K)

-mtime +x – modified more than x days ago
-mtime -x – modified less than x days ago

-perm onum – acess permissions match ‘onum’
-perm mode – access permissions match ‘mode’ values (rwx)

-user – user finds files owned by “user”
-o – logical or (find . -name ‘s*’ -o -name ‘p*’
-newer ref.file – searches the files that are newer than the reference file

Shell verses find
————————

Shell interprets wild cards:
————————————–
ls c* – searches only current directory

find interprets wild cards:
————————————
find . -name ‘c*’ – searches all directories below and including the current
find . -name c\* – the backslash makes the shell ignore the wild card

find . -name ‘s*’ -type f -size +2 -exec ls -l {} \;
find . -perm 644 -mtime +4 -print
644 = rw-r–r–

find . -name fleas -o -name misc
find / -name ‘security’ -print 2>errfile

Leave a Reply

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

*