Skip to content

Instantly share code, notes, and snippets.

@joshkraemer
Created February 8, 2012 01:41
Show Gist options
  • Save joshkraemer/1764166 to your computer and use it in GitHub Desktop.
Save joshkraemer/1764166 to your computer and use it in GitHub Desktop.
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/git@github.com:CollegePlus/git@github.com:collegeplus/g'
# 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