Processes
Run a process detached to the current terminal and monitor its output:
1
$ nohup my_command &2$ tail -F ./nohup.outSame as above but with multiple commands, the last cloning a disk to another:
1
$ nohup zsh -c "my_command && cat /dev/da1 > /dev/da0" &2$ tail -F ./nohup.outRun a process with a shell for a system user which has none (i.e. its default shell is set to /bin/false in /etc/passwd):
1
$ su sys_user -s /bin/bash -c "my_command"
Shell
Get the exit code of the latest ran command:
1
$ echo $?Run the last command as root (source):
1
$ sudo !!Show the user under which Iām currently logged in:
1
$ whoamiList of most used commands:
1
$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | headList cron jobs of the current user:
1
$ crontab -lIf you have the following error:
1
$ -bash: ./myscript.sh: /bin/bash^M: bad interpreter: No such file or directoryThen the fix consist of removing the bad characters:
1
$ sed -i 's/\r//' ./myscript.shExtract strings from a binary file:
1
$ strings ./firmware.bin | less
Memory
Free up some memory by clearing RAM caches (source):
1
$ sync ; echo 3 > /proc/sys/vm/drop_caches
Distribution
Display which distro is running the system (source):
1
$ lsb_release -aor
1
$ cat /etc/lsb-release
Services
Disable a service on Debian/Ubuntu, then re-enable it:
1
$ update-rc.d my-service-name remove2$ update-rc.d my-service-name defaultsSame thing as above but on a RedHat-like system:
1
$ chkconfig sshd --del2$ chkconfig sshd --add
Boot
Speed-up Grub boot, but always show the boot menu:
1
$ sudo sed -i 's/GRUB_TIMEOUT=10/GRUB_TIMEOUT=1/g' /etc/default/grub2$ sudo sed -i 's/GRUB_HIDDEN_TIMEOUT/#GRUB_HIDDEN_TIMEOUT/g' /etc/default/grub3$ sudo update-grub
Fonts
List fonts available on the system:
1
$ fc-list | cut -d ':' -f 2 | sort | uniq