Linux Find directory file name directive

Source: Internet
Author: User
Tags control characters

the PWD command displays the user's current working directory as an absolute path. command to write the full path name of the current directory (from the root directory) to standard output. All directories are used/delimited. The first/represents the root directory, and the last directory is the current directory. The PWD command immediately learns the absolute path name of the working directory where you are currently located.

The tree command lists the contents of the directory
Tree (option)
-A : Displays all files and directories;
-A: Use Asni drawing characters to display the tree instead of the ASCII character combination;
C: In the list of files and directories to add color, easy to distinguish between various types;
-D: First directory name instead of content;
-D: Lists the time the file or directory was changed;
-F: Displays the full relative path name before each file or directory;
-F: In the execution of files, directories, sockets, symbolic connections, pipe name names, respectively plus "*", "/", "@", "|" No.

-G: Lists the name of the group to which the file or directory belongs, and when there is no corresponding name, the group identifier is displayed;
-I: Do not list file and directory names in ladder form;
-l:< template Style > file or directory name that does not display the symbol template style;
-L: If you encounter a directory with a symbolic connection, directly list the original directory that the connection points to;
-N: Do not add color to the list of files and directories;
-N: Lists file and directory names directly, including control characters;
-P: Lists the permission marks;
-p:< template style > show only file and directory names that conform to the template style;
-Q: With "? "Number replaces the control character, listing the file and directory name;
- S: Lists file and directory sizes;

-T: Sorts the file and directory change times;
-U: Lists the name of the owner of the file or directory, and displays the user ID when there is no corresponding name;
-X: Limits the scope to the current file system, and if certain subdirectories under the specified directory are stored on another file system, the directory is excluded from the search scope

the which command is used to find and display the absolute path of a given command.environment variable The directory that you need to traverse when you save the Find command in path. The which directive looks for eligible files in the directory where the environment variable $path is set. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.

Which is to search for a running file based on the directory within the PATH variable configured by the user! Therefore, the different PATH configuration content found the command of course not the same!

the path of the Whereis command used to locate instructions for the binaries, source code files, and man manual pages, and other related files。 The Whereis command can only be used for program name searches, and only binary files (parameter-B), man description file (parameter-m), and source code file (parameter-s) are searched. If the argument is omitted, all information is returned. Whereis looks very fast compared to find, because the Linux system records all the files in the system in a single database file, and when you use Whereis and the locate described below, the data is looked up from the database, not like the Find command, By traversing the hard drive to find, the efficiency will naturally be very high. However, the database file is not updated in real time and is updated once a week by default, so when we use Whereis and locate to find files, we sometimes find data that has been deleted, or just created the file, but cannot find it because the database file is not updated.

whereis (option)
- B: Only binary files are found;
-b< directory;: Find binary files only in the directory you set;
-F: The path name before the file name is not displayed;
-M: Find only documentation;
-m< directory;: Find the description file only in the directory of the settings;
-S: Find only the original code file;
-s< directory > Find the original code file only in the directory of the settings;
-U: Finds files that do not contain the specified type.


the Find command is used to locate files under the specified directory. Any string that precedes the parameter will be treated as the name of the directory you want to find. If you use this command without setting any parameters, the Find command looks for subdirectories and files under the current directory. and displays all the subdirectories and files that are found.
Find (Options)
-amin< minutes;: Finds files or directories that have been accessed at a specified time, measured in minutes;
-anewer< reference file or directory;: Find its access time more closely to the current file or directory than the specified file or directory;
-atime<24 hours;: Finds files or directories that have been accessed at a specified time, in 24-hour terms;
-cmin< minutes;: Finds files or directories that have been changed at the specified time;-cnewer< reference files or directories > Find them change time more closely to the current file or directory than the specified file or directory;
-ctime<24 hours;: Finds files or directories that have been changed at a specified time, measured in 24 hours;
-daystart: Calculate the time from today;
-depth: Start searching from the deepest subdirectory under the specified directory;
-expty: Look for files with a file size of 0 byte, or empty directories without any subdirectories or files in the directory;
-exec< execution instruction;: If the return value of the Find command is true, execute the instruction;
-false: Sets the callback value of the Find command to false;
-fls< list file: The effect of this parameter is similar to specifying the "-ls" parameter, but saves the result as a specified list file;
-follow: Exclude symbolic connections;
-fprint< list file: The effect of this parameter is similar to specifying the "-print" parameter, but the result is saved to the specified list file;
-fprint0< list file: The effect of this parameter is similar to specifying the "-print0" parameter, but the result is saved to the specified list file;
-fprintf< list file >< output format: The effect of this parameter is similar to specifying the "-printf" parameter, but the result is saved to the specified list file;
-fstype< file system type;: Only look for files or directories under the file system type;

