-
Notifications
You must be signed in to change notification settings - Fork 0
/
easily-remember-linux-commands-44191f6843f6.html
322 lines (270 loc) · 11.7 KB
/
easily-remember-linux-commands-44191f6843f6.html
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="" />
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,400;0,700;1,400&family=Source+Sans+Pro:ital,wght@0,300;0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./theme/stylesheet/style.min.css">
<link id="pygments-light-theme" rel="stylesheet" type="text/css"
href="./theme/pygments/github.min.css">
<link rel="stylesheet" type="text/css" href="./theme/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="./theme/font-awesome/css/brands.css">
<link rel="stylesheet" type="text/css" href="./theme/font-awesome/css/solid.css">
<link href="https://shanedowling.com/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Shane Dowling Atom">
<link href="https://shanedowling.com/feeds/all.rss.xml" type="application/rss+xml" rel="alternate" title="Shane Dowling RSS">
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'G-Z9P3V6D0SV', 'auto');
ga('send', 'pageview');
</script>
<meta name="author" content="Shane Dowling" />
<meta name="description" content="I use an absolute ton of awesome tools my various linux distros. The problem is I tend to forget a lot of the time how to use the tools, so I got a list of frequently used command with and a few examples of how to use them from here …" />
<meta name="keywords" content="">
<meta property="og:site_name" content="Shane Dowling"/>
<meta property="og:title" content="Easily remember linux commands"/>
<meta property="og:description" content="I use an absolute ton of awesome tools my various linux distros. The problem is I tend to forget a lot of the time how to use the tools, so I got a list of frequently used command with and a few examples of how to use them from here …"/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="./easily-remember-linux-commands-44191f6843f6.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2012-02-19 00:00:00+00:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="./author/shane-dowling.html">
<meta property="article:section" content="Tech"/>
<meta property="og:image" content="/images/logo.png">
<title>Shane Dowling – Easily remember linux commands</title>
</head>
<body class="light-theme">
<aside>
<div>
<a href="./">
<img src="/images/logo.png" alt="Shane Dowling" title="Shane Dowling">
</a>
<h1>
<a href="./">Shane Dowling</a>
</h1>
<p>Platform Engineering Manager</p>
<nav>
<ul class="list">
<li>
<a target="_self"
href="./pages/contact.html#contact">
Contact
</a>
</li>
<li>
<a target="_self"
href="./pages/now-page.html#now-page">
Now Page
</a>
</li>
<li>
<a target="_self"
href="./pages/statuslog.html#statuslog">
Statuslog
</a>
</li>
<li>
<a target="_self" href="https://hybridcloudshow.com/" >podcast</a>
</li>
<li>
<a target="_self" href="https://pemonthly.com/" >newsletter</a>
</li>
</ul>
</nav>
<ul class="social">
<li>
<a class="sc-github"
href="http://github.com/shano"
target="_blank">
<i class="fa-brands fa-github"></i>
</a>
</li>
<li>
<a class="sc-mastodon"
rel="me" href="http://social.lol/@sed"
target="_blank">
<i class="fa-brands fa-mastodon"></i>
</a>
</li>
<li>
<a class="sc-linkedin"
href="https://www.linkedin.com/in/shanedow/"
target="_blank">
<i class="fa-brands fa-linkedin"></i>
</a>
</li>
</ul>
</div>
</aside>
<main>
<article class="single">
<header>
<h1 id="easily-remember-linux-commands-44191f6843f6">Easily remember linux commands</h1>
<p>
Posted on Sun 19 February 2012 in <a href="./category/tech.html">Tech</a>
</p>
</header>
<div>
<p>I use an absolute ton of awesome tools my various linux distros. The
problem is I tend to forget a lot of the time how to use the tools, so I
got a list of frequently used command with and a few examples of how to
use them from <a href="http://www.thegeekstuff.com/2010/11/50-linux-commands/">here</a>.</p>
<p>So here's the file I use.</p>
<p>— Create a new tar archive
$ tar cvf archive_name.tar dirname/
— Extract from an existing tar archive.
$ tar xvf archive_name.tar
— Grep for a given string in a file (case in-sensitive search).
$ grep -i "the" demo_file
— Print the grep line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
— Grep for a given string in all files recursively
$ grep -r "ramesh" *
— Grep for a string that starts with $ char and contains what's in $1
grep — color=auto -B 1 -E '^$.b'$1'b' cmd_examples.txt
— Find files using file-name ( case in-sensitve find)
$ find -iname "MyCProgram.c"
— Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} ;
— Find all empty files in home directory
$ find ~ -empty
— Converts the DOS file format to Unix file format using sed command.
$ sed 's/.$//' filename
— Print file content in reverse order
$ sed -n '1!G;h;$p' thegeekstuff.txt
— Add line number for all non-empty-lines in a file
$ sed '/./=' thegeekstuff.txt | sed 'N; s/n/ /'
— Remove duplicate lines using awk
$ awk '!($0 in array) { array[$0]; print }' temp
— Print all lines from /etc/passwd that has the same uid and gid
$ awk -F ':' '$3==$4' passwd.txt
— Print only specific field from a file.
$ awk '{print $2,$5;}' employee.txt
— Diff ignore white space while comparing.
$ diff -w name_list.txt name_list_new.txt
— Sort a file in ascending order
$ sort names.txt
— Sort a file in descending order
$ sort -r names.txt
— Sort passwd file by 3rd field.
— Xarg:Copy all images to external hard-drive
$ ls <em>.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
— Xarg:Search all jpg images in the system and archive it.
$ find / -name </em>.jpg -type f -print | xargs tar -cvzf images.tar.gz
— XargLDownload all the URLs mentioned in the url-list.txt file
$ cat url-list.txt | xargs wget –c
— LS:Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
— LS:Visual Classification of Files With Special Characters Using ls -F
$ ls -F
— Gzip:Display compression ratio of the compressed file using gzip -l
$ gzip -l <em>.gz
$ bzip2 test.txt
$ bzip2 -d test.txt.bz2
— UNZip:View the contents of </em>.zip file (Without unzipping it):
$ unzip -l jasper.zip
— Shutdown the system after 10 minutes.
$ shutdown -h +10
— Force the filesystem check during reboot.
# shutdown -Fr now
— FTP:Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.
$ ftp IP/hostname
— FTP:To download a file
$ ftp> mget <em>.html
— To view the file names located on the remote server before downloading, mls ftp command as shown below.
$ ftp> mls </em>.html -
— View crontab entry for a specific user
$ crontab -u john -l
— Schedule a cron job every 10 minutes.
$ <em>/10 * * * * /home/ramesh/check-disk-cron
$ service ssh status
— Status:Check the status of all the services.
$ service — status-all
— Restart a service.
# service ssh restart
— To view current running processes.
$ ps -ef | more
— To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
$ df -T
$ rm -i filename.txt
$ rm -i file</em>
— Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
— While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf
— Give full access to user and group (i.e read, write and execute ) on a specific file.
$ chmod ug+rwx file.txt
— Revoke all access for the group (i.e read, write and execute ) on a specific file.
$ chmod g-rwx file.txt
— Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt
— To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.
$ chown oracle:dba dbora.sh
— Create nested directories using one mkdir command.
$ mkdir -p dir1/dir2/dir3/dir4/
— Sample uname output from a Ubuntu laptop is shown below.
$ uname -a
— When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.
$ whereis ls
— This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.
$ whereis -u -B /tmp -f lsmk
— Whatis command displays a single line description about a command.
$ whatis ls
— The example below shows all files in the system that contains the word crontab in it.
$ locate crontab
— Print the last 10 lines of a file by default.
$ tail filename.txt
— Print N number of lines from the file named filename.txt
$ tail -n N filename.txt
— View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.
$ tail -f log-file
— less is very efficient while viewing huge log files, as it doesn't need to load the full file while opening.
$ less huge-log-file.log
— Ping a remote host by sending only 5 packets.
$ ping -c 5 gmail.com
— Download and store it with a different name.
$ wget -O taglist.zip <a href="http://www.vim.org/scripts/download_script.php?src_id=7701">http://www.vim.org/scripts/download_script.php?src_id=7701</a></p>
<p>Then I use this command to search for the specific command and get back
the examples with an explanation. Please note, to add your own examples,
you need to save the same format of the command starting with a $ and
the line above providing the explanation. When you do a search you must
search for the command.</p>
<p>grep — color=auto -B 1 -E '^$.bpingb' ~/cmd_examples.txt</p>
<p>And if you wish to use it in a bash alias, you'll need to create a
function</p>
<p>function exam() { grep — color=auto -B 1 -E '^$.b'"$*"'b' ~/cmd_examples.txt ;}</p>
<p>Calling</p>
<p>$ exam ping</p>
<p>should return</p>
<p>— Ping a remote host by sending only 5 packets.</p>
<p>$ ping -c 5 gmail.com</p>
</div>
<div class="tag-cloud">
<p>
</p>
</div>
</article>
<footer>
<p>© </p>
<p>
Built with <a href="http://getpelican.com" target="_blank">Pelican</a> using <a href="http://bit.ly/flex-pelican" target="_blank">Flex</a> theme
</p></footer> </main>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Blog",
"name": " Shane Dowling ",
"url" : ".",
"image": "/images/logo.png",
"description": ""
}
</script>
</body>
</html>