Bash Flashcards

(73 cards)

1
Q

Bash: how to delete from cursor to beginning of word?

A

ctrl-w

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bash: how to jump to end of line?

A

ctrl-e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Bash: how to jump to the beginning of line?

A

ctrl-a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bash: how to jump one word backwards?

A

alt-b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Bash: how to jump one word forwards?

A

alt-f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Bash: how to delete from cursor to end of line?

A

ctrl-k

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Bash: how to delete from cursor to beginning of line?

A

ctrl-u

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Bash: how to go to previous directory (.bashrc shorthand)?

A

$ bd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Bash: how to go to previous directory with builtin?

A

$ cd -

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Bash: how to do arithmetic calculations?

A

$(( expression ))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Bash: how to reuse argument of previous command?

A

!$
or
!:1

Example:
$ ls hello
$ ls !$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Bash: how to paste from special clipboard (ctrl-u & k use)?

A

ctrl-y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Bash: how to save output of command to file (overwrite)?

A

$ cmd > filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Bash: how to save output of command to file (append)?

A

$ cmd&raquo_space; filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Bash: which command argument is usually used to display output (expanded format) before execution?

A

-x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Bash: how to display history of commands?

A

$ history

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Bash: after displaying history - how to execute command by number?

A

$ !83

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Bash: how to execute/reference previous command?

A

$ !!
or
$ !-1

Example:
$ echo /etc/test
$ sudo !!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Bash: How to execute command from history by keywords?

A

$ !?keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Bash: how to replace words from previous command (for example create file and view content)?

A

^search^replace^

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Bash: how to get the first argument of a command starting with x?

A

!keyword:^

Example:
$ ls test
$ cd hallo
$ ls !ls:^

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Bash: how to get filename of path from previous command?

A

!!:$:t

Example:
$ cat /etc/test/hallo.txt
$ vim !!:$:t
returns: hallo.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Bash: how to delete extension from path from previous command?

A

!!:$:r

Example:
$ cat /etc/test/hallo.txt
$ vim !!:$:t
returns: /etc/test/hallo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Bash: How to do sed like substitution of previous command?

A

!!:s/search/replace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Bash: how to repeat previous substitution on previous command?
!!:g& | & becomes a and sign (has been escaped)
26
Bash: how to print substition before executing it?
append ":p" to substitution
27
Bash: how to change 3 directories up (own helper in .bashrc)
$ ....
28
Bash: how to change 2 directories up (own helper in .bashrc)
$ ...
29
Bash: how to change 1 directory up (own helper in .bashrc)
$ ..
30
Bash: how to securely clear the screen of terminals?
$ clear
31
Bash: how to append text found by delimiter of another file into another file (heredocument syntax)?
$ cat >> path/to/file << ""
32
Bash: how to save current directory as name "test" to bashmarks?
$ s test
33
Bash: how to list all bashmarks folders and names?
$ l
34
Bash: how to go to bashmark with name test?
$ g test
35
Bash: how to get the first column of output?
$ | awk -v col=1 '{print $col}'
36
Bash: how to create directories for folder names inside file?
for a in `cat ./dirs`; do mkdir $a; done
37
Bash: what is xargs used for?
It is used to build and execute command lines from standard input. For example: $ cat dirs | xargs mkdir will use cat to take the strings (be it newline or blank character separated) from file ‘dirs’ and pass them through pipe to xargs which will then send one by one line as argument to mkdir which will then create those dirs or complain if those are existent.
38
Bash: how to delete filename (get folder) from path of previous command?
!!:$:h Example: $ cat /test/hallo.txt $ cd !!:$:h
39
Bash: how to get the first argument of the previous command?
!!:^
40
Bash: how to jump between start of line and cursor position?
ctrl-xx
41
Bash: how to delete from cursor to end of word?
alt-d
42
Bash: how to swap character with previous one?
ctrl-t
43
Bash: how to delete character before cursor?
ctrl-h
44
Bash: how to delete character under cursor?
ctrl-d
45
Bash: how to enter the search mode in history by keywords?
ctrl-r
46
Bash: how to get the previous command (instead of arrow up)?
ctrl-p
47
Bash: how to get the next command (instead of arrow down)?
ctrl-n
48
Bash: how to get the last word of the previous command with shortcuts?
alt-.
49
Bash: how to make lowercase from cursor to end of word?
alt-l
50
Bash: how to make uppercase from cursor to end of word?
alt-u
51
Bash: how to run a command found in history mode (ctrl-r)?
ctrl-o
52
Bash: how to scroll one line up?
ctrl-shift-arrow up
53
Bash: how to scroll one line down?
ctrl-shift-arrow down
54
Bash: how to swap word with previous one?
alt-t
55
Bash: how to remove preceding path from filename in variable f?
${f##*/}
56
Bash: how to remove extension from filename in variable f?
${f%.*}
57
Bash: how to replace string in variable (first occurance)?
${variable/search/replace} ${$var... not working!
58
Bash: how to remove string at beginning of variable?
${var#string_to_remove}
59
Bash: how to remove string at end of variable?
${var%string_to_remove}
60
Bash: how to replace all occurances of search with replace in variable?
${variable//search/replace} ${$var... not working!
61
Bash: how to get the Process ID of a process with name "x"?
pidof x
62
Bash: how to kill process with id x?
kill x
63
Bash: how to kill process listening on port?
fuser -n tcp -k 9001
64
Bash: how to copy files an rename?
for file in bin/docker-create-build-*.in; do cp $file ${file/local/live}; done
65
Bash: how to get files which changed in the last 2 mins?
find . -mmin -2 -type f print
66
Bash: How to search for string starting with "test" and only print the match?
echo "test32. 23232. 23232" | grep -o 'test[^\s]*'
67
Bash: How to get item index 0 from array x?
${x[0]}
68
Bash: How to iterate over an array with a for loop counting the index?
for ((x = 0; x < ${#array[@]}; x++)); then...
69
Bash: how to fer the exit status of decent Command?
$?
70
Bash: how to get the Process id of a Bash Command ein in background?
it Returns the process id
71
Bash: How to list directories recursively?
find . -type d -print
72
Bash: how to list files recursively?
find . -type f -print
73
Bash: how to remove all files execpt?
rm -r !(file1|file2)