Вы находитесь на странице: 1из 2

UNIX FIND Command Examples 1 To list all files in the file system with a given base file name,

ty pe: find / -name .profile -print This searches the entire file system and writes the complete path na mes of all files named .profile. The / (slash) tells the find command to search the root directory and all of its subdirectories. In order not to waste time, it is best to limit the search by specifying the directories where you thi nk the files might be. 2 To list files having a specific permission code in the current direc tory tree, type: find . -perm 0600 -print This lists the names of the files that have only owner-read and owne r-write permission. The . (dot) tells the find command to search the current dir ectory and its subdirectories. See the chmod command for an explanation of permission codes. 3 To search several directories for files with certain permission code s, type: find manual clients proposals -perm -0600 -print This lists the names of the files that have owner-read and owner-wri te permission and possibly other permissions. The manual, clients, and proposals directories and their subdirectories are searched. In the previous e xample, -perm 0600 selects only files with permission codes that match 0600 exac tly. In this example, -perm -0600 selects files with permission codes tha t allow the accesses indicated by 0600 and other accesses above the 0600 level. This also matches the permission codes 0622 and 2744. 4 To list all files in the current directory that have been changed du ring the current 24-hour period, type: find . -ctime 1 -print 5 To search for regular files with multiple links, type: find . -type f -links +1 -print This lists the names of the ordinary files (-type f) that have more than one link (-links +1). Note: Every directory has at least two links: the ent ry in its parent directory and its own . (dot) entry. The ln command expla ins multiple file links. 6 To find all accessible files whose path name contains find, type: fi nd . -name '*find*' -print 7 To remove all files named a.out or *.o that have not been accessed f or a week and that are not mounted using nfs, type: find / \( -name a.out -o -na me '*.o' \) -atime +7 ! -fstype nfs -exec rm {} \; Note: The number used within the -atime expression is +7. This is th e correct entry if you want the command to act on files not accessed for more th an a week (seven 24-hour periods). 8 To print the path names of all files in or below the current directo ry, except the directories named SCCS or files in the SCCS directories, type: fi nd . -name SCCS -prune -o -print To print the path names of all files in or below the current directo

ry, including the names of SCCS directories, type: 9 find . -print -name SCCS -prune To search for all files that are exactly 414 bytes long, type:

find . -size 414c -print 10 To find and remove every file in your home directory with the .c suf fix, type: find /u/arnold -name "*.c" -exec rm {} \; Every time the find command identifies a file with the .c suffix, th e rm command deletes that file. The rm command is the only parameter specified f or the -exec expression. The {} (braces) represent the current path name. 11 In this example, dirlink is a symbolic link to the directory dir. Yo u can list the files in dir by refering to the symbolic link dirlink on the comm and line. To do this, type: find -H dirlink -print 12 In this example, dirlink is a symbolic link to the directory dir. To list the files in dirlink, traversing the file hierarchy under dir including an y symbolic links, type: find -L dirlink -print 13 To determine whether the file dir1 referred by the symbolic link dir link is newer than dir2, type: find -H dirlink -newer dir2 Note: Because the -H flag is used, time data is collected not from d irlink but instead from dir1, which is found by traversing the symbolic link. 14 1. To produce a listing of files in the current directory in ls form at with expanded user and group name, type : 15 find . -ls -long To list the files with ACL/EA set in current directory, type: find . -ea

Вам также может понравиться