Sunday, July 20, 2014

How to search and find files on Linux

Find by Name
To find a file by name, type:
find -name "query"
To find a file by name, but ignore the case of the query, type:
find -iname "query"

Find by Type
You can specify the type of files you want to find with the "-type" parameter. It works like this:
find -type type_descriptor "query"
Some of the most common descriptors that you can use to specify the type of file are here:
  • f: regular file
  • d: directory
  • l: symbolic link
  • c: character devices
  • b: block devices

For instance, if we wanted to find all of the character devices on our system, we could issue this command:
find / -type c
Results:
/dev/parport0
/dev/snd/seq
/dev/snd/timer
/dev/autofs
/dev/cpu/microcode
/dev/vcsa7
/dev/vcs7
/dev/vcsa6
/dev/vcs6
/dev/vcsa5
/dev/vcs5
/dev/vcsa4
. . .

We can search for all files that end in ".conf" like this:
find / -type f -name "*.conf"
Results:
/var/lib/ucf/cache/:etc:rsyslog.d:50-default.conf
/usr/share/base-files/nsswitch.conf
/usr/share/initramfs-tools/event-driven/upstart-jobs/mountall.conf
/usr/share/rsyslog/50-default.conf
/usr/share/adduser/adduser.conf
/usr/share/davfs2/davfs2.conf
/usr/share/debconf/debconf.conf
/usr/share/doc/apt-utils/examples/apt-ftparchive.conf
. . .

(Reference: https://www.digitalocean.com/community/tutorials/how-to-use-find-and-locate-to-search-for-files-on-a-linux-vps)

No comments:

Post a Comment