-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-cute-and-fluffy-intro-to-linux-aka-yet-another-linux-guide.html
1730 lines (1439 loc) · 85.4 KB
/
my-cute-and-fluffy-intro-to-linux-aka-yet-another-linux-guide.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Cute and Fluffy Intro to Linux (aka Yet Another Linux Guide)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Marina von Steinkirch">
<!-- Le styles -->
<link rel="stylesheet" href="./theme/css/bootstrap.dark.css" type="text/css" />
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.tag-1 {
font-size: 13pt;
}
.tag-2 {
font-size: 11pt;
}
.tag-2 {
font-size: 10pt;
}
.tag-4 {
font-size: 8pt;
}
</style>
<link href="./theme/css/bootstrap-responsive.dark.css" rel="stylesheet">
<link href="./theme/css/font-awesome.css" rel="stylesheet">
<link href="./theme/css/pygments.css" rel="stylesheet">
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="./theme/images/favicon.ico">
<link rel="apple-touch-icon" href="./theme/images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="./theme/images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="./theme/images/apple-touch-icon-114x114.png">
<link href="./feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="chmod +x singularity.sh ATOM Feed" />
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="./index.html">chmod +x singularity.sh </a>
<div class="nav-collapse">
<ul class="nav">
<li class="divider-vertical"></li>
<ul class="nav pull-right">
<li><a href="./authors.html">About</a></li>
<li><a href="./archives.html"><b>Archives</b></a></li>
<li>
<a href="https://github.com/bt3gl">github
<!--<i class="icon-github-sign icon-large" ></i>-->
</a></li>
<li>
<a href="https://twitter.com/1bt337">
<!--<i class="icon-twitter-sign icon-large"></i> -->
twitter
</a></li>
<li><a href="http://bt3gl.github.io/projects_page/index.html">Bygone Playful Times
</a></li>
</ul>
</ul>
<!--<p class="navbar-text pull-right">Logged in as <a href="#">username</a></p>-->
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="span9" id="content">
<section id="content">
<article>
<header>
<h1>
<a href=""
rel="bookmark"
title="Permalink to My Cute and Fluffy Intro to Linux (aka Yet Another Linux Guide)">
My Cute and Fluffy Intro to Linux (aka Yet Another Linux Guide)
</a>
</h1>
</header>
<div class="entry-content">
<div class="well">
<footer class="post-info">
<abbr class="published" title="2014-11-10T04:20:00">
Mon 10 November 2014 </abbr>
<span class="label"> Category</span>
<a href="./category/lifeuniverseeverything.html"><i class="icon-folder-open"></i>Life,Universe,Everything</a>
<span class="label">Tags</span>
<a href="./tag/linux.html"><i class="icon-tag"></i>Linux</a>
<a href="./tag/python.html"><i class="icon-tag"></i>Python</a>
<a href="./tag/unicode.html"><i class="icon-tag"></i>Unicode</a>
<a href="./tag/tr.html"><i class="icon-tag"></i>tr</a>
<a href="./tag/ifconfig.html"><i class="icon-tag"></i>ifconfig</a>
<a href="./tag/ssh.html"><i class="icon-tag"></i>ssh</a>
<a href="./tag/netcat.html"><i class="icon-tag"></i>netcat</a>
<a href="./tag/stripe.html"><i class="icon-tag"></i>Stripe</a>
</footer><!-- /.post-info --> </div>
<p>Being a Linux user is, above all, a <em>life style</em>. Interestingly, more and more people have been joining this community, keeping it dynamic and organic.</p>
<p>Linux has been in my life since my high school years and I'm still constantly inspired by the fact that it has not lost any of its appeal. There is always something new or deeper to be learned. Linux is <em>the</em> tool for those who choose to spend their excess of curiosity flying around bytes.</p>
<p>With the novice in mind, this blog post is my introduction to the Linux machinery, containing some of my favorite tricks. I hope you enjoy this exciting adventure of taking control of <em>The Machine</em>.</p>
<p><strong>Disclaimer I</strong>: Keep in mind that the truly way for mastering Linux is making the <strong>man</strong> and <strong>help</strong> pages in the command line your best friends:</p>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">man</span> <span class="o"><</span><span class="nb">COMMAND</span><span class="o">></span>
</pre></div>
<p><strong>Disclaimer II</strong>: The Linux distributions I'm current using are Fedora and Kali (Debian-based). You should be comfortable exploring several distributions until you find your favorite. You should definitely aim to go beyond Ubuntu.</p>
<p><strong>Disclaimer III</strong>: This guide is written for <a href="http://www.gnu.org/software/bash/">bash</a>. I encourage you to go further and search for your favorite shell.</p>
<hr />
<h1>The Linux Environment</h1>
<h2>The Linux Filesystem</h2>
<ul>
<li>Let's start getting an idea of our system. The <em>Linux filesystem</em> is composed of several system directories locate at <strong>/</strong>:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ls</span> <span class="o">/</span>
</pre></div>
<p><img alt="" src="http://i.imgur.com/qhYyiK8.png" /></p>
<ul>
<li>You can verify their sizes and where they are mounted with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">df</span> <span class="o">-</span><span class="n">h</span> <span class="p">.</span>
<span class="n">Filesystem</span> <span class="n">Type</span> <span class="n">Size</span> <span class="n">Used</span> <span class="n">Avail</span> <span class="n">Use</span><span class="o">%</span> <span class="n">Mounted</span> <span class="n">on</span>
<span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">mapper</span><span class="o">/</span><span class="n">fedora</span><span class="o">-</span><span class="n">home</span> <span class="n">ext4</span> <span class="mi">127</span><span class="n">G</span> <span class="mi">62</span><span class="n">G</span> <span class="mi">59</span><span class="n">G</span> <span class="mi">51</span><span class="o">%</span> <span class="o">/</span><span class="n">home</span>
</pre></div>
<ul>
<li>The filesystem architecture is generally divided into the following folders:</li>
</ul>
<h3>/bin, /sbin and /user/sbin</h3>
<ul>
<li>
<p><strong>/bin</strong> is a directory containing executable binaries, essential commands used in single-user mode, and essential commands required by all system users.</p>
</li>
<li>
<p><strong>/sbin</strong> contains commands that are not essential for the system in single-user mode.</p>
</li>
</ul>
<h3>/dev</h3>
<ul>
<li>
<p><strong>/dev</strong> contains device nodes, which are a type of pseudo-file used by most hardware and software devices (except for network devices).</p>
</li>
<li>
<p>The directory also contains entries that are created by the <strong>udev</strong> system, which creates and manages device nodes on Linux (creating them dynamically when devices are found).</p>
</li>
</ul>
<h3>/var</h3>
<ul>
<li>
<p><strong>/var</strong> stands for <em>variable</em> and contains files that are expected to be changing in size and content as the system is running.</p>
</li>
<li>
<p>For example, the system log files are located at <strong>/var/log</strong>, the packages and database files are located at <strong>/var/lib</strong>, the print queues are located at <strong>/var/spool</strong>, temporary files stay inside <strong>/var/tmp</strong>, and networks services can be found in subdirectories such as <strong>/var/ftp</strong> and <strong>/var/www</strong>.</p>
</li>
</ul>
<h3>/etc</h3>
<ul>
<li>
<p><strong>/etc</strong> is short for <em>et cetera</em> and contains the system configuration files. It contains no binary programs, but it might have some executable scripts.</p>
</li>
<li>
<p>For instance, the file <strong>/etc/resolv.conf</strong> tells the system where to go on the network to obtain the host name of some IP address (<em>i.e.</em> DNS).</p>
</li>
<li>
<p>The <strong>/etc/passwd</strong> file is the authoritative list of users on any Unix system. It does not contain the passwords: the encrypted password information was migrated into <strong>/etc/shadow</strong>.</p>
</li>
<li>
<p>The <strong>/etc/hosts</strong> contains a list of hostname to IP address mappings, which can be used to assign names to servers, independently of the public DNS service.</p>
</li>
</ul>
<h3>/lib</h3>
<ul>
<li>
<p><strong>/lib</strong> contains libraries (common code shared by applications and needed for them to run) for essential programs in <strong>/bin</strong> and <strong>/sbin</strong>.</p>
</li>
<li>
<p>This library filenames either start with <code>ld</code> or <code>lib</code> and are called <em>dynamically loaded libraries</em> (or shared libraries).</p>
</li>
</ul>
<h3>/boot</h3>
<ul>
<li>
<p><strong>/boot</strong> contains the few essential files needed to boot the system.</p>
</li>
<li>
<p>For every alternative kernel installed on the system, there are four files:</p>
<ul>
<li>
<p><code>vmlinuz</code>: the compressed Linux kernel, required for booting.</p>
</li>
<li>
<p><code>initramfs</code> or <code>initrd</code>: the initial RAM filesystem, required for booting.</p>
</li>
<li>
<p><code>config</code>: the kernel configuration file, used for debugging.</p>
</li>
<li>
<p><code>system.map</code>: the kernel symbol table.</p>
</li>
<li>
<p><a href="http://null-byte.wonderhowto.com/how-to/hack-like-pro-linux-basics-for-aspiring-hacker-part-21-grub-bootloader-0154965/">GRUB</a> files can also be found here (in /boot/grub/grub.cfg)</p>
</li>
</ul>
</li>
</ul>
<h3>/opt</h3>
<ul>
<li>Optional directory for application software packages, usually installed manually by the user.</li>
</ul>
<h3>/tmp</h3>
<ul>
<li><strong>/tmp</strong> contains temporary files that are erased in a reboot.</li>
</ul>
<h3>/usr</h3>
<ul>
<li>
<p><strong>/usr</strong> contains multi-user applications, utilities and data. The common subdirectories are:</p>
<ul>
<li>
<p><strong>/usr/include</strong>: header files used to compile applications.</p>
</li>
<li>
<p><strong>usr/lib</strong>: libraries for programs in <strong>usr/(s)bin</strong>.</p>
</li>
<li>
<p><strong>usr/sbin</strong>: non-essential system binaries, such as system daemons. In modern Linux systems, this is actually linked together to <strong>/sbin</strong>.</p>
</li>
<li>
<p><strong>usr/bin</strong>: primary directory of executable commands of the system.</p>
</li>
<li>
<p><strong>usr/share</strong>: shaped data used by applications, generally architecture-independent.</p>
</li>
<li>
<p><strong>usr/src</strong>: source code, usually for the Linux kernel.</p>
</li>
<li>
<p><strong>usr/local</strong>: data and programs specific to the local machine, things that apply to computer rather than things provided by the operating system go.</p>
</li>
</ul>
</li>
</ul>
<h3>/proc</h3>
<ul>
<li><strong>/proc</strong> contains dynamically-created virtual filesystem that contains data about each running process and about the system as a whole.</li>
</ul>
<hr />
<h2>/dev Specials</h2>
<ul>
<li>
<p>There exist files provided by the operating system that do not represent any physical device, but provide a way to access special features:</p>
<ul>
<li>
<p><strong>/dev/null</strong> ignores everything written to it. It's convenient for discarding unwanted output.</p>
</li>
<li>
<p><strong>/dev/zero</strong> contains an <em>infinite</em> number of zero bytes, which can be useful for creating files of a specified length.</p>
</li>
<li>
<p><strong>/dev/urandom</strong> and <strong>/dev/random</strong> contain infinite stream of operating-system-generated random numbers, available to any application that wants to read them. The difference between them is that the second guarantees strong randomness (it will wait until enough is available) and so it should used for encryption, while the former can be used for games.</p>
</li>
</ul>
</li>
<li>
<p>For example, to output random bytes, you can type:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">cat</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">urandom</span> <span class="o">|</span> <span class="n">strings</span>
</pre></div>
<h2>The Kernel</h2>
<ul>
<li>
<p>The <strong>Linux Kernel</strong> is the program that manages <em>input/output requests</em> from software, and translates them into <em>data processing instructions</em> for the <em>central processing unit</em> (CPU).</p>
</li>
<li>
<p>To find the Kernel information you can type:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">cat</span> <span class="o">/</span><span class="n">proc</span><span class="o">/</span><span class="n">version</span>
<span class="n">Linux</span> <span class="n">version</span> <span class="mf">3.14.9</span><span class="o">-</span><span class="mf">200.f</span><span class="n">c20</span><span class="p">.</span><span class="n">x86_64</span> <span class="p">(</span><span class="n">mockbuild</span><span class="err">@</span><span class="n">bkernel02</span><span class="p">.</span><span class="n">phx2</span><span class="p">.</span><span class="n">fedoraproject</span><span class="p">.</span><span class="n">org</span><span class="p">)</span> <span class="p">(</span><span class="n">gcc</span> <span class="n">version</span> <span class="mf">4.8.3</span> <span class="mi">20140624</span> <span class="p">(</span><span class="n">Red</span> <span class="n">Hat</span> <span class="mf">4.8.3</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">(</span><span class="n">GCC</span><span class="p">)</span> <span class="p">)</span> <span class="err">#</span><span class="mi">1</span> <span class="n">SMP</span> <span class="n">Thu</span> <span class="n">Jun</span> <span class="mi">26</span> <span class="mi">21</span><span class="o">:</span><span class="mi">40</span><span class="o">:</span><span class="mi">51</span> <span class="n">UTC</span> <span class="mi">2014</span>
</pre></div>
<ul>
<li>You can also print similar system information with the specific command to print system information, <code>uname</code>. The flag <strong>-a</strong> stands for all:</li>
</ul>
<div class="highlight"><pre> <span class="err">$</span> <span class="n">uname</span> <span class="o">-</span><span class="n">a</span>
<span class="n">Linux</span> <span class="n">XXXXX</span> <span class="mf">3.14.9</span><span class="o">-</span><span class="mf">200.f</span><span class="n">c20</span><span class="p">.</span><span class="n">x86_64</span> <span class="err">#</span><span class="mi">1</span> <span class="n">SMP</span> <span class="n">Thu</span> <span class="n">Jun</span> <span class="mi">26</span> <span class="mi">21</span><span class="o">:</span><span class="mi">40</span><span class="o">:</span><span class="mi">51</span> <span class="n">UTC</span> <span class="mi">2014</span> <span class="n">x86_64</span> <span class="n">x86_64</span> <span class="n">x86_64</span> <span class="n">GNU</span><span class="o">/</span><span class="n">Linux</span>
</pre></div>
<ul>
<li>For instance, we might be interested on <strong>checking whether you are using the latest Kernel</strong>. You can do this by checking whether the outputs of the following commands match:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">rpm</span> <span class="o">-</span><span class="n">qa</span> <span class="n">kernel</span> <span class="o">|</span> <span class="n">sort</span> <span class="o">-</span><span class="n">V</span> <span class="o">|</span> <span class="n">tail</span> <span class="o">-</span><span class="n">n</span> <span class="mi">1</span>
<span class="err">$</span> <span class="n">uname</span> <span class="o">-</span><span class="n">r</span>
</pre></div>
<ul>
<li>Additionally, for Fedora (and RPM systems) you can check what kernels are installed with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">rpm</span> <span class="o">-</span><span class="n">q</span> <span class="n">kernel</span>
</pre></div>
<hr />
<h2>Processes</h2>
<ul>
<li>
<p>A running program is called <strong>process</strong>. Each process has a <strong>owner</strong> (in the same sense as when we talk about file permissions below).</p>
</li>
<li>
<p>You can find out which programs are running with the <strong>ps</strong> command. This also gives the <strong>process ID</strong> or <strong>PID</strong>, which is a unique long-term identity for the process (different copies of a given program will have separate PIDs).</p>
</li>
<li>
<p>To put a job (process) in the background we either run it with <strong>&</strong> or we press CTRL-Z and then type <strong>bg</strong>. To bring back to the foreground, we type <strong>fg</strong>.</p>
</li>
<li>
<p>To get the list of running jobs in the shell, we type <strong>jobs</strong>. Each job has a <strong>job ID</strong> which can be used with the percent sign <strong>%</strong> to <strong>bg</strong>, <strong>fg</strong> or <strong>kill</strong> (described below).</p>
</li>
</ul>
<h3>ps</h3>
<ul>
<li>To see the processes that were not started from your current session you can run:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="n">x</span>
</pre></div>
<ul>
<li>To see your processes and those belonging to other users:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="n">aux</span>
</pre></div>
<ul>
<li>To list all zombie processes you can either do:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="n">aux</span> <span class="o">|</span> <span class="n">grep</span> <span class="o">-</span><span class="n">w</span> <span class="n">Z</span>
</pre></div>
<p>or</p>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="o">-</span><span class="n">e</span>
</pre></div>
<h3>top</h3>
<ul>
<li>Another useful command is <strong>top</strong> (table of processes). It tells you which programs are using the most of memory or CPU:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">top</span>
</pre></div>
<ul>
<li>I particularly like <a href="http://hisham.hm/htop/">htop</a> over top, which needs to be installed if you want to use it.</li>
</ul>
<h3>kill</h3>
<ul>
<li>To stop running a command you can use <strong>kill</strong>. This will send a message called <strong>signal</strong> to the program. There are <a href="http://www.linux.org/threads/kill-commands-and-signals.4423/">64 different signals</a>, some having distinct meanings from <em>stop running</em>:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">kill</span> <span class="o"><</span><span class="n">SIGNAL</span> <span class="n">or</span> <span class="n">OPTION</span><span class="o">></span> <span class="o"><</span><span class="n">ID</span> <span class="n">or</span> <span class="n">PID</span><span class="o">></span>
</pre></div>
<ul>
<li>
<p>A user can kill all her process but not another user's process or processes the System is using (unless it's root).</p>
</li>
<li>
<p>The default signal sent by kill is <strong>SIGTERM</strong> (15), telling the program that you want it to quit. This is just a request, and the program can choose to ignore it. <strong>SIGHUP</strong> (1) is a less secure way of killing the process.</p>
</li>
<li>
<p>The signal <strong>SIGKILL</strong> is mandatory and cause the immediate end of the process. The only exception is if the program is in the middle of making a request to the operating system, <em>i.e.</em> a system call). This is because the request needs to finish first. This is the most <strong>unsafe</strong> way to kill the process (check <a href="https://stripe.com/blog/game-day-exercises-at-stripe">this post from Stripe's Game Day</a>). <strong>SIGKILL</strong> is the 9th signal in the list and it is usually sent with:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">kill</span> <span class="o">-</span><span class="mi">9</span> <span class="o"><</span><span class="n">ID</span> <span class="n">or</span> <span class="n">PID</span><span class="o">></span>
</pre></div>
<ul>
<li>To know all the process with their PID, run:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="o">-</span><span class="n">A</span>
</pre></div>
<ul>
<li>To find the PID of a specific process:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">pidof</span> <span class="n">subl</span>
</pre></div>
<p>or</p>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ps</span> <span class="n">aux</span> <span class="o">|</span> <span class="n">grep</span> <span class="n">subl</span>
</pre></div>
<p>or even</p>
<div class="highlight"><pre><span class="err">$</span> <span class="n">pgrep</span> <span class="n">subl</span>
</pre></div>
<ul>
<li>
<p>Pressing CTRL-C is a simpler way to tell the program to quit, and it sends a message called <strong>SIGINT</strong>. You can also specify the PID as an argument to kill.</p>
</li>
<li>
<p>Another way of killing process:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">pkill</span> <span class="o"><</span><span class="n">PROCESS</span> <span class="n">NAME</span><span class="o">></span>
</pre></div>
<h3>uptime</h3>
<ul>
<li>Another great command is <strong>uptime</strong>, which shows how long the system has been running, with a measure of its load average as well:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">uptime</span>
</pre></div>
<h3>nice and renice</h3>
<ul>
<li>Finally, you can change processes priority using <code>nice</code> (runs a program with modified scheduling priority) and <code>renice</code>(alter priority of running processes).</li>
</ul>
<hr />
<h2>Environment Variables</h2>
<ul>
<li><em>Environment variables</em> are several dynamic named values in the operating system that can be used in running processes.</li>
</ul>
<h3>set and env</h3>
<ul>
<li>You can see the <em>environment variables and configuration</em> in your system with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">set</span>
</pre></div>
<p>or</p>
<div class="highlight"><pre><span class="err">$</span> <span class="n">env</span>
</pre></div>
<h3>export and echo</h3>
<ul>
<li>The value of an environment variable can be changed with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">export</span> <span class="kd">VAR</span><span class="o">=<</span><span class="nb">value</span><span class="o">></span>
</pre></div>
<ul>
<li>The value can be checked with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">echo</span> <span class="err">$</span><span class="n">VAR</span>
</pre></div>
<ul>
<li>The <strong>PATH</strong> (search path) is the list of directories that the shell look in to try to find a particular command. For example, when you type <code>ls</code> it will look at <code>/bin/ls</code>. The path is stored in the variable <strong>PATH</strong>, which is a list of directory names separated by colons and it's coded inside <strong>./bashrc</strong>. To export a new path you can do:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">export</span> <span class="n">PATH</span><span class="o">=</span><span class="nv">$PATH</span><span class="p">:</span><span class="o">/<</span><span class="nx">DIRECTORY</span><span class="o">></span>
</pre></div>
<h3>Variable in Scripts</h3>
<ul>
<li>Inside a running shell script, there are pseudo-environment variables that are called with <strong>$1</strong>, <strong>$2</strong>, etc., for individual arguments that were passed to the script when it was run. In addition, <strong>$0</strong> is the name of the script and <strong>$@</strong> is for the list of all the command-line arguments.</li>
</ul>
<hr />
<h2>The "~/." Files (dot-files)</h2>
<ul>
<li>The leading dot in a file is used as an indicator to not list these files normally, but only when they are specifically requested. The reason is that, generally, dot-files are used to store configuration and sensitive information for applications.</li>
</ul>
<h3>~/.bashrc</h3>
<ul>
<li>
<p><strong>~/.bashrc</strong> contains scripts and variables that are executed when bash is invoked.</p>
</li>
<li>
<p>It's a good experience to customize your <strong>~/.bashrc</strong>. Just google for samples, or take a look at this <a href="http://dotfiles.org">site dedicated for sharing dot-files</a>, or at <a href="https://github.com/mariwahl/Dotfiles-and-Bash-Examples/blob/master/configs/bashrc">mine</a>. Don't forget to <code>source</code> your <strong>./bashrc</strong> file every time you make a change (opening a new terminal has the same effect):</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">source</span> <span class="o">~/</span><span class="p">.</span><span class="n">bashrc</span>
</pre></div>
<h3>Sensitive dot-files</h3>
<ul>
<li>
<p>If you use cryptographic programs such as <a href="http://en.wikipedia.org/wiki/Secure_Shell">ssh</a> and <a href="https://www.gnupg.org/">gpg</a>, you'll find that they keep a lot of information in the directories <strong>~/.ssh</strong> and <strong>~/.gnupg</strong>.</p>
</li>
<li>
<p>If you are a <em>Firefox</em> user, the <strong>~/.mozilla</strong> directory contains your web browsing history, bookmarks, cookies, and any saved passwords.</p>
</li>
<li>
<p>If you use <a href="http://pidgin.im/">Pidgin</a>, the <strong>~/.purple</strong> directory (after the name of <a href="https://developer.pidgin.im/wiki/WhatIsLibpurple">the IM library</a>) contains private information. This includes sensitive cryptographic keys for users of cryptographic extensions to Pidgin such as <a href="https://otr.cypherpunks.ca/">Off-the-Record</a>.</p>
</li>
</ul>
<hr />
<h2>File Descriptors</h2>
<ul>
<li>
<p>A <strong>file descriptor</strong> (FD) is a number indicator for accessing an I/O resource. The values are the following:</p>
<ul>
<li>fd 0: stdin (standard input).</li>
<li>fd 1: stdout (standard output).</li>
<li>fd 2: stderr (standard error).</li>
</ul>
</li>
<li>
<p>This naming is used for manipulation of these resources in the command line. For example, to send an <strong>input</strong> to a program you use <strong><</strong>:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="o"><</span><span class="nx">PROGRAM</span><span class="o">></span> <span class="o"><</span> <span class="o"><</span><span class="nb">INPUT</span><span class="o">></span>
</pre></div>
<ul>
<li>To send a program's <strong>output</strong> somewhere else than the terminal (such as a file), you use <strong>></strong>. For example, to just discard the output:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="o"><</span><span class="nx">PROGRAM</span><span class="o">></span> <span class="o">></span> <span class="p">/</span><span class="nx">dev</span><span class="p">/</span><span class="nb">null</span>
</pre></div>
<ul>
<li>To send the program's error messages to a file you use the file descriptor 2:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="o"><</span><span class="nx">PROGRAM</span><span class="o">></span> <span class="mi">2</span><span class="o">></span> <span class="o"><</span><span class="nb">FILE</span><span class="o">></span>
</pre></div>
<ul>
<li>To send the program's error messages to the same place where <strong>stdout</strong> is going, <em>i.e.</em> merging it into a single stream (this works greatly for pipelines):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="o"><</span><span class="nx">PROGRAM</span><span class="o">></span> <span class="mi">2</span><span class="o">>&</span><span class="mi">1</span>
</pre></div>
<hr />
<h2>File Permissions</h2>
<ul>
<li>Every file/directory in Linux is said to belong to a particular <strong>owner</strong> and a particular <strong>group</strong>. Files also have permissions stating what operations are allowed.</li>
</ul>
<h3>chmod</h3>
<ul>
<li>
<p>A resource can have three permissions: read, write, and execute:</p>
<ul>
<li>
<p>For a file resource, these permission are: read the file, to modify the file, and to run the file as a program.</p>
</li>
<li>
<p>For a directory, these permissions are: the ability to list the directory's contents, to create and delete files inside the directory, and to access files within the directory.</p>
</li>
</ul>
</li>
<li>
<p>To change the permissions you use the command <code>chmod</code>.</p>
</li>
</ul>
<h3>chown and chgrp</h3>
<ul>
<li>
<p>Unix permissions model does not support <em>access control lists</em> allowing a file to be shared with an enumerated list of users for a particular purpose. Instead, the admin needs to put all the users in a group and make the file to belong to that group. File owners cannot share files with an arbitrary list of users.</p>
</li>
<li>
<p>There are three agents relate to the resource: user, group, and all. Each of them can have separated permissions to read, write, and execute.</p>
</li>
<li>
<p>To change the owner of a resource you use <code>chown</code>. There are two ways of setting permissions with chmod:</p>
<ul>
<li>
<p>A numeric form using octal modes: read = 4, write = 2, execute = 1, where you multiply by user = x100, group = x10, all = x1, and sum the values corresponding to the granted permissions. For example 755 = 700 + 50 + 5 = rwxr-xr-x: <code>$ chmod 774 <FILENAME></code></p>
</li>
<li>
<p>An abbreviated letter-based form using symbolic modes: u, g, or a, followed by a plus or minus, followed by a letter r, w, or x. This means that u+x "grants user execute permission", g-w "denies group write permission", and a+r "grants all read permission":<code>$ chmod g-w <FILENAME></code>.</p>
</li>
</ul>
</li>
<li>
<p>To change the group you use <code>chgrp</code>, using the same logic as for chmod.</p>
</li>
<li>
<p>To see the file permissions in the current folder, type:</p>
</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ls</span> <span class="o">-</span><span class="n">l</span>
</pre></div>
<ul>
<li>For example, <code>-rw-r--r--</code> means that it is a file (-) where the owner has read (r) and write (w) permissions, but not execute permission (-).</li>
</ul>
<hr />
<h1>Shell Commands and Tricks</h1>
<h2>Reading Files</h2>
<h3>cat</h3>
<ul>
<li>Prints the content of a file in the terminal:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">cat</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>tac</h3>
<ul>
<li>Prints the inverse of the content of a file in the terminal (starting from the bottom):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">tac</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>less and more</h3>
<ul>
<li>Both print the content of a file, but adding page control:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">less</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
<span class="err">$</span> <span class="nx">more</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>head and tail</h3>
<ul>
<li>To read 20 lines from the begin:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">head</span> <span class="o">-</span><span class="mi">20</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>To read 20 lines from the bottom:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">tail</span> <span class="o">-</span><span class="mi">10</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>nl</h3>
<ul>
<li>To print (cat) a file with line numbers:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">nl</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>tee</h3>
<ul>
<li>To save the output of a program and see it as well:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="o"><</span><span class="nx">PROGRAM</span><span class="o">></span> <span class="o">|</span> <span class="nx">tee</span> <span class="na">-a</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>wc</h3>
<ul>
<li>To print the length and number of lines of a file:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">wc</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<hr />
<h2>Searching inside Files</h2>
<h3>diff and diff3</h3>
<ul>
<li>
<p><strong>diff</strong> can be used to compare files and directories. Useful flags include: <strong>-c</strong> to list differences, <strong>-r</strong> to recursively compare subdirectories, <strong>-i</strong> to ignore case, and <strong>-w</strong> to ignore spaces and tabs.</p>
</li>
<li>
<p>You can compare three files at once using <strong>diff3</strong>, which uses one file as the reference basis for the other two.</p>
</li>
</ul>
<h3>file</h3>
<ul>
<li>The command <strong>file</strong> shows the real nature of a file:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">file</span> <span class="n">requirements</span><span class="p">.</span><span class="n">txt</span>
<span class="n">requirements</span><span class="p">.</span><span class="n">txt</span><span class="o">:</span> <span class="n">ASCII</span> <span class="n">text</span>
</pre></div>
<h3>grep</h3>
<ul>
<li><strong>grep</strong> finds matches for a particular search pattern. The flag <strong>-l</strong> lists the files that contain matches, the flag <strong>-i</strong> makes the search case insensitive, and the flag <strong>-r</strong> searches all the files in a directory and subdirectory:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">grep</span> <span class="na">-lir</span> <span class="o"><</span><span class="nx">PATTERN</span><span class="o">></span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>For example, to remove lines that are not equal to a word:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">grep</span> <span class="na">-xv</span> <span class="o"><</span><span class="nx">WORD</span><span class="o">></span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<hr />
<h2>Listing or Searching for Files</h2>
<h3>ls</h3>
<ul>
<li><strong>ls</strong> lists directory and files. Useful flags are <strong>-l</strong> to list the permissions of each file in the directory and <strong>-a</strong> to include the dot-files:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ls</span> <span class="o">-</span><span class="n">la</span>
</pre></div>
<ul>
<li>To list files sorted by size:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ls</span> <span class="o">-</span><span class="n">lrS</span>
</pre></div>
<ul>
<li>To list the names of the 10 most recently modified files ending with .txt:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ls</span> <span class="o">-</span><span class="n">rt</span> <span class="o">*</span><span class="p">.</span><span class="n">txt</span> <span class="o">|</span> <span class="n">tail</span> <span class="o">-</span><span class="mi">10</span>
</pre></div>
<h3>tree</h3>
<ul>
<li>The <strong>tree</strong> command lists contents of directories in a tree-like format.</li>
</ul>
<h3>find</h3>
<ul>
<li>To find files in a directory:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">find</span> <span class="o"><</span><span class="nx">DIRECTORY</span><span class="o">></span> <span class="na">-name</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>which</h3>
<ul>
<li>To find binaries in PATH variables:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">which</span> <span class="n">ls</span>
</pre></div>
<h3>whereis</h3>
<ul>
<li>To find any file in any directory:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">whereis</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>locate</h3>
<ul>
<li>To find files by name (using database):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">locate</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>To test if a a file exist:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">test</span> <span class="na">-f</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<hr />
<h2>Modifying Files</h2>
<h3>true</h3>
<ul>
<li>To make a file empty:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="kc">true</span> <span class="o">></span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>tr</h3>
<ul>
<li><strong>tr</strong> takes a pair of strings as arguments and replaces, in its input, every letter that occurs in the first string by the corresponding characters in the second string. For example, to make everything lowercase:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">tr</span> <span class="n">A</span><span class="o">-</span><span class="n">Z</span> <span class="n">a</span><span class="o">-</span><span class="n">z</span>
</pre></div>
<ul>
<li>To put every word in a line by replacing spaces with newlines:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">tr</span> <span class="o">-</span><span class="n">s</span> <span class="sc">' '</span> <span class="sc">'\n'</span>
</pre></div>
<ul>
<li>To combine multiple lines into a single line:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">tr</span> <span class="o">-</span><span class="n">d</span> <span class="sc">'\n'</span>
</pre></div>
<ul>
<li><strong>tr</strong> doesn't accept the names of files to act upon, so we can pipe it with cat to take input file arguments (same effect as <code>$ <PROGRAM> < <FILENAME></code>):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">cat</span> <span class="s">"$@"</span> <span class="o">|</span> <span class="n">tr</span>
</pre></div>
<h3>sort</h3>
<ul>
<li>Sort the contents of text files. The flag <strong>-r</strong> sort backwards, and the flag <strong>-n</strong> selects numeric sort order (for example, without it, 2 comes after 1000):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">sort</span> <span class="na">-rn</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>To output a frequency count (histogram):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">sort</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span> <span class="o">|</span> <span class="nx">uniq</span> <span class="na">-c</span> <span class="o">|</span> <span class="nb">sort</span> <span class="na">-rn</span>
</pre></div>
<ul>
<li>To chose random lines from a file:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">sort</span> <span class="na">-R</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span> <span class="o">|</span> <span class="nb">head</span> <span class="o">-</span><span class="mi">10</span>
</pre></div>
<ul>
<li>To combine multiple files into one sorted file:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nb">sort</span> <span class="na">-m</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>uniq</h3>
<ul>
<li><strong>uniq</strong> remove <em>adjacent</em> duplicate lines. The flag <strong>-c</strong> can include a count:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">uniq</span> <span class="na">-c</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>To output only duplicate lines:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">uniq</span> <span class="na">-d</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>cut</h3>
<ul>
<li><strong>cut</strong> selects particular fields (columns) from a structured text files (or particular characters from each line of any text file). The flag <strong>-d</strong> specifies what delimiter should be used to divide columns (default is tab), the flag <strong>-f</strong> specifies which field or fields to print and in what order:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">cut</span> <span class="na">-d</span> <span class="s1">' '</span> <span class="na">-f</span> <span class="mi">2</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<ul>
<li>The flag <strong>-c</strong> specifies a range of characters to output, so <strong>-c1-2</strong> means to output only the first two characters of each line:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">cut</span> <span class="na">-c1</span><span class="o">-</span><span class="mi">2</span> <span class="o"><</span><span class="nb">FILENAME</span><span class="o">></span>
</pre></div>
<h3>join</h3>
<ul>
<li><strong>join</strong> combines multiple file by common delimited fields:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="k">join</span> <span class="o"><</span><span class="nx">FILENAME1</span><span class="o">></span> <span class="o"><</span><span class="nx">FILENAME2</span><span class="o">></span>
</pre></div>
<hr />
<h2>Creating Files and Directories</h2>
<h3>mkdir</h3>
<ul>
<li><strong>mkdir</strong> creates a directory. An useful flag is <strong>-p</strong> which creates the entire path of directories (in case they don't exist):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">mkdir</span> <span class="na">-p</span> <span class="o"><</span><span class="nx">DIRNAME</span><span class="o">></span>
</pre></div>
<h3>cp</h3>
<ul>
<li>Copying directory trees is done with <strong>cp</strong>. The flag <strong>-a</strong> is used to preserve all metadata:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">cp</span> <span class="na">-a</span> <span class="o"><</span><span class="nx">ORIGIN</span><span class="o">></span> <span class="o"><</span><span class="nx">DEST</span><span class="o">></span>
</pre></div>
<ul>
<li>Interestingly, commands enclosed in <strong>$()</strong> can be run and then the output of the commands is substituted for the clause and can be used as a part of another command line:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">cp</span> <span class="err">$</span><span class="p">(</span><span class="nx">ls</span> <span class="na">-rt</span> <span class="o">*</span><span class="bp">.</span><span class="nx">txt</span> <span class="o">|</span> <span class="nx">tail</span> <span class="o">-</span><span class="mi">10</span><span class="p">)</span> <span class="o"><</span><span class="nx">DEST</span><span class="o">></span>
</pre></div>
<h3>pushd and popd</h3>
<ul>
<li>The <strong>pushd</strong> command saves the current working directory in memory so it can be returned to at any time, optionally changing to a new directory:</li>
</ul>
<div class="highlight"><pre> <span class="err">$</span> <span class="n">pushd</span> <span class="o">~/</span><span class="n">Desktop</span><span class="o">/</span>
</pre></div>
<ul>
<li>The <strong>popd</strong> command returns to the path at the top of the directory stack.</li>
</ul>
<h3>ln</h3>
<ul>
<li>Files can be linked with different names with the <strong>ln</strong>. To create a symbolic (soft) link you can use the flag <strong>-s</strong>:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="nx">ln</span> <span class="na">-s</span> <span class="o"><</span><span class="nb">TARGET</span><span class="o">></span> <span class="o"><</span><span class="nx">LINKNAME</span><span class="o">></span>
</pre></div>
<h3>dd</h3>
<ul>
<li><strong>dd</strong> is used for disk-to-disk copies, being useful for making copies of raw disk space. For example, to back up your <a href="http://en.wikipedia.org/wiki/Master_boot_record">Master Boot Record</a> (MBR):</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">dd</span> <span class="k">if</span><span class="o">=/</span><span class="n">dev</span><span class="o">/</span><span class="n">sda</span> <span class="n">of</span><span class="o">=</span><span class="n">sda</span><span class="p">.</span><span class="n">mbr</span> <span class="n">bs</span><span class="o">=</span><span class="mi">512</span> <span class="n">count</span><span class="o">=</span><span class="mi">1</span>
</pre></div>
<ul>
<li>To use <strong>dd</strong> to make a copy of one disk onto another:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">dd</span> <span class="k">if</span><span class="o">=/</span><span class="n">dev</span><span class="o">/</span><span class="n">sda</span> <span class="n">of</span><span class="o">=/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb</span>
</pre></div>
<hr />
<h2>Network and Admin</h2>
<h3>du</h3>
<ul>
<li><strong>du</strong> shows how much disk space is used for each file:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">du</span> <span class="o">-</span><span class="n">sha</span>
</pre></div>
<ul>
<li>To see this information sorted and only the 10 largest files:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">du</span> <span class="o">-</span><span class="n">a</span> <span class="o">|</span> <span class="n">sort</span> <span class="o">-</span><span class="n">rn</span> <span class="o">|</span> <span class="n">head</span> <span class="o">-</span><span class="mi">10</span>
</pre></div>
<ul>
<li>To determine which subdirectories are taking a lot of disk space:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">du</span> <span class="o">--</span><span class="n">max</span><span class="o">-</span><span class="n">depth</span><span class="o">=</span><span class="mi">1</span> <span class="o">|</span> <span class="n">sort</span> <span class="o">-</span><span class="n">k1</span> <span class="o">-</span><span class="n">rn</span>
</pre></div>
<h3>df</h3>
<ul>
<li><strong>df</strong> shows how much disk space is used on each mounted filesystem. It displays five columns for each filesystem: the name, the size, how much is used, how much is available, percentage of use, and where it is mounted. Note the values won't add up because Unix filesystems have <strong>reserved</strong> storage blogs which only the root user can write to.</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">df</span> <span class="o">-</span><span class="n">h</span>
</pre></div>
<h3>ifconfig</h3>
<ul>
<li>You can check and configure your network interface with:</li>
</ul>
<div class="highlight"><pre><span class="err">$</span> <span class="n">ifconfig</span>
</pre></div>
<ul>
<li>
<p>In general, you will see the following devices when you issue <strong>ifconfig</strong>:</p>