Posted: . At: 9:13 PM. This was 10 years ago. Post ID: 6731
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 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.

homer@deusexmachina ~/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.

homer@deusexmachina ~/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.

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

Another example.

homer@deusexmachina ~/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.

homer@lollinux-machina:~/c-plus-equality ☠ $ locate vim.tiny
/usr/bin/vim.tiny

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

[root@localhost boot]# updatedb

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

[root@localhost 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