• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Question about Unix search commands

Arkitech

Diamond Member
I'm looking for a certain file pattern within a Unix directory but I'm unsure exactly which subfolder the files reside in. What's the best way to search for that file?


 
Just thought of another question, lets say you have a really large data file and you're looking for a specific string or phrase within that file. Is there a command that will show all the specified strings within the file?
 
Originally posted by: Arkitech
I'm looking for a certain file pattern within a Unix directory but I'm unsure exactly which subfolder the files reside in. What's the best way to search for that file?

find /path/to/directory -name filename

see the man file. (man find) There are many options for finding names or patterns, case insensitive searches, time stamps and other things.

 
Originally posted by: Arkitech
Just thought of another question, lets say you have a really large data file and you're looking for a specific string or phrase within that file. Is there a command that will show all the specified strings within the file?

grep command will look through input and display lines that contain the strings your looking for.

In it's simpliest form it would be like:

grep string /path/to/filename

(of course in these commands can be a absolute path or a relative path (ie just the filename))

See the man file for details on it's many powerfull options.


you can use these things to do very powerfull searches.

For instance to look for a file with a filename and then tell you if that file contains a string you'd go:

find ./ -name filename | while read i; do if grep string "$i" > /dev/null 2> /dev/null ; then echo "$i has a match"; fi ; done

That sort of thing.

Goto the The Linux Documentation Project's website's pages containing lists of guides. They have a few informative guides ranging from understanding the basics to advanced techniques at using bash shells.
 
Back
Top