Posted: . At: 11:04 PM. This was 9 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.

How to find a file with the Linux command line.

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.

knoppix@Microknoppix:~$ sudo find /proc -name "meminfo"
/proc/meminfo

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

knoppix@Microknoppix:~$ sudo find / -maxdepth 2 -name "meminfo"
/proc/meminfo

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

knoppix@Microknoppix:~$ 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’.

knoppix@Microknoppix:~$ locate /bin/ls
locate: warning: database `/var/cache/locate/locatedb' is more than 8 days old (actual age is 503.1 days)
/bin/ls
/bin/lsblk
/bin/lsmod
/usr/bin/lsattr
/usr/bin/lsb_release
/usr/bin/lscpu
/usr/bin/lsdistcc
/usr/bin/lsdvb
/usr/bin/lshal
/usr/bin/lsinitramfs
/usr/bin/lsof
/usr/bin/lspci
/usr/bin/lspgpot
/usr/bin/lss16toppm
/usr/bin/lsusb
/usr/lib/klibc/bin/ls

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.

Leave a Comment

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