Manage processes
$systemctl enable/disable nginx = enables/disables nginx to start/stop at boot time
$systemctl start/stop nginx = starts/stops nginx in the current time
$systemctl reload serviceName = re-read program configuration file without killing the process
$systemctl daemon-reload = reload daemon after every service configuration change
$htop = lists all running processes
$ps aux --sort=-%mem | head = This will show you top 10 process that using the most memory $ps -ef = lists all user processes
$ps aux | grep -i firefox = find firefox PID so you can kill process if needed (kill PID)
$kill $! = kill the most recently backgrounded job
$kill $(ps -A -ostat,ppid | awk '/[zZ]/{print $2}') = kill all zombie processes
Other commands to send processes to background, bring process to foreground, kill, etc:
https://unix.stackexchange.com/questions/104821/how -to-terminate-a-background-process/104825
$sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld = reloads apparmor usr.sbin.mysqld profile when mysql server does not start
$sar -r = monitor CPU, RAM, I/O etc.
Display kernel messages from boot time
$dmesg | grep -i error = print the error message buffer of the kernel
$dmesg | grep -i warn
$dmesg = print messages produced by the device drivers. The boot process generates a particularly dense stream of kernel mess ages.
Find username and process and kill
$who | grep username (to get the pts/# terminal) = check all username connections to the server and kill the process with next command
$sudo pkill -f pts/#
$ps -aux | grep 'nano' = finds the PID and user that uses the 'nano' application
$kill -9 PID = force (-9) kills specified PID
Fix DNS
$sudo apt-get remove --purge resolvconf && sudo apt-get install --reinstall resolvconf = uninstall and re-install resolvconf
Search file/directory/program on hard drive
$grep -E --color wordToFind /path/To/file = searches and highlights the wordToFind inside of a file
$which date = shows you where the program “date” is located so you can pass that path into your script when you call that pro gram
$locate -i interfaces = searches for file "interfaces" on hard drive (on root folder and subfolders)
$find . -type d -exec chmod 755 {} \; = search in current location (.) for type “directory” and execute chmod to change permissions to 755 for everything inside directory
$find . -type f -exec chmod 644 {} \; = search in current location (.) for type “file” and execute chmod to change permissions to 644 for all files
$sudo find / |grep "\.pem" = search for all files with extension pem on root folder /
$find / -name fileNameOrPartOf\* -print = search for fileNameOrPartOf with wildcard at the end (use escape \ for *) in top root \ folder and print results
$grep appNameInstalled /var/log/apt/history.log = find time/date appNameInstalled was installed on server
$zgrep appNameInstalled /var/log/apt/history.log.2.gz = searches through the archived log file
$sudo apt list --installed = lists all installed packages
$sudo apt remove package-name = uninstalls package-name
Permanently enable timestamp for 'history' command:
$echo'HISTTIMEFORMAT="%d/%m/%y %T "'>> ~/.bashrc = for e.g. “29/02/99 23:59:59”
$echo'HISTTIMEFORMAT="%F %T "'>> ~/.bashrc = for e.g. “1999-02-29 23:59:59”
$source~/.bashrc
Diff command:
diff is a command-line utility that allows you to compare two files line by line. It can also compare the contents of directories. The diff command is most commonly used to create a patch containing the differences between one or more files that can be applied using the patch command.
$diff -qrc tx2_june01.csv all.csv
$diff -c tx2_june01.csv all.csv
$diff -U 0 all.csv tx2_june01.csv | grep ^@ | wc -l
$diff -U all.csv tx2_june01.csv | grep ^@ | wc -l
$diff all.csv $tx2_june01.csv | grep ^@ | wc -l
$diff all.csv tx2_june01.csv | wc -l
$ls -al all.csv tx2_june01.csv
$wc -l tx2_june01.csv
$wc -l all.csv
$sudo nano all2.csv