Useful Linux bash search commands

Here is some useful commands you should have around you when you’re looking for something on your hard drive.

Find in content files

This linux command can be used if you want to find something into content files. Be sure to be in the desired directory where you want to start the search. It can take a while because of the (-r) recursion. It will display number lines with the -n parameter. grep –help to find more parameters.

Find in content of filtered extension files

This is the same but using find command with more possibilities likes file filtering. This example will search in .php files:

Find in file names

Find your myfile.php file in the current directory and subdirectories

Find in directory names

If you want to find all directories by their names:

Find in Linux indexed db

You could use the locate command to get files and/or directories containing your search keywords. This command uses a Linux indexed database which won’t be updated by the system automatically. Then you should use the updatedb command to refresh it before making your search:

Find and replace in all files

The sed command let you do something very useful: to search and replace a string in all files easily. For example if you want the rain gives way to the sun, you could replace all rainy occurrences by sunny in all your files like this :

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation