![]() ![]() Using +10 means “older than 10 days” and -5 means “younger than 5 days, etc., e.g. The -mtime expression allows you to give a modify time expression. The -user expression allows you to give a userid that must be the owner of the pathnames found, e.g. The basename patterns can include shell-GLOB-style path metacharacters such as * and ?, and the patterns must be quoted to protect them from GLOB expansion by the shell, e.g. The -name expression allows you to give a matching pattern that is the basename, found in any directory, starting from each of the starting_directories. With modern versions of find, you can omit the -print keyword it’s the default behaviour. Without any expression, find finds all pathnames. name 'basename', -size +100M, -print, or -ls. It consists of keywords, each preceded by dashes and usually followed by some argument, e.g. The expression limits the pathnames that are found or changes the output format. The optional expression must follow the starting directories. If you don’t specify any startdir, find uses. list in which to search comes first, followed by the optional expression that says what to find. only pathnames with a size greater than some numberĢ.only pathnames modified within some number of days.only pathnames owned by a particular userid.only pathnames containing a particular basename pattern.all pathnames under a list of starting directories.The expressions follow the starting directories on the command line.īelow are five important uses of find, each explained in detail. The find command has its own huge set of expressions for finding pathnames precisely and efficiently. You rarely need to use any options, so the first thing following the find command name is usually the one directory or list of directories in which to look. The is an optional list of starting directories in which find will do the search, instead of using the current directory. The Usage line for find given below is abbreviated from man find: Usage: find 2 Five common ways to use the find command Index To find pathnames by anything other than name, e.g. size, or owner, or modify date (etc.), use the find command with the right expression. If the pathname has existed for some time and is saved in the right database, you might be able to use the faster locate or slocate commands to search by name. To find pathnames by name you can use the find command. ![]() ![]() The fgrep command searches content inside files, it doesn’t find the names of files. You can tell fgrep to search the contents of an entire directory tree of files by turning on the fgrep “recursive” option but, that won’t help you find the name of a pathname in that directory. (To use fgrep to find the full name of a pathname, you would first have to use some other command to generate a list of all pathnames and feed that to fgrep in a pipeline as standard input – see the example below.) They aren’t directly useful for finding and generating the names of those pathnames. The fgrep (and grep and egrep) commands look for patterns or text inside files whose names you already know. People confuse fgrep, which looks for text inside files (and doesn’t look at the file names), with find, which finds files by name (and doesn’t look inside the files). What if we don’t know which directory that file is located in?Ĭan we start a fgrep at the root and ask the fgrep command to look in all subdirectories? ![]()
0 Comments
Leave a Reply. |