ali aboos

Archive for February, 2009

Linux: find a string recursively within files

by on Feb.14, 2009, under Linux

Well… there are several ways of doing this in Linux and Unix:
find /<path> 'filename.extension> (wildcard allowed)
find /<path> *.* | xargs grep <string>
find . -type f -exec grep "<string>" {} \; -print
grep -r "<string>" /<path>/<filename>

You can also add a ‘>> <filename>’ (no quotes) to the end to write the output to a file so you can take a look at it later.

To recursively find and replace a string within files:
find . -type f | xargs perl -pi~ -e 's/<current string>/<new string>/g;'
sed -i '<current string>/from/to/<new string>' `find . -name \*.ext`

Put `find . -name \*.ext` in a double quote and it should work for filenames with space as well.

If you want to find and delete files or directories recursively, look here.

1 Comment more...

How to enter diagnostic boot – Dell laptops

by on Feb.10, 2009, under Misc

Hold “fn” while pressing the power button!

1 Comment more...

Search InsaneLabs.com

Can't find what you're looking for? Drop a comment on a post or email (ali aht insanelabs doht com)

Links

Links open in a new window