How to find a file with the Linux command line.

Posted: November 9, 2014. At: 11:04 PM. This was 3 years ago. Post ID: 7904
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

The Linux command line is very useful for finding files, the find command is the best way to locate files on your filesystem.

This is a simple example.

[email protected]:~$ sudo find /proc -name "meminfo"

Use the -maxdepth parameter to only search a certain number of levels deep into directories.

[email protected]:~$ sudo find / -maxdepth 2 -name "meminfo"

Use the -cmin parameter to display files that changed a certain number of minutes ago.

[email protected]:~$ sudo find /home/knoppix -cmin 5
find: `/home/knoppix/.gvfs': Permission denied
/home/knoppix/.config/chromium/Default/Current Session

In this example I am looking for files that changed 5 minutes ago.

This command will find all files in your home directory that have changed in the last 24 hours.

find $HOME -mtime 0

The locate command is another way to find files on your filesystem. In this example, I am finding all files in the /bin directory that start with ‘ls’.

[email protected]:~$ locate /bin/ls
locate: warning: database `/var/cache/locate/locatedb' is more than 8 days old (actual age is 503.1 days)

Use the sudo updatedb command to update the database that the locate command uses. This is a faster way to search for files than find.

No comments have been made. Use this form to start the conversation :)

Leave a Reply