bash


  1. find all files with extension recursively and delete them
find . -name "*.png" -type f -delete
  1. make a directory multiple levels deep
mkdir -p currentdir/newdir/foo
  1. recursively search bash history
CTRL + r (tap r to cycle through history)
  1. go back to last working directory
cd -
  1. repeat previous command with sudo
sudo !!
  1. read latest entries on log files
tail -f logfile
  1. get size of directory contents
du -sh *
  1. kill process
ps -e | grep {package} // get the pid from this
kill {pid} // pid from previous command
  1. find and replace using sed
sed -i 's/oldstring/newstring/g' hello.txt
  1. search recursively for string and return line numbers of any occurrences
grep -rn string .
  1. add following to .zshrc or .bash_profile to return files whose name contains a string
f () { find . -name '*'"$@"'*' ; }
# "f .png" recursively returns all files in the current directory that contain ".png"