How to find a file with Linux using the command line.

The Linux command line offers useful tools that enable you to find files easily. The find command is one useful example.

Here I am using the find command to look for all *.png files in a folder.

[email protected] ~/Documents $ find /usr/share/backgrounds -name "*.png"
/usr/share/backgrounds/linuxmint-petra/linux_mint_16.png
/usr/share/backgrounds/linuxmint-petra/petra.png
/usr/share/backgrounds/warty-final-ubuntu.png

And using wildcards to find all files with init in their name.

[email protected] ~/Documents $ find /lib -name "init*"
/lib/modules/3.11.0-12-generic/initrd
/lib/modules/3.11.0-12-generic/kernel/drivers/scsi/initio.ko
/lib/lsb/init-functions.d
/lib/lsb/init-functions
/lib/init

This is how to find a file from the root directory and suppress all errors.

[email protected] ~/Documents $ sudo find / -name "vmlinuz" 2> /dev/null
[sudo] password for homer: 
/vmlinuz

Another example.

[email protected] ~/Documents $ sudo find / -name "vim.tiny" 2> /dev/null
/usr/bin/vim.tiny

The locate command for Linux also allows you to search for files on your Linux system. Below is an example.

[email protected]:~/c-plus-equality ☠ $ locate vim.tiny
/usr/bin/vim.tiny

Use the updatedb command to update the database for the locate command.

[[email protected] boot]# updatedb

These commands allow you to find files on your Linux system very easily. Here is a final example; using the find command.

[[email protected] boot]# find / -name 'vmlinuz*' 2> /dev/null
/boot/vmlinuz-3.13.3-201.fc20.x86_64
/boot/vmlinuz-3.13.4-200.fc20.x86_64
/boot/vmlinuz-0-rescue-96f268a55cb54041bfbb56390631336b
/boot/vmlinuz-3.12.10-300.fc20.x86_64

Comments have been closed/disabled for this content.