Command Line Tools

In Linux world everything is file. Linux system is managed through the several configuration files. Most of configuration files have associated documentation file or sample file. You can use sample files in exam. For RHCE exam you should be able to find the file. It is very common to forget the path of file during the exam. You may know the name of file but not path in that case use these commands to find the file.

  • find
  • locate

find

find command need two arguments file name and location. Syntax of find command is

#find [location] -name  [file name ]
  • find :- command
  • location :- where you want to search the file
  • -name :- option to specify the file name
  • file name :- name of file which you want to search

For example to search vsftpd.conf [FTP configuration file] file we would use following command

#find / -name vsftpd.conf

This would start search from top level root directory and list the found.

find vsftpd

Searching from root directory should be your last resources. When you perform search form root directory find command scan the entire Linux system for the desired file. It is time consuming process. Use subdirectories whenever you know it. For example if we know that vsftpd.conf file is located in /etc directory we should use following command

#find /etc -name vsftpd.conf

find vsftpd conf

find command accepts wildcard. Wildcard allows us to find a file even we know only few characters of file name. For example our desired file starts from vs and have .conf in the end but we do not know the middle characters. In this case we would find it in following way

#find /etc -name vs*.conf

find vsftpd from wildcards

Wildcards

* Any number of alphanumeric characters
? Single alphanumeric characters

Example of wildcards

Create a directory and move in it

find create directory

Make some blank files for practice of find command. Use touch command to create files.

touch

Find the files those start from f and end with .conf

It would returns with following error

find: paths must precede expression

find error

find command expand the wild card while it parse. So if result contain single match it would return without any error. Like in above example we searched for vs*.conf and it returned with correct result. But if result contains more than one match it would return with find: paths must precede expression error. It is because what find parsing in this case will look like

#find /root/practices_of_find  -name file1.conf  filek.conf

how to solve find: paths must precede expression error

solution of find: paths must precede expression error is very simple. Put the file name in quotes. It would stop the shell (bash) expanding your wildcards.

find wild card

Find the files which

  • have file in staring
  • later one character could be anything
  • ends with .conf

find with wild card

locate

find command is too time consuming specially in 2 hour RHCE exam. use locate command instead of find in exam. locate command use a database of installed files and directories. locate command database updated only once in a day.
Syntax of locate command is following

#locate [file name]

locate command search form its database so it does not require path.

locate vsftpd

Major drawback of locate command is that it update its database only once in a day. For example you can find demo.conf which we created in above example from find command but not from locate command.

database of locate command is updated from /etc/cron.daily/mlocate.cron script. We can manually run this script.

find demo conf

Now we can find demo.conf also from locate command

locate demo

In exam

  • Update locate command database as soon as possible and use locate command whenever you need to search any file.
  • Use find command when locate does not works. Try to specify as much path as you remember when using find command.