Linux which command to find files using

  

Linux which command belongs to the search command, it will be used when you want to find a file, the following with the small series to understand the specific command under Linux Usage, interested friends may wish to find out.

effect which command is specified in the PATH variable path, searches the position of a system command, and returns a search result first. In other words, using the which command, you can see if a system command exists and which command is executed.

1. Command format:

which executable file name

2. Command Function:

Which command searches for the location of a system command in the path specified by the PATH variable and returns the first search result.

3. Command Parameters:

-n Specifies the length of the file name. The specified length must be greater than or equal to the longest file name in all files.

-p Same as the -n parameter, but here is the path to the file.

-w Specifies the width of the field at the time of output.

-V Display version information

4. Use case:

Instance 1: Find file, display command path

Command:

which lsmod

Output:

[root @localhost ~]# which pwd

/bin/pwd

[root@localhost ~]# which adduser

/usr/sbin/adduser

[root@localhost ~]#

Description:

which is to search for executable files based on the directory in the PATH variable configured by the user! Therefore, the commands found by different PATH configuration contents are of course different!

Example 2: Use which to find out which

command:

which which

output:

[root@localhost ~ ]# which which

alias which=‘alias |  /usr/bin/which --tty-only --read-alias --show-dot --show-tilde’

/usr/bin/which

[root@localhost ~ ]#

Description:

There will be two which, one of which is alias. This is the so-called "command alias", which means that input which will be equal to the following sequence of commands!

Example 3: This command cd find

command:

which cd

Output:

Description: < Br>

cd This commonly used command can't be found! why? This is because cd is a built-in bash command! But which default is to find the directory specified in the PATH, so of course not found!

The above is the usage of the which command under Linux. The search command under Linux is not limited to this command. There are other commands that can be used to find the file location. The usage of different commands is slightly different.

Copyright © Windows knowledge All Rights Reserved