Linux tricks
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. e.g. !:0 is the last command, and !:-1 is the first argument of last command
Alt+. the last argument of any of the previous commands.
Esc + . last argument of the last command.
!^ first argument
!$ last argument
!* all arguments
!:2 second argument
!:2-3 second to third arguments
!:2-$ second to last arguments
!:2* second to last arguments
!:2- second to next to last arguments
!:0 the command
!! repeat the previous line
Check for Spelling of Words in Linux
look docum
Linux terminal shortcuts list
- Ctrl+a Move cursor to start of line
- Ctrl+e Move cursor to end of line
- Ctrl+u Cut everything before the cursor
- Ctrl+k Cut everything after the cursor
- Ctrl+i Clear the terminal
- Ctrl+r Search command in history - type the search term
- Ctrl+b Move back one character
- Alt++b Move back one word
- Ctrl+f Move forward one character
- Alt++f Move forward one word
- Ctrl+d Delete current character
- Ctrl+w Cut the last word
- Alt++d Cut word after the cursor
- Alt++w Cut word before the cursor
- Ctrl+y Paste the last deleted command
- Ctrl+_ Undo
- Ctrl+xx Toggle between first and current position
- Ctrl+c Cancel the command
- Ctrl+j End the search at current history entry
- Ctrl+g Cancel the search and restore original line
- Ctrl+n Next command from the History
- 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 minpack.ps minpack.py
Check disk usage
sudo du -ah --max-depth=1 / | sort -hr
create crontab tasks with cron -e
Comments