OSDN Git Service

Regular updates
[twpd/master.git] / command_line.md
1 ---
2 title: Command line stuff
3 ---
4
5 ## List (ls)
6
7     ls [options] [paths]
8
9 ### Format
10
11 | Switch | Description |
12 |---|---|
13 | `-1` | One entry per line |
14 | `-l` | Long view |
15 | `-o` | Long view (without groups) |
16 | `-C` | Multicolumn (sorted horizontally) |
17 | `-x` | Multicolumn (sorted vertically) |
18 |---
19 | `-F` | Add / after directories |
20 | `-G` | Color |
21 {:.shortcuts}
22
23 ### Options
24
25 | `-R` | Recurse |
26 | `-a` | Include hidden (dotfiles) |
27 | `-A` | Include hidden (but not . and ..) |
28 {:.shortcuts}
29
30 ### Sorting
31
32 | Switch | Description |
33 |---|---|
34 | `-r` | reverse order |
35 | `-S` | sort by size |
36 | `-t` | sort by time modified |
37 | `-u` | sort by time accessed |
38 | `-U` | sort by time created |
39 | `-c` | sort by time status was changed |
40 |---
41 | `-h` | Human-readable size (3k) |
42 {:.shortcuts}
43
44 <br>
45
46 ## Tail
47
48     tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]
49
50 ### Modes
51
52 | `-f` | follow |
53 | `-F` | follow by filename (accounts for log rotation) |
54 | `-r` | Reverse order |
55 {:.shortcuts}
56
57 ### Options
58
59 | `-bN` | N*512 bytes |
60 | `-cN` | N bytes |
61 | `-nN` | N lines |
62 | `+N`  | Start from line N |
63 {:.shortcuts}
64
65 <br>
66
67 ## Sudo
68
69 ```
70 sudo [options] <command>
71 ```
72
73 ### Listing
74
75 | `-l` | List allowed commands |
76 {:.shortcuts}
77
78 ### Options
79
80 | `-A` | Use $SUDO_ASKPASS |
81 | `-b` | Run in background |
82 | `-E` | Preserve environment |
83 | `-H` | use target's $HOME |
84 | `-n` | Don't prompt for password |
85 | `-P` | Preserve group vector |
86 | `-S` | Read password from stdin |
87 {:.shortcuts}
88
89 ### File descriptors
90
91 | `-C fd` | Close all open file descriptors |
92 {:.shortcuts}
93
94 ### Prompt
95
96 | `-p prompt` | Custom prompt (-p "%p password:") |
97 {:.shortcuts}
98
99 ### Interactive
100
101 | Switch | Description |
102 |---|---|
103 | `-i [cmd]` | Interactive shell without variables |
104 | `-s [cmd]` | Interactive shell |
105 |----
106 | `-u user` | run as this user |
107 | `-g group` | run as this group |
108 {:.shortcuts}
109
110 ### Timestamp
111
112 | `-v` | revalidate timestamp for 5 mins |
113 | `-k` | invalidate timestamp |
114 | `-K` | just like -k |
115 {:.shortcuts}
116
117 <br>
118
119 ## wc (Word count)
120
121 ```
122 ... | wc [options]
123 ```
124
125 | `-c` | Bytes |
126 | `-l` | Lines |
127 | `-m` | Characters (incl multi-byte) |
128 | `-w` | Words |
129 {:.shortcuts}
130
131 <br>
132
133 ## Search-and-replace in all files
134
135     perl -p -i -e 's/hello/HELLO/g' **/*
136
137 <br>
138
139 ## Grep
140
141 ```
142 grep [options] [pattern] [file ...]
143 ```
144
145 ### Options
146
147 | Switch | Description |
148 |---|---|
149 | `-A num` | Print `num` lines of training context |
150 |----
151 | `-G` | --basic-regexp (default) |
152 | `-E` | --extended-regexp |
153 | `-P` | --perl-regexp |
154 |----
155 | `-f file` | --file (Get patterns for file) |
156 | `-F` | --fixed-strings |
157 |----
158 | `-h` | --no-filename |
159 | `-H` | --with-filename |
160 |----
161 | `-l` | --files-with-matches (just print filenames) |
162 | `-L` | --files-without-match |
163 |----
164 | `-r, -R` | --recursive |
165 | `-v` | --invert-match |
166 | `-i` | --ignore-case |
167 {:.shortcuts}
168
169 ### Synonyms
170
171     egrep  =>  grep -E
172     fgrep  =>  grep -F