Some of my favorite Linux commands

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

(Visited 19 times, 1 visits today)
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments