This is a compilation of tips and tricks, tools and shortcuts for those who enjoy living inside a terminal.
I use debian + gnome3 + terminator + zsh + oh-my-zsh and some commands could not work on all terminals.
(from http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-productivity/)
Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
Ctrl + r – search the history backwards
Ctrl + g – escape from history searching mode
Ctrl + p – previous command in history (i.e. walk back through the command history)
Ctrl + n – next command in history (i.e. walk forward through the command history)
Alt + . – use the last word of the previous command
Ctrl + l – clear the screen
Ctrl + s – stops the output to the screen (for long running verbose command)
Ctrl + q – allow output to the screen (if previously stopped using command above)
Ctrl + c – terminate the command
Ctrl + z – suspend/stop the command
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
!! – run last command
!blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
!blah:p – print out the command that !blah would run (also adds it as the latest command in the command history)
!$ – the last word of the previous command (same as Alt + .)
!$:p – print out the word that !$ would substitute
!* – the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘)
!*:p – print out what !* would substitute
ctrl + 7 <- undo! (works for multiple records on history!!). Also ctrl + _
(motion) ctrl + x ctrl + e: opens default editor for power command editing (executes after quit on bash or leave command on prompt on zsh)
(more on shortcuts: https://ss64.com/bash/syntax-keyboard.html)
use bash-completion package in order to help yourself completing available commands. Zsh and oh-my-zsh is a great combination as it let you navigate through options.
apt install bash-completion
- Less is more than more
- cat
- tail
- head
- ccze -A: colorize (great combo with tail)
- ctrl + r: backward search
- ctrl + s: forward (only if
setty -ixon
) - sudo!!
``command $(command)```
backslash is your friend!
Some apps cand handle - as input instead of a filename. Example:
ls | vim -
will open ls ouput as content for vi
use two dashes to stop parsing parameters.
Example:
touch -- -hello
rm -- -hello
(remember those ugly filenames?)
tree -d -L 2
ssh user@host -C -t 'sudo apt update && sudo apt dist upgrade -y'
apt search stuff
dpkg-query --list
or dpkg -l
- env
- set
- sed
- awk
- grep + grep -v + grep -e
- htop
- ps aux
- killall
- locate/updatedb
:.w !bash
require sudo apt install notification-daemon libnotify-bin
(or only libnotify-bin)
example:
notify-send something
dosomething; notify-send
dosomething && notify-send good || notify-send bad
tail -f /tmp/kk.log | while read line; do notify-send "$line"; done
ssh -t millocal 'tail -f /tmp/was.log' | while read line; do notify-send "$line"; done
- my processes:
ps ux
- all processes
ps aux
- htop
- go background: ctrl + z
- list jobs:
jobs
- get job on foreground
fg
or%
or%[jobnumber]
or (zsh)%[command-name]
- sh vs bash vs zsh (+oh-my-zsh)
- debug script (set -x)
- do not beep, plz (setterm -blength 0)
- Any executable #!/path/to/tool (such as #!/bin/bash #!/bin/php
- Powerful find commands
- for f in $(command); do command; done
- redirect outputs (STDOUT STDERR...)
cat file.txt | xsel -i -b
or xclip -sel clip < wiki_snt_testing.txt
arp-scan -l
ethtool eth0
useful info such as link speed
wget -qO- ipecho.net/plain
or easier with curl curl ipecho.net/plain
curl wttr.in/alcala_de_henares
expr 5 * 111
will return 555
expr $(expr 5 \\* 111) : "5\+"
will count how many 'fives' the previous expr has
ping google.com -i 10| while read pong; do echo "$(date): $pong"; done
will ping each 10 seconds and decorate ping output with date
use ctrl + d instead as it will not keep the command on the history. Almost any console apps will quit (mysql, ssh sessions...)
cd /home/use
= cd $HOME
= cd ~
try cd /tmp
then cd -
. Will go to previous path. Do again to toggle between paths. Zsh can handle more records cd -3
. Use completion to see what
diff file1 file2
vimdiff file1 file2
also you by installing lynx
you can download any youtube video.