-gid< group identification Code;: Find files or directories that match the specified group ID;
-group< Group name: Find a file or directory that matches the specified group name;
-help or--help: online help;
-ilname< template style;: This parameter has the same effect as specifying the "-lname" parameter, but ignores the difference in the case of the character;
-iname< template style;: This parameter has the same effect as specifying the "-name" parameter, but ignores the difference in the case of the character;
-inum: Finds a file or directory that matches the specified inode number;
-ipath< template style;: This parameter has the same effect as specifying the "-path" parameter, but ignores the difference in the case of the character;
-iregex< template style;: This parameter has the same effect as specifying the "-regexe" parameter, but ignores the difference in the case of the character;
-links< number of connections;: Find files or directories that match the specified number of hard connections;
-iname< template style;: Specifies a string as the template style for searching for symbolic connections;
-ls: Assuming that the return value of the Find command is ture, the file or directory name is listed to the standard output;
-maxdepth< directory hierarchy;: Set the maximum directory level;
-mindepth< directory hierarchy;: Set the minimum directory level;
-mmin< minutes;: Finds files or directories that have been changed at a specified time, measured in minutes;
-mount: The effect of this parameter is the same as specifying "-xdev";
-mtime<24 hours;: Find files or directories that have been changed at a specified time, measured in 24 hours;
-name< template style;: Specifies a string as a template style for searching for a file or directory;
-newer< reference file or directory;: Find changes time more closely to the current file or directory than the specified file or directory;
-nogroup: Find files or directories that do not belong to the local landlord group identification code;
-noleaf: Do not consider the directory must have at least two hard connections exist;
-nouser: Find files or directories that do not belong to the local host user identification code;
-ok< execution instructions; the effect of this parameter is similar to specifying "-exec", but the user is asked before executing the instruction, and if "Y" or "Y" is answered, the execution of the command is discarded;
-path< template style;: Specifies the string as the template style for the search directory;
-perm< permission value;: Find the file or directory that matches the specified permission value;
-print: Assuming that the return value of the Find directive is ture, the file or directory name is listed to standard output. The format is a name for each column, with a "./" string before each name;
-print0: Assuming that the return value of the Find directive is ture, the file or directory name is listed to standard output. All names are in the same line;
-printf< output format: Assuming that the return value of the Find directive is ture, the file or directory name is listed to standard output. The format can be specified by itself;
-prune: Do not look for a string as a template to find a file or directory style;
-regex< template style;: Specifies a string as a template style for searching for a file or directory;
-size< file size;: Find files that match the specified file size;
-true: Sets the callback value of the Find command to true;
-typ< file type;: Only files that match the specified file type are found;
-uid< user identification Code;: Find a file or directory that matches the specified user ID;
-used< days;: Find files or directories that have been accessed at a specified time after a file or directory has been changed, and the units are calculated on a daily basis;
-user< name of the owner;: a file or directory with a finder and a specified owner name;
-version or--version: Displays version information;
-xdev: Confine the scope to the first file system;
-xtype< file type;: The effect of this parameter is similar to specifying the "-type" parameter, except that it checks for symbolic connections.

-atime +n/-n:access time to access or execute files that are greater than/less than n days
-ctime +n/-n:change Time Write, change inode properties (for example, change owner, permissions, or links)
-mtime +n/-n:modified Time writes more than/less than n days of files


The stat command can be used to list atime, CTime, and mtime of files.

'-name filename ' directly finds the file name of the file, this option is used a lot.
[[email protected] ~]# find. -name test2
./test/test2
./test2
-type filetype is found by file type. The file type contains F, B, C, D, L, S, and so on.
[Email protected] ~]# find/tmp/-type D
/tmp/
/tmp/. Ice-unix
/tmp/test


both the Locate command and the Slocate command are used to locate files or directories.
The locate command is actually another way of find-name, but much faster than the latter because it does not search for a specific directory, but instead searches for a database/var/lib/locatedb, which contains all the local file information. The Linux system automatically creates this database and updates it automatically once a day, so you can't find the latest changed files using the Locate command. To avoid this situation, you can manually update the database by using the UpdateDB command before using locate

Locate/slocate (option)
-d< directory > or--database=< directory;: Specifies the directory where the database resides;
-U: Update slocate database;
--help: Display Help;
--version: Displays version information.

Linux Find directory file name directive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.