Linux: awesome helping commands

Search all log files for the word debug case insensitive

$ grep -i debug /var/www/html/register_by_email/var/logs/*.log

Delete all files except one:

$ sudo ls | grep -v 000-default.conf | sudo xargs rm

The same but ignore errors:

$ sudo rm /etc/apache2/ssl/*.* &>/dev/null && cd /etc/apache2/sites-available/ && sudo ls | grep -v 000-default.conf | sudo xargs rm &>/dev/null && cd /etc/apache2/sites-enabled/ && sudo ls | grep -v 000-default.conf | sudo xargs rm &>/dev/null

Advanced copy of files using regular expressions: from a folder with csv files named using a date format like DK20170514.csv this command will copy only files with date from 14 may to 12 june.

$ sudo find -regextype posix-extended -regex '.*/??20170(5(1[4-9]|2[0-9])|6(0[0-9]|1[0-2]))\.csv' | xargs cp -t ../../../special/41393/ &>/dev/null

Note theĀ .*/ in the beginning of the regex: find needs this to work!

Watch how crons work

watch -n 0.1 'ls -1 | wc -l'

Copy a log file from remote to local using ssh

scp -i ~/.ssh/abdel some-server:/var/www/html/myapp/var/logs/dev.log local_dev.log

Display end of file: useful for live debugging single or multiple log files

tail -n 4 -f var/logs/*.*