• Run a process detached to the current terminal:

    $ nohup my_command &
    
  • 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):

    $ su sys_user -s /bin/bash -c "my_command"
    
  • Get the exit code of the latest runned command:

    $ echo $?
    
  • Run the last command as root (source):

    $ sudo !!
    
  • Show the user under which I’m currently logged in:

    $ whoami
    
  • List cron jobs of the current user:

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

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

    Then the fix consist of removing the bad characters:

    $ sed -i 's/\r//' ./myscript.sh
    
  • Extract strings from a binary file:

    $ strings ./firmware.bin | less
    
  • Free up some memory by clearing RAM caches (source):

    $ sync ; echo 3 > /proc/sys/vm/drop_caches
    
  • Display which distro is running the system (source):

    $ lsb_release -a
    

    or

    $ cat /etc/lsb-release
    
  • List of most used commands:

    $ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
    
  • Disable a service on Debian/Ubuntu, then re-enable it:

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

    $ chkconfig sshd --del
    $ chkconfig sshd --add
    

Related content