Linux Shell] [Find command or file under Linux

We can easily find in Windows Explorer in the appropriate file, and indeed do it under Linux GUI (such as GNOME's "File" you can find the appropriate file), then we can not pass the command line to find it? of course can.

 

A. Find Bash Shell built-in command

In order to facilitate the action of the shell, Bash shell is already integrated with many commands, such as: cd, ls, history, umask and so on.

These commands are not in the form of a script file on your hard drive, so you direct search is not search in the directory tree , you want to see if a command is a Bash built by typing:

type command

Then he will tell you whether this command is a Bash shell built-in.

( Actually, using bash csdn insert the code can also be judged, you go write command, if bash is built, it will highlight; if it is the hard disk of binary commands exist, then it is not highlighted )

 

II. Find script file

In addition to the Bash Shell built-in command, almost all commands are in the form of a script file exists on your hard disk.

The reason why you can execute commands quickly, because the absolute path of the corresponding script file has been added to your PATH, shell be able to find and execute your script file by PATH .

So, if we want to find such a script file, as long as the search path set in the PATH line. Corresponding command is:

which command

 

III. Finding the appropriate file

A very well-known Linux command to find files is find, however, in addition to slow, find also affect disk performance

In general, we use about two commands to find the appropriate documents, they are:

  1.  whereis: Find files in a specific directory .
  2. locate: According to the database to find files .

In both cases can not be found, we use find.

(1). whereis 

Let's talk about whereis, the so-called specific directory can be viewed by clicking the command:

# 如果你真的执行了这个,你会发现这些目录是有bin man src三个分类的
whereis -l

Find the appropriate file method is relatively simple, and that is:

whereis filename

(2). locate

The database is used to locate the corresponding file to find, there is the database / var / lib / mlocate in.

In general, this is a day to update the database, you can force him updated by updatedb command.

The way to find files and whereis exactly the same (except that you can use regular expressions ):

locate filename

 

IV. Use find to find files

Finally, we want to find is the most powerful, we use this to find the Linux file folder.

It is noteworthy that not only can find to find files by name, but also according to permissions, size, modification time to find out.

Before I always thought that learning will fall to learn thoroughly, of course, now I do not think so, the most important thing is to talk about the most common thing engraved in the bones.

So here only search for files in a given file name with the find.

You have to know the difference and find before speaking locate and whereis, its usage pattern is:

find [PATH] [OPTION] [MODE]

If you want to search for the file name of the corresponding file, mode:

find PATH -name filename [ACTION]

And two command before an important difference is that he has to specify the search path.

Another noteworthy place is ACTION, this is a what is it? A simple example to explain:

find / -perm /7000 -exec ls -l {} \;

Wherein, ACTION it is defined as the -exec \; the entire contents of the intermediate . find results speak to be put in {}.

So this command simply lists the root directory permissions to 7000 files.

发布了137 篇原创文章 · 获赞 19 · 访问量 1万+

Guess you like

Origin blog.csdn.net/qq_43338695/article/details/103845031