find-finds files

 <  Day Day Up  >  

find ”finds files

 find pathnamelist expression 

find recursively descends the directory hierarchy for each pathname in the pathname list (i.e., one or more pathnames) seeking files that match options. The first argument is the path where the search starts. The rest of the arguments specify some criteria by which to find the files, such as name, size , owner, permissions, and so on. Check the UNIX manual pages for different syntax.

Example A.27.
 1   find . -name \*.c -print 2   find .. -type f -print 3   find . -type d -print 4   find / -size 0 - exec rm "{}" \; 5   find ~ -perm 644 -print 6   find . -type f -size +500c -atime +21 -ok rm -f "{}" \; 7   find . -name core -print 2> /dev/null  (Bourne and Korn Shells)  (find . -name core -print > /dev/tty) >& /dev/null  (C shell)  8   find / -user ellie xdev -print 9   find ~ -atime +31 -exec mv {} /old/{} \; -print 

EXPLANATION

  1. Starting at the present working directory (dot), finds all files ending in .c and prints the full pathname of the files.

  2. Starting at the parent directory (dot dot), finds all files of type file (i.e., files that are not directories).

  3. Starting at the present directory (dot), finds all directory files.

  4. Starting at the root directory, finds all files of size 0 and removes them. The {} are used as a placeholder for the name of each file as it is found.

  5. Starting at the user's home directory ~ (Korn and C shells), finds all files that have permissions 644 (read and write for the owner, and read permission for the group and others).

  6. Starting at the present working directory, finds files that are over 500 bytes and have not been accessed in the last 21 days and asks if it is okay to remove them.

  7. Starting at the present working directory, finds and displays all files named core and sends errors to /dev/null , the UNIX bit bucket.

  8. Prints all files on the root partition that belong to user ellie .

  9. Moves files that are older than 31 days into a directory, /old , and prints the files as it moves them.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net