moodLearning Wiki

This is an old revision of the document!

Find Stuff

  • looking for duplicate filenames in 2 directories
fdupes --recurse dir1/ dir2/ 
  • find a word in a file
grep -rnw '/path/to/files/' -e "pattern"
  • find all socket files your system runs
find / -type s
  • find the latest file in a folder/subfolder
find . -type f -printf '%T@ %P\n' | sort -n | awk '{print $2}'


  • between files, showing side by side
diff -y file1 file2 | less
  • differences of files between directories
diff <(ls -a /dir1/) <(ls -a /dir 2/)

or compare

comm <(ls -a /dir/) <(ls -a /dir2/)


  • kill a process wholesale
kill $(ps aux | grep "$process_term" | grep -v 'grep' | awk '{print $2}')
  • trim log. example:
cat /dev/null > modsec_audit.log

See also “log rotate” on mL wiki.

  • remove everything else except…
rm -rf !(filename)

This works only if extglob is enabled. So

shopt -s extglob


  • View php config
php -r "print phpinfo();" | grep ".ini"


php -i | grep in

  • reinstall all php packages
apt-get install --reinstall `dpkg -l | grep 'ii  php7' | awk '{ printf($2" "); next}'`

Log Analysis

* limiting by date range

sed -n '/8\/Oct\/2019/,/8\/Oct\/2019/ p' access.log