-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbashSheet.tex
More file actions
243 lines (233 loc) · 8.22 KB
/
bashSheet.tex
File metadata and controls
243 lines (233 loc) · 8.22 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
%%Strictly a bash cheat sheet.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{relsize}
\usepackage{float}
\usepackage{longtable}
\begin{document}
\begin{center}
\begin{longtable}{||p{5.5cm}|p{5.5cm}||} %longtable so it wraps pages
\caption{Bash commands and what they mean}
%make the main header
\\\hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endfirsthead
%make the next page header
\hline
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued from previous page}}
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endhead
%make the previous page footer
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued on next
page}} \\ \hline
\endfoot
%make the last footer
\hline
\endlastfoot
%contents of the table
\verb|ls| & list contents of current directory
\\ \hline
\verb|ls -a| & show hidden files too \\ \hline
\verb|ls -altr| & see the last changes made to
the files in a directory \\ \hline
\verb|mkdir directory| & make a new directory
\\ \hline
\verb|cd directory| & change directory \\ \hline
\verb|cd .. |& go back a directory \\ \hline
\verb|cd ../..| & go back two directories \\ \hline
\verb|cd ~ |& go to your root \\ \hline
\verb|pwd| & print working directory \\ \hline
\verb|~/| & means your root \\ \hline
\verb|.| & means the current directory \\ \hline
\verb|cp file/to/copy where/newName| & copy
a file \\ \hline
\verb|cp file/to/copy .| & copy a file to current
directory without changing the name \\ \hline
\verb|cp directory/* . |& copy all the files in a
directory \\ \hline
& to the current directory \\ \hline
\verb|cp -r directory new/directory| & copy a
directory recursively \\ \hline
\verb|rm file/to/remove| & remove a file \\ \hline
\verb|rmdir directory| & remove a directory \\ \hline
\verb|rm -rf directory| & blow away a directory
permanently \\ \hline
\verb|mv file/to/move where/newName| & moves
or renames a file \\ \hline
\verb|man command| & show the manual for a
command \\ \hline
\verb|cat file/one file/two| \textgreater \verb| new_file|
& concatonate two or more
files into a new file \\ \hline
\verb|history| & shows a history of your
commands \\ \hline
\verb|less file/to/see| & shows one page of a
file \\ \hline
& space turns the page q quits \\ \hline
\verb|head file/to/see| & see the first page
of a file \\ \hline
\verb|head -n 8 file/to/see| & see the first 8 lines
of a file \\ \hline
\verb|tail file/to/see| & see the last page of a file
\\ \hline
\verb|tail -n 10 file/to/see| & see the last 10 lines
of a file \\ \hline
\verb|grep keyword file/to/search| & search a file
for a keyword and print all the lines with
that
keyword
to the
screen \\ \hline
\verb|history |\textbar\verb| grep keyword| & search your history
for a keyword \\ \hline
\verb|grep keyword file/to/search|& count
the occurences of lines with a \\
\textbar \verb| wc -l| & keyword\\ \hline
\verb|command |\textbar \verb| less| & pipe the output of a command
to less \\ \hline
\verb|command |\textgreater\textgreater\verb| file|
& append the output of a
command to a file \\ \hline
\verb|command |\textgreater \verb| file| & writes the output of the
command to a file \\ \hline
\verb|!command| & executes the most recent command
that starts with the letters you typed \\ \hline
\verb|echo something| & print something to the screen \\\hline
\verb|ls -altr| & see when files in the directory were last
altered \\\hline
\verb|sed -i 's/to replace/new| & find and replace a phrase in a
file \\
\verb|phrase/' file/to/search| & \\ \hline
\verb|grep -Rl keyword| & recursively search for a keyword and
print the file it was found in \\\hline
\verb|awk '!a[$0]++' file/to/search| & get rid of duplicate lines
\\\hline
\verb|echo "phrase" >> file/to/append| & append a phrase to a file \\\hline
\end{longtable}
\end{center}
\begin{center}
\begin{longtable}{||p{4.5cm}|p{6.5cm}||}%longtable so it wraps pages
\caption{Emacs commands and what they mean}
%first header
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endfirsthead
%next page header
\hline
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued from previous page}}
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endhead
%footer
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued on next
page}} \\ \hline
\endfoot
%last footer
\hline
\endlastfoot
%contents of table
\verb|emacs path/to/file| & enter emacs editor for
existing file or creates new file with that name \\ \hline
ctrl+x ctrl+s & save file \\ \hline
ctrl+x ctrl+c y & save and quit a file \\ \hline
ctrl+x ctrl+c n & quit without saving \\ \hline
ctrl+w & cut a line (highlight line first) \\ \hline
ctrl+y & paste a line \\ \hline
ctrl+k & kills the contents of a line/cut a line \\ \hline
ctrl+k ctrl+k ... & kills however many lines--helpful to copy and
paste blocks of code \\ \hline
ctrl+shift+- & undo \\ \hline
ctrl+u \verb|3 command| & executes the command 3 times \\ \hline
ctrl+x ctrl+f & find and open a file (at the bottom of the screen)\\ \hline
ctrl+space & set marker \\ \hline
\multicolumn{2}{||c||}{Add text to a block of code}
\\ \hline
ctrl+space & set marker \\
ctrl+x & set end of rectangle\\
R & format as rectangle\\
T ``text" & add text\\
or k & or delete \\
\end{longtable}
\end{center}
\begin{center}
\begin{longtable}{||p{4.5cm}|p{6.5cm}||}
\caption{Loops in bash}
%first header
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endfirsthead
%next page header
\hline
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued from previous page}}
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endhead
% footer
\\ \hline
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued on next
page}} \\ \hline
\endfoot
%last footer
\hline
\endlastfoot
%contents of table
\verb|for i in {1..100}| & for 100 iterations \\
\verb|do|& \\
\verb|command $i| & do this thing(\verb|$i| \\
\verb|done| & references the index)\\
\hline
\verb|if [ condition ]| & check the condition \\
\verb|then| & if it's true \\
\verb|command| & do this \\
\verb|else| & if it's not \\
\verb|command| & do this \\
\verb|fi| & ends if statement \\ \hline
\verb|if [ -e file ] |& check if a file exists \\ \hline
\verb|for i in `ls -d */`| & visit every directory in the current \\
\verb|do cd $i| & directory \\
\verb|command| & and execute some command \\
\verb|cd .. done| & \\ \hline
\hline
\end{longtable}
\end{center}
\begin{center}
\begin{longtable}{||p{4.5cm}|p{6.5cm}||}
\caption{Example of a Bash loop}
%first header
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endfirsthead
%next page header
\hline
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued from previous page}}
\\ \hline
\textbf{Command} & \textbf{What it does}\\ \hline \hline
\endhead
%footer
\multicolumn{2}{||c||}
{\tablename\ \thetable\ -- \textit{Continued on next
page}} \\ \hline
\endfoot
%last page footer
\hline
\endlastfoot
\verb|for i in `ls -d */`| & for all directories \\
\verb|do| & \\
\verb|cd $i| & enter the directory named\\
\verb|if [! -f KPOINTS]|& if KPOINTS doesn't exist\\
\verb|then getKPoints| & run the getKPoints script \\
\verb|echo $i| & print the directory number \\
\verb|fi| & end if statement\\
\verb|cd ..| & go back one directory \\
\verb|done|& close loop\\
\end{longtable}
\end{center}
\end{document}