Results 1 to 1 of 1
Threaded View
-
9th Feb 2012, 12:03 PM #1OPMemberWebsite's:
AVANETCO.COM AVAVPS.COMSearching for files/text using SSH
In some cases you would need to find the location of a given file or to search for a certain text in all files under a directory. SSH provides two different commands, which can be used to accomplish this.
In order to search for a file location you can use the find command. Find is a very powerful tool and accepts various arguments allowing you to specify the exact search term (i.e search by name, by type or even by modified time).
For example, to search for a file called myFile.txt under the current folder (and all subfolders), you would need to use the following command:
find . -name myFile.txt
If you are uncertain about the file name or would like to match a part of the name, you can use a wildcard pattern:
find . -name ?myFile*?
If you would like to list only directories and leave all files out of the result:
find . -type d
Or if you want to filter only files modified for the last 2 days, you would need to use:
find . -mtime -2
You can also search for a given text in the files content as well. The command you should be using in this case is ?grep? . Grep is a very powerful tool and accepts various command line arguments. For a full list it is recommended to check the manual pages by typing ?man grep?.
An example of using grep to find a certain text can be found below:
grep ?database? configuration.php
The above command instructs grep to look for the string ?database? in configuration.php file and display the containing line. If you don?t know which file contains the text, you can use:
grep -r -H ?database? *
This will make grep look recursively (-r option) and provide the result in human readable format (-H option) for the string ?database? in all (*) files under the current working directory.
To only list the file names containing the string you are searching but omit the line containing it, you can use the -l argument:
grep -l ?database? *
This will display the filenames containing the word database, but will not actually list the line containing it.
Grep can also be used to filter the results from other commands. For example, the line below will only output configuration.php result:
ls -la | grep configuration.php
In some rare cases, you would not like to use find or grep. For example, to find a certain file in the whole server, it would be best to use an alternative command -- whereis or which:
whereis perl
or
which perl
The execution of the above commands will locate the perl binary and display the full path(s) to it.Albert.Nawaro Reviewed by Albert.Nawaro on . Searching for files/text using SSH In some cases you would need to find the location of a given file or to search for a certain text in all files under a directory. SSH provides two different commands, which can be used to accomplish this. In order to search for a file location you can use the find command. Find is a very powerful tool and accepts various arguments allowing you to specify the exact search term (i.e search by name, by type or even by modified time). For example, to search for a file called myFile.txt Rating: 5
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Searching for text in files
By roadrunner in forum Web Development AreaReplies: 6Last Post: 6th Jul 2012, 02:56 PM -
[Hiring] Checking 500 Text Files For 100$
By orbofdarkness in forum Completed TransactionsReplies: 12Last Post: 5th Apr 2011, 02:28 PM -
replace multiple different texts in different text files
By techdaemon in forum Technical Help Desk SupportReplies: 13Last Post: 20th Jan 2011, 04:54 PM -
Does Hotfile allow searching for hosted files?
By Prazsky in forum File Host DiscussionReplies: 4Last Post: 18th Dec 2010, 04:56 AM -
[linux]Rar files, upload to RS,Hotfile,fileserve,sharingmatrix then delete the files
By jpavsex in forum Tutorials and GuidesReplies: 10Last Post: 13th Jul 2010, 04:49 PM
themaCreator - create posts from...
Version 3.18 released. Open older version (or...