Pawan Bahuguna

Let's Learn and Share
Menu
  • Home
  • Books
    • Free Books
    • RHEL 7 Books
  • Practice Papers
  • Tools
    • Responsive Checker
  • Scripts
  • Contact
  • Privacy

Preparing for RHCSA or RHCE Certification? >>> Check RHEL 7 : RHCSA & RHCE Practice Papers

YES, Show Me Sample Papers.
Home
Linux
5 Ways To Find Any Commands in Linux Servers
Linux

5 Ways To Find Any Commands in Linux Servers

Pawan Bahuguna

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

 

How To Find Any Commands in Linux Servers

 

1. locate

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.

Advertisements

 

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# 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.

 

2. which

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.

 

1
2
3
[root@localhost ~]# which passwd
/bin/passwd
[root@localhost ~]#

 

This command belongs to RPM called “which“. Just search your YUM repo and install it.

 

3. whereis

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.

 

1
2
3
4
5
6
7
[root@localhost ~]# whereis which
which: /usr/bin/which /usr/share/man/man1/which.1.gz
[root@localhost ~]#
 
[root@localhost ~]# whereis -b which
which: /usr/bin/which
[root@localhost ~]#

 

This command is part of “util-linux” rpm.

 

4. find

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’.

 

1
2
3
4
5
6
7
8
9
[root@localhost ~]# 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
[root@localhost ~]#

 

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.

 

1
2
3
4
5
[root@localhost ~]# 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.

 

SUBSCRIBE NOW

 

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.

Show your love by Sharing:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to share on Telegram (Opens in new window)
  • Click to print (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to share on Skype (Opens in new window)
  • Click to share on Pocket (Opens in new window)
Share
Pinterest
Linkedin
Tweet
Google+
Stumble
Email
Prev Article
Next Article

Related Articles

Red Hat Released RHEL 7.4
Red Hat has made its enterprise level server Red Hat …

Red Hat Released RHEL 7.4 with Improved Security & Performance

RHEL 7 Syllabus
From many days after we published our article on RHEL …

RHEL 7 Syllabus for RHCSA & RHCE

Tags:Fun With Linux How To Linux Linux Basics Redhat Redhat Certification RHCE RHCSA Tips Tutorial

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 

Find a domain starting at $0.48

powered by Namecheap

Like Our Book

Like Our Book

Lets Connect

Subscribe Below & Get RHEL 7 EXAM TIPS eBook

GET eBOOK NOW!

We don’t spam! Read our privacy policy for more info.

Check your inbox or spam folder to confirm your subscription.

  • Popular
  • Recent

Pawan Bahuguna

Let's Learn and Share
Copyright © 2021 Pawan Bahuguna
Home | Privacy Policy | Contact
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.