Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Useful Terminal Commands
# Recursively find all files named config and replace a string using sed. The -i flag requires a blank suffix '' to work on Mac.
find . -name config -type f -print | xargs sed -i '' 's/'
# Recursively find all files with a certain file extension and replace a string using perl.
find . -name "*.fileext" -print | xargs perl -i -p -e 's/STRINGTOFIND/STRINGTOREPLACE/g'
# Display filesystem of mounted volumes
df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
# Recursively force files lowercase with rename
find . -depth -print -execdir rename -f 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
# Recursively change spaces to underscores with rename
find . -depth -print -execdir rename -f 'y/ /_/' {} \;
# Trim log files to keep 100 last lines at bottom of file.
find / -name '*'.log | while read x; do sed -i -e :a -e '$q;N;100,$D;ba' $x; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment