~~NOTOC~~
====== 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.
====== Differences======
* 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/)
\\
====== Maintenance======
* 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
\\
====== Compression======
* lossless, multi-thread compression: keeping sourcing file, progress, high efficiency, extrem flag
time xz -6ve -k --threads=0
* compress multiple files
xz file1.txt file2.txt file3.txt
* decompress
xz -d file.txt.xz
unxz file.txt.xz
* test integrity
xz -tv .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
test
example
text
xzgrep exa test.txt.xz
example
====== PHP======
* View php config
php -r "print phpinfo();" | grep ".ini"
or
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