CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
find |
find [pathnames] [conditions] An extremely useful command for finding particular groups of files (numerous examples follow this description). find descends the directory tree beginning at each pathname and locates files that meet the specified conditions. The default pathname is the current directory. The most useful conditions include -print (which is the default if no other expression is given), -name and -type (for general use), -exec and -size (for advanced users), and -mtime and -user (for administrators). Conditions may be grouped by enclosing them in ( ) (escaped parentheses), negated with ! (use ! in the C shell), given as alternatives by separating them with -o, or repeated (adding restrictions to the match; usually only for -name, -type, -perm). Modification refers to editing of a file's contents. Change refers to modification, permission or ownership changes, and so on; therefore, for example, -ctime is more inclusive than -atime or -mtime. Conditions and actions-atime +n n n Find files that were last accessed more than n (+n), less than n (-n), or exactly n days ago. Note that find changes the access time of directories supplied as pathnames. -ctime +n n n Find files that were changed more than n (+n), less than n (-n), or exactly n days ago. A change is anything that changes the directory entry for the file, such as a chmod. -depth Descend the directory tree, skipping directories and working on actual files first (and then the parent directories). Useful when files reside in unwritable directories (e.g., when using find with cpio). -exec command Run the Linux command, from the starting directory on each file matched by find (provided command executes successfully on that file; i.e., returns a 0 exit status). When command runs, the argument substitutes the current file. Follow the entire sequence with an escaped semicolon (;). -follow Follow symbolic links and track the directories visited (don't use this with -type l). -group gname Find files belonging to group gname. gname can be a group name or a group ID number. -inum n Find files whose inode number is n. -links n Find files having n links. -mount, -xdev Search for files that reside only on the same filesystem as pathname. -mtime +n n n Find files that were last modified more than n (+n), less than n (-n), or exactly n days ago. A modification is a change to a file's data. -name pattern Find files whose names match pattern. Filename metacharacters may be used but should be escaped or quoted. -newer file Find files that have been modified more recently than file; similar to -mtime. Affected by -follow only if it occurs after -follow on the command line. -ok command Same as -exec but prompts user to respond with y before command is executed. -perm nnn Find files whose permission flags (e.g., rwx) match octal number nnn exactly (e.g., 664 matches -rw-rw-r--). Use a minus sign before nnn to make a 'wildcard' match of any unspecified octal digit (e.g., -perm -600 matches -rw-******, where * can be any mode). Print the matching files and directories, using their full pathnames. Return true. -regex pattern Like -path but uses grep-style regular expressions instead of the shell-like globbing used in -name and -path. -size n[c] Find files containing n blocks, or if c is specified, n characters long. -type c Find files whose type is c. c can be b (block special file), c (character special file), d (directory), p (fifo or named pipe), l (symbolic link), s (socket), or f (plain file). -user user Find files belonging to user (name or ID). -daystart Calculate times from the start of the day today, not 24 hours ago. -maxdepth num Do not descend more than num levels of directories. -mindepth num Begin applying tests and actions only at levels deeper than num levels. -noleaf Normally, find assumes that each directory has at least two hard links that should be ignored (a hard link for its name and one for '.'; i.e., two fewer 'real' directories than its hard link count indicates). -noleaf turns off this assumption, a useful practice when find runs on non-Unix-style filesystems. This forces find to examine all entries, assuming that some might prove to be directories into which it must descend (a time-waster on Unix). -amin +n n n Find files last accessed more than n (+n), less than n (-n), or exactly n minutes ago. -anewer file Find files that were accessed after file was last modified. Affected by -follow when after -follow on the command line. -cmin +n n n Find files last changed more than n (+n), less than n (-n), or exactly n minutes ago. -cnewer file Find files that were changed after they were last modified. Affected by -follow when after -follow on the command line. -empty Continue if file is empty. Applies to regular files and directories. -false Return false value for each file encountered. -fstype type Match files only on type filesystems. Acceptable types include minix, ext, ext2, xia, msdos, umsdos, vfat, proc, nfs, iso9660, hpfs, sysv, smb, and ncpfs. -gid num Find files with numeric group ID of num. -ilname pattern A case-insensitive version of -lname. -iname pattern A case-insensitive version of -name. -ipath pattern A case-insensitive version of -path. -iregex pattern A case-insensitive version of -regex. -lname pattern Search for files that are symbolic links, pointing to files named pattern. pattern can include shell metacharacters and does not treat / or . specially. The match is case-insensitive. -mmin +n n n Find files last modified more than n (+n), less than n (-n), or exactly n minutes ago. -nouser The file's user ID does not correspond to any user. -nogroup The file's group ID does not correspond to any group. -path pattern Find files whose names match pattern. Expect full pathnames relative to the starting pathname (i.e., do not treat / or . specially). ExamplesList all files (and subdirectories) in your home directory: find $HOME -printList all files named chapter1 in the /work directory: find /work -name chapter1 -printList all files beginning with memo owned by ann: find /work -name 'memo*' -user ann -printSearch the filesystem (begin at root) for manpage directories: find / -type d -name 'man*' -printSearch the current directory, look for filenames that don't begin with a capital letter, and send them to the printer: find . ! -name '[A-Z]*' -exec lpr ;Find and compress files whose names don't end with .gz: gzip `find . ! -name '*.gz' -printRemove all empty files on the system (prompting first): find / -size 0 -ok rm ;Search the system for files that were modified within the last two days (good candidates for backing up): find / -mtime -2 -printRecursively grep for a pattern down a directory tree: find /book -print | xargs grep '[Nn]utshell'If the files kt1 and kt2 exist in the current directory, their names can be printed with the command: $ find . -name 'kt[0-9]'./kt1 ./kt2 Since the command prints these names with an initial ./ path, you need to specify the ./ when using the -path option: $ find . -path './kt[0-9]'./kt1 ./kt2 The -regex option uses a complete pathname, like -path, but treats the following argument as a regular expression rather than a glob pattern (although in this case the result is the same): $ find . -regex './kt[0-9]'./kt1 ./kt2 |
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 577
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved