Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

21Jul/100
Search within files on a Linux Server

This is a very useful bit of code, used to search within files on a Linux server. Replace the . after find to search within a folder.

find . | xargs grep "search string" > search.log

This script finds all files at or below current directory, then runs a search within the files.

find . (find all files at or below current directory)
xargs (build and execute commands from standard input, separated by newline)
grep (search within the file for the quoted string)

20Jul/100
Recursively count the number of files on a Linux server

Simple script to recursively count the number of files on a Linux server.

ls -laR | wc -l

How this works:

ls (lists folder contents), -l (long listing format), -a (all), -R (recursive)
wc (word count), -l (or --lines, prints only the newline counts)