How to find files on the Linux filesystem.

Posted: March 16, 2015. At: 3:14 PM. This was 3 years ago. Post ID: 8090

The find command is very useful for locating files on your Linux filesystem. Below is an example of wildcards to locate files in the /boot directory.

[email protected]:~$ sudo find /boot -name "vm*"
/boot/vmlinuz-3.13.0-44-generic

Here I am searching the whole / filesystem for a set of files that end in *.log.

[email protected]:~$ sudo find / -name "log"
/var/log
/var/cache/pollinate/log
/dev/log
/usr/src/linux-headers-3.13.0-44-generic/include/config/log
/usr/src/linux-headers-3.13.0-44-generic/include/config/dm/log

The whereis command allows the user to search for programs and it will return where the program is installed.

ubuntu ~ $ whereis rm
rm: /bin/rm /usr/share/man/man1/rm.1.gz

To list all mounted filesystems on a Linux machine; use this command.

ubuntu ~ $ findmnt
TARGET                       SOURCE                                                 FSTYPE     OPTIONS
/                            /dev/disk/by-uuid/ee515a1e-7735-4529-822f-4cc9e7632cd3 ext4       rw,relatime,discard,data=ordered
├─/sys                       sysfs                                                  sysfs      rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/cgroup                                                                  tmpfs      rw,relatime,size=4k,mode=755
│ │ └─/sys/fs/cgroup/systemd systemd                                                cgroup     rw,nosuid,nodev,noexec,relatime,name=systemd
│ ├─/sys/fs/fuse/connections                                                        fusectl    rw,relatime
│ ├─/sys/kernel/debug                                                               debugfs    rw,relatime
│ ├─/sys/kernel/security                                                            securityfs rw,relatime
│ └─/sys/fs/pstore                                                                  pstore     rw,relatime
├─/proc                      proc                                                   proc       rw,nosuid,nodev,noexec,relatime
├─/dev                       udev                                                   devtmpfs   rw,relatime,size=503184k,nr_inodes=125796,mode=755
│ └─/dev/pts                 devpts                                                 devpts     rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
└─/run                       tmpfs                                                  tmpfs      rw,nosuid,noexec,relatime,size=101632k,mode=755
  ├─/run/lock                                                                       tmpfs      rw,nosuid,nodev,noexec,relatime,size=5120k
  ├─/run/shm                                                                        tmpfs      rw,nosuid,nodev,relatime
  └─/run/user                                                                       tmpfs      rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755

This gives you a good picture of your filesystem. All mounted filesystems are printed in a tree format by default.

Another command for searching your filesystem is the locate command. This can search your filesystem for various files.

ubuntu ~ $ locate dmesg
/bin/dmesg
/etc/init/dmesg.conf
/usr/lib/klibc/bin/dmesg
/usr/share/bash-completion/completions/dmesg
/usr/share/man/man1/dmesg.1.gz
/var/log/dmesg
/var/log/dmesg.0

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

Leave a Reply