Finding files in Linux filesystems

Both Linux and Unixish provides command to find file. The best and easy way to find file is to use command called locate. It list files in databases that match a pattern. For example to find file called myprog.c you need to use locate command as follows:

ADVERTISEMENTS

$ locate myprog.c | less

Another option is to use find command. For example find out all C source code file from /home/jerry directory:
$ find /home/jerry -name “*.c” -print
OR
$ find ~jerry -name “*.c” -print
Please note that ~jerry is short-cut name to refer user jerry’s home directory (/home/jerry). FIND command has very advance usage please see following articles for more information:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
5 comments… add one
  • NickJ Oct 5, 2006 @ 5:31

    How do I take a backup of a file which is continuously written by an application. And if the application not able to write in that file it will get crashed. I dont want to crashed the application.
    Also, the file size is around 700MB to 1GB.
    Please advice..

  • 🐧 nixCraft Oct 5, 2006 @ 12:13

    NickJ,

    USE LVM based backup, see following url for Logical Volume Manager snapshot to avoid inconsistent backup

    https://www.cyberciti.biz/tips/consistent-backup-linux-logical-volume-manager-snapshots.html

  • aref ghobadi Aug 23, 2015 @ 6:01

    Hi,
    very nice article

  • tj Sep 28, 2016 @ 11:23

    This can be improved with a regular expression; like this:
    $ find /home/jerry/ -regex '^.*\.c$'.

  • tj Sep 28, 2016 @ 11:27

    This can be improved with a regular expression; like so:

    $ find /home/jerry/ -regex '^.*\.c$'

    .

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.