moodLearning Wiki

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}'

  • show files greater than 1G

du -h * | grep '^\s*[0-9\.]\+G'

Change 'G' to 'M' for MB output.


  • 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


  • lossless, multi-thread compression: keeping sourcing file, progress, high efficiency, extrem flag

time xz -6ve -k --threads=0 <filename>

  • compress multiple files

xz file1.txt file2.txt file3.txt

  • decompress

xz -d file.txt.xz
unxz file.txt.xz

  • test integrity

xz -tv <filename>.tar.xz

  • concatenate multiple files

xzip -c file1.txt > files.xz
xzip -c file2.txt >> files.xz

  • concatenate, less, more, grep multiple files

xzcat test.txt.xz
xzgrep exa test.txt.xz


  • 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