In this article, we’re going to look at some useful way to find the files in Linux operating system.
Basically Linux Operating system have multiple directories which is used for different purposes. So it’s quite difficult to search the files within it.
To search the files in a Linux operating system, there is wonderful utility which is named as FIND.
There are some other utilities as well which is given below.
Now we’re going to search a file name called “passwd” on the server.
#find / -name “passwd”
Here this command will search the “passwd” file on the server root directory. It don’t required to mention / always, if you’ve little idea where the file may located.
#find /etc -name “passwd”
The advantage and disadvantage is, the find command will go through the entire file system. The search results may get delay, if you’ve any NFS mount points which is shared from other server.
[root@server ~]# find / -name "passwd" /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 /home/user/.vnc/passwd [root@server ~]# [root@server ~]# find /etc -name "passwd" /etc/passwd /etc/pam.d/passwd [root@server ~]#
Note: Here -name is used to check the file/directory which is named as a passwd. You will multiple exciting options to run the find utility.
To use other options in find utility, Please view the man pages “Tests” section.
You will get a options like atime, executable, nouser and etc.
atime – File was last accessed in last 24 hours ago.
executable – File/Directory which is having execution permission.
nouser – File which doesn’t belongs to any user.
There is also an another commands to find the binary files in the Operating System.
[root@server ~]# which passwd /bin/passwd [root@server ~]# whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz [root@server ~]#
Here which command will provide the result, where is binary file is located. And the whereis command will provide the result of entire environment of the passwd.
Another command is search the files in the operating system is locate.
[root@server ~]# locate nsswitch /etc/nsswitch.conf /etc/nsswitch.conf.bak /etc/nsswitch.conf.rpmnew /usr/share/man/man5/nsswitch.conf.5.gz /var/lib/authconfig/last/nsswitch.conf [root@server ~]#
Here the locate command will look for the string “nsswitch” on all the files/directories.
The important command which we all should know about the locate.
[root@server ~]# touch unixtechnocloud [root@server ~]# ls unixtechnocloud [root@server ~]# locate unixtechnocloud [root@server ~]#
Here I’ve created a file with name of “unixtechnocloud” but locate command unable to find the newly created file.
Because the locate command uses the database which needs to refreshed to get the new files/directories. By default, the updatedb command will be running by every one day (24 hours).
To do the same, use below command.
[root@server ~]# updatedb [root@server ~]# locate unixtechnocloud /root/unixtechnocloud [root@server ~]#