How to search for a file or directory on Linux CLI

This is a quick reference guide on how to find a file or directory on Linux Based Operating Systems.

To search by name – case sensitive.

root@VPS:~# find / -name sshd
/run/sshd
/etc/pam.d/sshd
/usr/sbin/sshd

To search by iname – not case sensitive.

root@VPS:~# find / -name SSHD
root@VPS:~# find / -iname SSHD
/run/sshd
/etc/pam.d/sshd
/usr/sbin/sshd

You will see that the -name command above does not return anything when searching for SSHD but the -iname does.

To search for a file or directory.

root@VPS:~# find / -type d -name sshd
/run/sshd
root@VPS:~# find / -type f -name sshd
/etc/pam.d/sshd
/usr/sbin/sshd

In the above example you are searching for either just files or directories containing sshd. The -type d option is to search by directory and the -type -f option is to search for files.

To search for a file or directory containing certain words or characters using a wildcard.

root@VPS:~# find / -type f -name sshd
/etc/pam.d/sshd
/usr/sbin/sshd
root@VPS:~# find / -type f -name *sshd*
/run/sshd.pid
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/ssh/sshd_config.ucf-dist
/usr/share/openssh/sshd_config
/usr/share/openssh/sshd_config.md5sum
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sshd.8.gz
/usr/share/vim/vim80/syntax/sshdconfig.vim
/usr/sbin/sshd
/var/lib/ucf/cache/:etc:ssh:sshd_config
/var/lib/systemd/deb-systemd-helper-enabled/sshd.service

As with the previous example when searching with just “sshd” that will return results with the exact name of the file or directory. When adding * on either side of the search term this will return results any file containing the word “sshd”.

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s