-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_help
84 lines (67 loc) · 2.79 KB
/
.bash_help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
########################################################################
# HISTORY:
########################################################################
!NUMBER - execute command <number>
!! - repeat last command
!xyz - repeat last command starting with xyz
!xyz:p -print last command starting with xyz
!$ - repeat the last argument of the last command(ex vim !$)
!* - repeat all arguments of the last command (echo !*)
^error^correction - replace first occurance of a with b in the last command and execute it
[root@master salt]# echo one tvo three
one tvo three
[root@master salt]# ^tvo^two
echo one two three
one two three
GET EXACT ARGUMENT
!:1 - get first argument
!:1-2 - get first and second argument
!:2-$ - get second to last arguments
:s substitute first occurance of the string
EX. !!:s/confih/config
:gs substitute all occurance of the string
EX. mroe /etc/hosts;more /etc/hostname
!:gs/mroe/more
CTRL+SHIFT+A - comment out current line
########################################################################
# MOVES:
########################################################################
^w erase word
^u erase from here to beginning of the line (I use this ALL the time.)
^k erase from here to beginning of the line (I use this ALL the time.)
^a move the cursor to the beginning of the line
^e move the curor to the end of the line
alt+[b,f] - move cursor back(forward) one word
alt+t - swap two words
########################################################################
# Word Modifiers
########################################################################
:h - Remove a trailing file name component, leaving only the head.
:t - Remove all leading file name components, leaving the tail.
:r - Remove a trailing suffix of the form .xxx, leaving the basename.
:e - Remove all but the trailing suffix.
EX:
cat /var/log/messages
cd !$:h -
!-5:t
GET EXACT ARGUMENT
!:1 - get first argument
!:1-2 - get first and second argument
!:2-$ - get second to last arguments
:s substitute first occurance of the string
EX. !!:s/confih/config
:gs substitute all occurance of the string
EX. mroe /etc/hosts;more /etc/hostname
!:gs/mroe/more
CTRL+SHIFT+A - comment out current line
CTRL+X,CTRL+E - open current command in $EDITOR
# COUNT output as a file
<()
diff <(grep somestring file1) <(grep somestring file2)
########################################################################
# REGEXP
########################################################################
To test RegExp in console, you can use following trick - let grep read from stdin, and use option -o to show only matching.
For example, to test RegExp which matches only lines with 8 or 9 at the end, execute:
grep -oE '.*(8|9)$'
Grep connects to stdin, and you can type any line you'd line. If line matches RegExp, you will receive a highlighted matched part