In Linux, there are many ways to do this. LinuxHaxor has compiled five commands to see if you know them. Most programmers, who probably use two or three of these commands regularly, are unlikely to be familiar with all five.
1. find
Find is the most common and powerful find command, and you can use it to find any file you want.
Find is used in the following format:
$find < specify directory > < specify condition > < specify action >
– < Specify directory > : the directory to search for and all its subdirectories. The default is the current directory.
– < Specify criteria > : characteristics of the file to be searched.
– < Specify action > : performs specific processing on the search results.
If nothing is added, find defaults to searching the current directory and its subdirectories and does not filter any results (that is, returning all files), displaying them all on the screen.
Examples of using find:
$ find . -name ‘my*’
Search for all files whose names start with my in the current directory (including subdirectories, same below).
$ find . -name ‘my*’ -ls
Search for all files in the current directory whose file names start with my and display their details.
$ find . -type f -mmin -10
Search the current directory for all regular files that have been updated in the last 10 minutes. If the -type f parameter is not specified, the system searches for common files, special files, and directories.
2. locate
The locate command is actually a variant of “find-name”, but it is much faster because it does not search a directory. Instead, it searches a database (/var/lib/locatedb) that contains information about all files locally. Linux automatically creates the database and updates it daily, so you can’t find the most recently changed files using the locate command. To avoid this, manually update the database using the updatedb command before using LOCATE.
Example Of the locate command:
$ locate /etc/sh
Search for all files starting with sh in the etc directory.
$ locate ~/m
Search for all files starting with M in the user’s home directory.
$ locate -i ~/m
Search for all files starting with M in the user’s home directory, and ignore case.
3. whereis
The whereis command can only be used to search for program names, and only binary files (parameter -b), man description files (parameter -m), and source code files (parameter -s) are searched. If the argument is omitted, all information is returned.
An example of the whereis command is:
$ whereis grep
4. which
The which command searches for the location of a system command in the PATH specified by the PATH variable and returns the first search result. That is, using the which command, you can see whether a system command exists and which location of the command was executed.
Example of the which command:
$ which grep
5. type
The type command is not really a look-up command. It is used to distinguish between commands that come with the shell and those provided by separate binaries outside the shell. If a command is an external command, the -p argument displays the path to the command, equivalent to the which command.
Example Of the type command:
$ type cd
CD is the build-in command of the shell.
$ type grep
Grep is an external command and the command path is displayed.
$ type -p grep
With the -p argument, it is equivalent to the which command.
Learn more about Python at gzitcast