We know that almost all of the native Linux commands are located in ‘/usr/bin’ & ‘/usr/sbin’. And the third party software generally installs their files in “/opt” directory. Sometimes it happens that we are not able to run the command because PATH is not set for it and we want to find in which directory it is residing or we want to find any files by the name we remember. In this tutorial, we will see how to find any command on Linux servers.
How To Find Any Commands in Linux Servers
This is one my favourite command to find any string, file or command by its name. It finds everything with the keyword you gave. Below is one example where I tried to find ‘passwd‘.
As per the output, it found all the files containing name passwd. So, if I am looking for passwd command, it has given me many options and this is the only disadvantage of this command according to me and you can use other commands instead. But, if you are looking for some files, then this disadvantage becomes the advantage as it looks for all the files having that keyword.
[[email protected] ~]# locate passwd | head /etc/passwd /etc/passwd- /etc/pam.d/passwd /etc/security/opasswd /usr/bin/gpasswd /usr/bin/grub2-mkpasswd-pbkdf2 /usr/bin/kpasswd /usr/bin/lppasswd /usr/bin/passwd /usr/bin/smbpasswd
This command belongs to RPM called “mlocate“. If you do not have that rpm, install it and try the locate command today.
This is a very useful command which will give you the exact full path of the command. Means you will get the exact location of the command. Just copy and run it.
Below is the example, where I tried to locate passwd.
[r[email protected] ~]# which passwd /bin/passwd [[email protected] ~]#
This command belongs to RPM called “which“. Just search your YUM repo and install it.
This is more advance command than which and locates the binary, source and manual files for the specified command names. In below example, I have used which command, so it has located the location of binary and its man page location.
[[email protected] ~]# whereis which which: /usr/bin/which /usr/share/man/man1/which.1.gz [[email protected] ~]# [[email protected] ~]# whereis -b which which: /usr/bin/which [[email protected] ~]#
This command is part of “util-linux” rpm.
This command is one of the most used commands in Linux and Unix based systems and is used to search for files in a directory. It has many options and you can almost find any files by its type, size, date of access, etc. It is like advance search.
Below is the example, where I tried to search for ‘passwd’.
[[email protected] ~]# find / -name passwd find: ‘/run/user/1000/gvfs’: Permission denied /sys/fs/selinux/class/passwd /sys/fs/selinux/class/passwd/perms/passwd /etc/passwd /etc/pam.d/passwd /usr/bin/passwd /usr/share/bash-completion/completions/passwd [[email protected] ~]#
By default, this command is present on all Linux system but if it is not, just install “findutils” rpm. I will cover one complete post on “find” command, explaining its widely used switches. So, do not forget to subscribe.
5. rpm -ql RPM_name
‘RPM’ is also a very useful command to know which file belongs to which RPM and which rpm contains which files. So, now if we know the rpm name for the command which we are looking for, we can know its exact location by using rpm command as shown below in the example.
[[email protected] ~]# rpm -ql passwd | head /etc/pam.d/passwd /usr/bin/passwd /usr/share/doc/passwd-0.79 /usr/share/doc/passwd-0.79/AUTHORS
This command belongs to ‘rpm’ package, which comes preinstalled on all the Linux machines.
Check the below video which shows you the complete tutorial in action and do not forget to like the video and subscribe to my channel for more videos.
I am sure, this article would have given you some tips on how to search or locate any command on Linux servers. Similarly, using few of the above commands you can search any files. Generally, in Linux, everything is a file. This tutorial can also help in your RHCSA & RHCE exam.
Hope you will share this article with your friends. If you have any doubts, questions or suggestions, please leave the comment below. Once again do not forget to subscribe.