Bash Flashcards

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
Q

Bash: how to repeat previous substitution on previous command?

A

!!:g&

& becomes a and sign (has been escaped)

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

Bash: how to print substition before executing it?

A

append “:p” to substitution

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

Bash: how to change 3 directories up (own helper in .bashrc)

A

$ ….

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

Bash: how to change 2 directories up (own helper in .bashrc)

A

$ …

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

Bash: how to change 1 directory up (own helper in .bashrc)

A

$ ..

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

Bash: how to securely clear the screen of terminals?

A

$ clear

31
Q

Bash: how to append text found by delimiter of another file into another file (heredocument syntax)?

A

$ cat&raquo_space; path/to/file &laquo_space;””

32
Q

Bash: how to save current directory as name “test” to bashmarks?

A

$ s test

33
Q

Bash: how to list all bashmarks folders and names?

A

$ l

34
Q

Bash: how to go to bashmark with name test?

A

$ g test

35
Q

Bash: how to get the first column of output?

A

$ | awk -v col=1 ‘{print $col}’

36
Q

Bash: how to create directories for folder names inside file?

A

for a in cat ./dirs; do mkdir $a; done

37
Q

Bash: what is xargs used for?

A

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
Q

Bash: how to delete filename (get folder) from path of previous command?

A

!!:$:h

Example:
$ cat /test/hallo.txt
$ cd !!:$:h

39
Q

Bash: how to get the first argument of the previous command?

A

!!:^

40
Q

Bash: how to jump between start of line and cursor position?

A

ctrl-xx

41
Q

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

A

alt-d

42
Q

Bash: how to swap character with previous one?

A

ctrl-t

43
Q

Bash: how to delete character before cursor?

A

ctrl-h

44
Q

Bash: how to delete character under cursor?

A

ctrl-d

45
Q

Bash: how to enter the search mode in history by keywords?

A

ctrl-r

46
Q

Bash: how to get the previous command (instead of arrow up)?

A

ctrl-p

47
Q

Bash: how to get the next command (instead of arrow down)?

A

ctrl-n

48
Q

Bash: how to get the last word of the previous command with shortcuts?

A

alt-.

49
Q

Bash: how to make lowercase from cursor to end of word?

A

alt-l

50
Q

Bash: how to make uppercase from cursor to end of word?

A

alt-u

51
Q

Bash: how to run a command found in history mode (ctrl-r)?

A

ctrl-o

52
Q

Bash: how to scroll one line up?

A

ctrl-shift-arrow up

53
Q

Bash: how to scroll one line down?

A

ctrl-shift-arrow down

54
Q

Bash: how to swap word with previous one?

A

alt-t

55
Q

Bash: how to remove preceding path from filename in variable f?

A

${f##*/}

56
Q

Bash: how to remove extension from filename in variable f?

A

${f%.*}

57
Q

Bash: how to replace string in variable (first occurance)?

A

${variable/search/replace}

${$var… not working!

58
Q

Bash: how to remove string at beginning of variable?

A

${var#string_to_remove}

59
Q

Bash: how to remove string at end of variable?

A

${var%string_to_remove}

60
Q

Bash: how to replace all occurances of search with replace in variable?

A

${variable//search/replace}

${$var… not working!

61
Q

Bash: how to get the Process ID of a process with name “x”?

A

pidof x

62
Q

Bash: how to kill process with id x?

A

kill x

63
Q

Bash: how to kill process listening on port?

A

fuser -n tcp -k 9001

64
Q

Bash: how to copy files an rename?

A

for file in bin/docker-create-build-*.in; do cp $file ${file/local/live}; done

65
Q

Bash: how to get files which changed in the last 2 mins?

A

find . -mmin -2 -type f print

66
Q

Bash: How to search for string starting with “test” and only print the match?

A

echo “test32. 23232. 23232” | grep -o ‘test[^\s]*’

67
Q

Bash: How to get item index 0 from array x?

A

${x[0]}

68
Q

Bash: How to iterate over an array with a for loop counting the index?

A

for ((x = 0; x < ${#array[@]}; x++)); then…

69
Q

Bash: how to fer the exit status of decent Command?

A

$?

70
Q

Bash: how to get the Process id of a Bash Command ein in background?

A

it Returns the process id

71
Q

Bash: How to list directories recursively?

A

find . -type d -print

72
Q

Bash: how to list files recursively?

A

find . -type f -print

73
Q

Bash: how to remove all files execpt?

A

rm -r !(file1|file2)