SoFunction
Updated on 2025-03-10

Search file command in Linux

File search command locate: Search fast, new files cannot be searched;

Command format: locate file name //Search by file name in the background database, the search speed is fast;

/var/lib/mlocate : The background database searched by the locate command

Command: updatedb // Update the database, the default is to automatically update it one day;

In the /etc/ configuration file:

1.      PRUNE_BIND_MOUNTS = “yes”

Turn on search restrictions

2.      PRINEFS =

File system that is not searched for when searching;

3.      PRUNEFNAMES =

The type of file that is not searched for when searching;

4.      PRUNEFATHS =

When searching, the path not searched;

Command search command:

Command format: whereis file name //The path where the search command is located and the location of the help document is located;

Options:

-b: Find only executable files

-m: Find only help documents

Command format: which file name //Search the path and alias where the command is located

PATH environment variable: defines the path of the system search command;

root@sd-ThinkCentre-XXXX:/#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

Command: whoami: Who is the current user?

Command: whats ls: What is this command for

File search command find

The size of a sector is 512K

find command: find [Search scope] [Search conditions] File name //Search for files;

eg :find  /  -

Note: Large-scale search of leather surfaces will consume system resources

Find searches for file names that meet the criteria in the system, and if a match is required, use wildcard characters. Wildcards are exact matches;

Wildcards in Linux:

1.      *  Match any content;

Eg: find /root –name ana*  // It means to match files starting with "ana";

find /root –name*   // means to find all files under /root

2.      ? Match any character;

find  /root –name ab?   //Match the file with three characters starting with ab;

3. [] Match the characters in any brackets of the person;

find/root –name ab[cd] //Match a file starting with ab and containing three characters of one of [cd];

Command find /root –iname    //No need to distinguish the case of file names

Command find /root –user root   //Search the file by the owner of the file

Command find /root –nouser   // Find files without owner

Command find /var/log/ -mtime +10   // Find files modified 10 days ago

1.     -10 Files Modified within 10 days

2.        10   Documents modified on the same day

3.      +10  Files modified 10 days ago

4.         atime file access time

5.       ctime  Change file properties

6.        mtime Modify the file content

Command find /etc  -size 25k  // Find files with file size of 25k

1.     -25k Files less than 25k

2. 25k file equal to 25k

3.       +25M Files greater than 25M

Command find /etc –inum 130958 // Find a file whose i node is 140958

Command find /etc –size +20k –a –size -50k //Search files that are larger than 20kb and smaller than 50kb in the /etc/ directory

1.       -a  and logic and, both conditions are met;

2. –o or logical or, only if one of the two conditions is satisfied;

The command find/etc –size +20k –a –size -15k –exec ls –lh {}\  //Find files larger than 20kb and smaller than 50kb in the /etc/ directory, and display detailed information;

// -exec command {} \  Perform an operation on the search results;

The above is the search file command in Linux introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!