Some of my favorite Linux commands

2/27/2009 — Leave a comment

linux-penguin

Find one of many strings in a set of files
grep -E "str1|str2|str" file*.*

Search through files with multiple file extensions
grep -r --include=\*.{html,php,htm} str /path/to/directory/to/grep

Search through files with multiple extensions with one find command
find -name "*.jsp" -o -name "*.java" | xargs grep -i "whee"

Search through files with multiple extensions with one find command, regex method
find -regex ".*\(\.jsp\|\.php\|\.html\|\.htm\).*" | xargs grep -i "whee"

Replace newlines with HTML breaks in a file
sed ':a;N;$!ba;s/\n/\/g' file.txt

Rename multiple files
for f in *.txt; do mv "$f" "${f%.txt}.bak"; done

Directory sizes here and below
du -sm $(find $1 -type d -maxdepth 1 -xdev) | sort -g

Find files containing between 600 to 700 characters, inclusive.
find . -size +599c -and -size -701c

Update a file’s timestamp, but do not create files
touch -c file*.txt

wvpv

what others do with talent, I do with obstinate fixation

No Comments

Be the first to start the conversation.

Leave a Reply

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

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>