How to Find File and Folder in Linux [Find File in CentOS, Debian, Ubuntu]
What is SSH?
SSH stands for Secure Shell. It is a protocol that connects you to a remote server or system. The established connection between the host and the client is extremely secure and safe due to encryption.
How to find file in Linux [How to find file in CentOS]
There are two prominent ways to Search File and Directory in Linux, carry out this task:
- Find command
- Grep command
Find command eases your process of find file in Linux (CentOS, Debian, Ubuntu)using various arguments. You can search for the desired file through date, time, or even through modified time.
Suppose, you wish to search for a file a.txt, follow the mentioned command:
find . -name testfile.txt
Now, if you do not remember the exact file name, try this method:
find . -name testfile*
Here, the system will scan all the files and present you with the file that matches your argument the best.
Moving on, if you want to view a list of all the directories, simply use the following command:
find . -type d
Next, to view files modified in the last 3 days, use
find . -mtime -3
Additionally, if you want to search a specific part of a text in a file, use the Grep command.
This command searches for the string, “warehouse” in the file config.php that you mentioned. Now, in case you forget the file name, simply follow this command:
grep -r -H “warehouse” *
Here, -r means recursively, -H means that the result is human-readable for your desired string. ‘*’ means that the command scans all the files in your current directory and offers you the result.
To search for a specific text in a file, use the below-mentioned command:
Grep “warehouse” config.php
Additionally, if you only want a list of all the files that contain your mentioned string and not the entire line, use this command:
Grep -l “warehouse” *
Moving on to our last segment, there can be situations when these commands don’t work. Follow these two commands in such cases.
That’s all for this article. We hope that using the commands listed you were able to find the files you were looking for. If you run into any problems, have any questions or suggestions, please leave them in the comment section below.
People are also reading: