Linux Tutorial: Finding Files in Linux

Note: In Linux, everything is treated as files.

Even folders are treated as files.

There will be situations where you might probably want to find a file in your Linux system. You can find files and folders in Linux using the following commands

  1. Which
  2. Whereis
  3. Locate
  4. Find

Which:

Which command returns the location of the executable’s ( installer files present in your system) which you are looking for. For example, a search for apache web server executable (apache2 (Ubuntu), httpd (centos) ) can be done using the following command.

The above command will return the location of the apache web server executable in the system.

Whereis:

Whereis command returns the location of binaries, executable’s and the man pages of the file you are looking for. Whereis command is associated with three options, -s, -b and –m. when you use whereis command with –s switch, it returns the source file, -b returns only binary and –m returns the man pages.

The above command returns the source, binary and man pages.

The above command returns only the source if the source exists.

whereis –m apache2
The above command returns the man pages for apache2.

Locate:

Locate command is used to locate files on your system. Before using the locate command, you have to update you db because there is a database which stores all the locations of your files in the system. This db file can be found in the following location

This database has to be updated in order to use the locate utility efficiently. This can be done by running the updatedb utility in the terminal.

You have to run the updatedb utility every time in order to get the latest changes made to the file system. For example, you ran the updatedb and after that, you created a new file demo.txt . If you try to find demo.txt using locate, it won’t return any output. If you run updated utility and use the locate command again, you would be able to find the demo.txt file location.
You can locate files using the following command.

Find:

Find is an awesome utility to locate files on your system. You can find files based on name and using the find utility.

Finding files using name

You can search for a specific file by its name by using –name switch with the find command.

Finding files using type

You can search for a specific file by its type (eg: directory) by using –type switch with the find command.

Finding file based on size

Using find, you can list files based on size.

The above command lists the files which are less than 50 MB

The above command lists the file which is above 50 MB

kindly share this post and leave a comment for feedback

Related

Even though you can check the disk , directory information and usage using graphical user interface, it is important to…

Read more
linux process managemtn

Linux is a multitasking system, which means it can run multiple tasks (process) at a time. Basically, a process is a…

Read more

Issue: I have my Jenkins master and slave setup on AWS instance. I am build i have a maven deploy task to upload a…

Read more

Internet is huge! Help us find great content

Newsletter

Never miss a thing! Sign up for our newsletter to stay updated.

About

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.

​98
%

Off

Udemy Black Friday Offer Courses For $9.99 For Limited Time