Bash Flashcards
Bash: how to delete from cursor to beginning of word?
ctrl-w
Bash: how to jump to end of line?
ctrl-e
Bash: how to jump to the beginning of line?
ctrl-a
Bash: how to jump one word backwards?
alt-b
Bash: how to jump one word forwards?
alt-f
Bash: how to delete from cursor to end of line?
ctrl-k
Bash: how to delete from cursor to beginning of line?
ctrl-u
Bash: how to go to previous directory (.bashrc shorthand)?
$ bd
Bash: how to go to previous directory with builtin?
$ cd -
Bash: how to do arithmetic calculations?
$(( expression ))
Bash: how to reuse argument of previous command?
!$
or
!:1
Example:
$ ls hello
$ ls !$
Bash: how to paste from special clipboard (ctrl-u & k use)?
ctrl-y
Bash: how to save output of command to file (overwrite)?
$ cmd > filename
Bash: how to save output of command to file (append)?
$ cmd»_space; filename
Bash: which command argument is usually used to display output (expanded format) before execution?
-x
Bash: how to display history of commands?
$ history
Bash: after displaying history - how to execute command by number?
$ !83
Bash: how to execute/reference previous command?
$ !!
or
$ !-1
Example:
$ echo /etc/test
$ sudo !!
Bash: How to execute command from history by keywords?
$ !?keyword
Bash: how to replace words from previous command (for example create file and view content)?
^search^replace^
Bash: how to get the first argument of a command starting with x?
!keyword:^
Example:
$ ls test
$ cd hallo
$ ls !ls:^
Bash: how to get filename of path from previous command?
!!:$:t
Example:
$ cat /etc/test/hallo.txt
$ vim !!:$:t
returns: hallo.txt
Bash: how to delete extension from path from previous command?
!!:$:r
Example:
$ cat /etc/test/hallo.txt
$ vim !!:$:t
returns: /etc/test/hallo
Bash: How to do sed like substitution of previous command?
!!:s/search/replace
Bash: how to repeat previous substitution on previous command?
!!:g&
& becomes a and sign (has been escaped)
Bash: how to print substition before executing it?
append “:p” to substitution
Bash: how to change 3 directories up (own helper in .bashrc)
$ ….
Bash: how to change 2 directories up (own helper in .bashrc)
$ …
Bash: how to change 1 directory up (own helper in .bashrc)
$ ..