Linux tricks

1 minute read

Tricks on Linux command line

cd -: back to the last working directory

Running multiple commands

  • Running multiple commands in one single command

    command_1; command_2; command_3
  • Running multiple commands in one single command only if the previous command was successful

    command_1 && command_2

Previous commands and arguments

!! the last command

!n : the n of previous command argument

Alt+. previous command argument

Check for Spelling of Words in Linux

look docum

Linux terminal shortcuts list

  1. Ctrl+a Move cursor to start of line
  2. Ctrl+e Move cursor to end of line
  3. Ctrl+u Cut everything before the cursor
  4. Ctrl+k Cut everything after the cursor
  5. Ctrl+i Clear the terminal
  6. Ctrl+r Search command in history - type the search term
  7. Ctrl+b Move back one character
  8. Alt++b Move back one word
  9. Ctrl+f Move forward one character
  10. Alt++f Move forward one word
  11. Ctrl+d Delete current character
  12. Ctrl+w Cut the last word
  13. Alt++d Cut word after the cursor
  14. Alt++w Cut word before the cursor
  15. Ctrl+y Paste the last deleted command
  16. Ctrl+_ Undo
  17. Ctrl+xx Toggle between first and current position
  18. Ctrl+c Cancel the command
  19. Ctrl+j End the search at current history entry
  20. Ctrl+g Cancel the search and restore original line
  21. Ctrl+n Next command from the History
  22. Ctrl+p previous command from the History

Ref stackoverflow

pretty view csv file in terminal

add this to .bashrc, and then just pretty_csv xxx.csv

function pretty_csv {
    column -t -s, -n "$@" | less -F -S -X -K

pretty print code in paper with enscript

sudo apt install enscript
enscript -2rj --highlight=python --color=1 -o

Check disk usage

sudo du -ah --max-depth=1  / | sort -hr

create crontab tasks with cron -e