Searching files directories and content in Linux

Posted By : Mohd Sheemal | 23-Sep-2017

First I check all the files or folders present in the current location with the help of ' ls ' command.

There are following commands we have to check the files, content, and folders are :

- grep

- find

- locate

 

- Grep: The grep command can be used to find out and can search content inside a file.

. To filter the folder hierarchy based on the files name then the find command is only used. If you want to search based on the content of the file, to use the grep. The default configuration to finding the ignore symbolic links, you have to add the -L option to the command.

 

Syntax of the command is: grep 'search text' filename

 

Example: We are using grep command to find text Testing inside the file log1.txt, with the help of grep command we can search content inside a file. If we have a big log file and I want to check the file of the content, where my Testing is written, we can directly go to the grep command.

Grep Testing log1.txt

 

- Find: The find command is used to, If the current location we have a lot of files and folders (directories) and I want to check a particular file exist in the current directory or not, we can use find command.

 

Syntax of the command is: find filename

 

If this file exists in the current folder or directories, It will display that and If we find any file - example: file1.txt, If this file does not exist so It is not going to give any file. It will display the message file1.txt : No such file or directory inside the current location.

 

- Locate: The locate command is used to search in the complete system. If I want to check all the files or folders which exist in my system where the name is Log. It will display all the results with respect to Log.

 . The locate command is used too often the simplest and the quickest way to finding the locations of the filed & folders on Linux

Syntax of the command is: locate file/folder name

About Author

Author Image
Mohd Sheemal

Mohd Sheemal is a Bright QA Engineer. He has a good knowledge over Selenium.

Request for Proposal

Name is required

Comment is required

Sending message..