How to Search or Find a File/folder on Your Linux Server?

find file on linux server

To locate files or folders on your Linux server through command line or bash, you can use the 'find' command.

The syntax for the find command is as follows :

find {dirctory_to_search} {search_by} {pattern_to_search} [action]

For Example, if you wish to search a file called 'filename.php' by name on the entire server.

find / -name filename.php 

 

Some of the popular 'search by' options are :

- -name pattern: This option finds the filenames of the given pattern.

For Example: Find a file named 'myfile.txt' in the 'home' folder of the server.

find /home -name myfile.txt

 

- -user username: Finds files owned by the given user name.

For Example: Find Files owned by the user 'WPOven' in the '/var/usr' folder of the server

find /var/usr -user WPOven

 

- -perm permission: Finds files of the given permissions.

For Example: Find all files with permission as '665' in the '/srv' folder

find /srv -perm 665

 

- -type X: Search files of type X. Here X can be :

f - File
d - Directory
l - Symbolic Link
For Example: Find a directory with name like 'mydir' in the '/var/www' folder

find /var/www -type d -name mydir

 

- -print File: Print the result full filename followed by a new line.

For Example: Find the files with name temp in the /srv folder and delete them

find /srv -type f -name temp -print | rm -f
WPOven
© 2024 WPOven Inc. All rights reserved. WPOven® and WordPress® are registered trademarks.
WPOven is the best Managed WordPress hosting for agencies and businesses that want to succeed. With Unlimited sites hosting option, its easy to use and manage, so you can focus on growing your business. 
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram