[Linux learning] Commands and file and directory search

Command and file and directory lookup

1. Command search

1.1 which

Format: which -a command. For example which -a ifconfig

[root@www ~]# which ifconfig

This command is mainly used to find the location of the corresponding command from the directory in the PATH system variable. Since the PATH system variables configured by different users are different, the results found vary from user to user. In addition, some built-in commands may not be found using this command.

2. File and directory search

2.1 whereis

Format: whereis -bmsu file or directory

[root@www ~]# whereis ifconfig

-b : only look for files in binary format

-m : only look for files under the manual help folder

-s : only look for source source files

-u : Find other special files other than the above 3

It should be noted that the search command searches for the corresponding file or directory in the database of the Linux system, which is faster.

2.2 locate

Format: locate -ri full or partial names of files and directories or regular expressions

-r : Find files and directories corresponding to regular expressions

-i : ignore case lookup

Also similar to the whereis command, the search is also based on the database, but because the update of the database is different and the time is deterministic, sometimes the search fails or the search for invalid files occurs because the database is not updated. deleted, etc.).

2.3 find

Format:

find path -mtime +n/-n/n action

find path -atime +n/-n/n action

find path -ctime +n/-n/n action

find path -newer file

find path -user user

find path -name filename

find path +/- size file size

find path -type f/d/b/l/s/p ( f file, d directory, b device file, l link file, ssocket file, p pipe)

find path perm mode (find files whose file permissions are only mode )

find path - perm mode (find files whose file permissions are limited by mode )

find path +perm mode ( find files whose file permissions include any permission limited by mode )

Among them, +n represents n days ago, -n represents within n days, and n represents nth day. Combined with mtime/atime/ctime, you can get files modified in a specific time period.

The action is: -exec action command \; .

[root@www ~]# find / -name passwd -exec ls -al {} \;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325733798&siteId=291194637