Processes

  • Run a process detached to the current terminal and monitor its output:

    1 $ nohup my_command &
    2 $ tail -F ./nohup.out
  • Same 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.out
  • Run 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 $ whoami
  • List of most used commands:

    1 $ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
  • List cron jobs of the current user:

    1 $ crontab -l
  • If you have the following error:

    1 $ -bash: ./myscript.sh: /bin/bash^M: bad interpreter: No such file or directory

    Then the fix consist of removing the bad characters:

    1 $ sed -i 's/\r//' ./myscript.sh
  • Extract 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 -a

    or

    1 $ cat /etc/lsb-release

Services

  • Disable a service on Debian/Ubuntu, then re-enable it:

    1 $ update-rc.d my-service-name remove
    2 $ update-rc.d my-service-name defaults
  • Same thing as above but on a RedHat-like system:

    1 $ chkconfig sshd --del
    2 $ 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/grub
    2 $ sudo sed -i 's/GRUB_HIDDEN_TIMEOUT/#GRUB_HIDDEN_TIMEOUT/g' /etc/default/grub
    3 $ sudo update-grub

Fonts

  • List fonts available on the system:

    1 $ fc-list | cut -d ':' -f 2 | sort | uniq

Other Resources