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
|
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="https://static.luevano.xyz/scripts/theme.js"></script>
<link id="code-theme-css" rel="stylesheet" type="text/css" href="https://static.luevano.xyz/hl/styles/solarized-dark.min.css">
<script type="text/javascript" src="https://static.luevano.xyz/hl/highlight.min.js"></script>
<script type="text/javascript">hljs.initHighlightingOnLoad();</script>
<link rel="stylesheet" type="text/css" href="https://static.luevano.xyz/fa/css/all.min.css">
<link id="theme-css" rel="stylesheet" type="text/css" href="https://static.luevano.xyz/css/dark.css">
<link rel="stylesheet" type="text/css" href="https://static.luevano.xyz/css/general_style.css">
<link rel="icon" href="https://static.luevano.xyz/fa/svgs/solid/dragon.svg">
<meta charset="utf-8">
<title>Luévano's Blog</title>
</head>
<body>
<div id="theme-switcher-container">
<i class="fas fa-sun"></i>
<label class="switch theme">
<input id="theme-switch" type="checkbox" onclick="toggleTheme()">
<span class="slider round"></span>
</label>
<i class="fas fa-moon"></i>
</div>
<header>
<ul class="menubar">
<li>
<a href="https://luevano.xyz/"><i class="fas fa-home" alt="Home"></i><span>Home</span></a>
</li>
<li>
<a href="https://blog.luevano.xyz/"><i class="fas fa-book-open" alt="Blog"></i><span>Blog</span></a>
</li>
<li><i class="fab fa-git" alt="Git"></i><span>Git</span>
<ul>
<li><a href="https://git.luevano.xyz/" target="_blank"><i class="fab fa-git-alt" alt="Git-alt"></i></a></li>
<li><a href="https://github.com/luevano" target="_blank"><i class="fab fa-github" alt="Github"></i></a></li>
<li><a href="https://gitlab.com/dluevano" target="_blank"><i class="fab fa-gitlab" alt="Gitlab"></i></a></li>
</ul>
</li>
<li><i class="fas fa-box-open" alt="Stuff"></i><span>Stuff</span>
<ul>
<li><a href="https://gb.luevano.xyz/"><i class="fas fa-gamepad" alt="Gameboy"></i><span>Gameboy</span></a></li>
</ul>
</li>
<li>
<a href="https://luevano.xyz/donate"><i class="fas fa-donate" alt="Donate"></i><span>Donate</span></a>
<ul>
<li><a href="https://paypal.me/dlvna"><i class="fab fa-paypal" alt="Paypal"></i><span>Paypal</span></a></li>
</ul>
</li>
</ul>
</nav>
</header>
<h1>Linux tutorial video notes</h1>
<p>I was requested to make a summary of a video about basic Linux stuff (like the <a href="https://blog.luevano.xyz/a/sql_video_notes">SQL tutorial video notes</a>); this time, I did most of the notes depending on the topic since I'm familiar with most of the stuff presented in the video. The video in question is: <a href="https://www.youtube.com/watch?v=wBp0Rb-ZJak">The Complete Linux Course: Beginner to Power User!</a>. Also, some notes were taken from <a href="https://wiki.archlinux.org/">Arch Linux Wiki</a> since it's got pretty decent documentation, and, of course, general googling.</p>
<h2>(Basic) commands</h2>
<p>A list of basic commands and small explanation (note that options are started with either <code>-</code> or <code>--</code>, depending on the program, but most of the time <code>-</code> is used for letter options and <code>--</code> for word options, <code>-l</code> vs <code>--list</code> for example):</p>
<ul>
<li><code>pwd</code>: “print working directory”, full <strong>absolute</strong> path to the current directory.</li>
<li><code>cd</code>: “change directory”, followed by the absolute or relative path of the directory to change to.
<ul>
<li>Absolute path is started with <code>/</code>, while a relative path is started with <code>./</code> or just the name of the folder.</li>
<li>Use <code>..</code> (two dots) to go up one directory.</li>
<li>An abbreviation of <code>/home/username</code> is <code>~</code> (tilde).</li>
</ul></li>
<li><code>ls</code>: “list” files and directories in current directory, or specify a directory from which to show the list after typing <code>ls</code>. Has many options, the most common ones being:
<ul>
<li><code>l</code>: use long listing format.</li>
<li><code>r</code> or <code>reverse</code>: reverse order while sorting.</li>
<li><code>s</code>: sort by file size, largest first.</li>
<li><code>a</code> or <code>all</code>: do not ignore entries starting with <code>.</code>.</li>
</ul></li>
<li><code>mkdir</code>: “make directory”, create a new directory with specified name.</li>
<li><code>touch</code>: create new (empty) files.</li>
<li><code>cp</code>: “copy” files or directories (using option <code>r</code> for recursive). Requires file/directory to copy and destination, separated by space.</li>
<li><code>mv</code>: “move” files or directories, also requires file/directory to copy and destination, separated by space. This is also used to <strong>rename</strong> files/directories.</li>
<li><code>rm</code>: “remove”, followed by a file to remove it.</li>
<li><code>rmdir</code>: “remove empty directory”, followed by a directory to remove it. If the directory is not empty, use <code>rm -r</code> on the directory (“remove recursive”).</li>
<li><code>su</code>: “switch user”, by default to <strong>root</strong> user, but another one can be specified.</li>
<li><code>sudo</code>: “switch user, do”, similar to <code>su</code>, but only to execute a command as <strong>root</strong> or the specified user.</li>
<li><code>clear</code>: clear the terminal window, a (common) keyboard shortcut is <code>Ctrl + l</code>.</li>
<li><code>find</code>: search for files/directories matching a pattern or all contents of a directory (using <code>.</code>).</li>
<li><code>grep</code>: comes from the <code>ed</code> command “g/re/p”, for searching plain-text for lines that match a regular expression (regex).</li>
<li><code>top</code>: a task manager program, shows currently running commands and gives important info such as PID (process ID), user who is running that command, command name, cpu and ram usage, etc.. Some useful commands to manage programs running are:
<ul>
<li><code>pgrep</code>: get the PID of a running process, or a list in chronological order.</li>
<li><code>kill</code> or <code>pkill</code>: kill a running process either by PID or by name.</li>
<li><code>killall</code>: similar to <code>pkill</code>.</li>
</ul></li>
<li><code>ssh</code>: “secure shell” is a remote login client used to connect into a remote machine and executing commands remotely, basically taking control of the remote machine. Widely used when managing servers.</li>
<li><code>ftp</code> or <code>sftp</code>: “(secure) file transfer protocol” used to transfer files from one machine to another one (usually a server). It's recommended to use <code>sftp</code> instead of <code>ftp</code> because anyone can look through the packages if it's not secured (encrypted).</li>
</ul>
<p>And in general, to see the options supported by almost any command, use <code>command -h</code> or <code>command --help</code>, for a quick explanation. <strong>IMPORTANT</strong>: Most programs have <strong>man (manual) pages</strong>; to access them do <code>man command</code>, this is a very powerful tool to use.</p>
<p>Commands can be redirected to other commands (the output), which is powerful to create mini scripts or to achieve a goal in a single command. Most of the time the redirection can be done with the special characters <code>></code>, <code><</code> and most powerful, the <code>|</code> (pipe). Also, some commands accept an option to execute another command, but this depends on a command to command basis (<code>exec</code> option for <code>find</code>, for example).</p>
<p><strong>Most terminal programs accept <code>Ctrl-c</code> or just <code>q</code> to exit the program.</strong></p>
<h2>File permissions and ownership</h2>
<p>When listing files with <code>ls -l</code>, an output with file attributes (permissions) and ownership is shown, such as <code>drwxr-xr-x 2 user group 4096 Jul 5 21:03 Desktop</code>, where the first part are the attributes, and <code>user</code> and <code>group</code> the ownership info (all other info is irrelevant for now).</p>
<p>File attributes (<code>drwxr-xr-x</code> in the example above) are specified by 10 (sometimes 11) characters, and can be break into 4 parts (or 5):</p>
<ul>
<li>The first character is just the file type, typically <code>d</code> for directories or just <code>-</code> for files. There is <code>l</code> too, which is for <strong>symlinks</strong>.</li>
<li>The next 3 characters represent the permissions that the <strong>owner</strong> has over the file.</li>
<li>Next 3 the permissions that the <strong>group</strong> has over the file.</li>
<li>Next 3 the permissions everyone else (<strong>others</strong>) have over the file.</li>
<li>An optional <code>+</code> character that specifies whether an alternate access method applies to the file. When the character is a space, there is no alterante access method.</li>
</ul>
<p>Each of the three permission triads (<code>rwx</code>) can be:</p>
<ul>
<li><code>-</code> or <code>r</code>, for the first character, if the file can be <strong>read</strong> or directory's content can be shown.</li>
<li><code>-</code> or <code>w</code>, for the second character, if the file can be <strong>modified</strong> or the directory's content can be modified (create new files or folders or rename existing files or folders).</li>
<li><code>-</code> or <code>x</code>, for the third character, if the file can be <strong>executed</strong> or the directory can be <strong>accessed</strong> with <code>cd</code>. Other characters can be present, like <code>s</code>, <code>S</code>, <code>t</code> and <code>T</code> (for more: <a href="https://wiki.archlinux.org/index.php/File_permissions_and_attributes">Arch Linux Wiki: File permissions and attributes</a>).</li>
</ul>
<p>To change attributes or ownership use <code>chmod</code> and <code>chown</code>, respectively.</p>
<h2>Services</h2>
<p>Special type of linux process (think of a program or set of programs that run in the background waiting to be used, or doing essential tasks). There are many ways to manage (start, stop, restart, enable, disable, etc.) services, the most common way (if using <code>systemd</code>) is to just use <code>systemctl</code>. Basic usage of <code>systemctl</code> is <code>systemctl verb service</code>, where <code>verb</code> could be <code>start</code>, <code>enable</code>, <code>stop</code>, <code>disable</code>, <code>restart</code>, etc. Also, to get a general system status run <code>systemctl status</code> or just <code>systemctl</code> for a list of running <strong>units</strong> (a unit is an instance of a service, or a mount point or even a device or a socket). For more: <a href="https://wiki.archlinux.org/index.php/systemd">Arch Linux Wiki: systemd</a>.</p>
<p><code>systemd</code> also provides a way to do tasks based on a <strong>timer</strong>, where you can schedule from the second to the year. One could also use <code>cron</code> (using <code>crontab</code> with option <code>e</code>) to do this. These timers provide support for calendar time events, monotonic time events, and can be run asynchronously.</p>
<h2>User and group management</h2>
<p>Most mainstream linux distributions come with a Graphic User Interface (GUI) to manage users and groups on the system. For a Command-Line Interface (CLI) just use <code>useradd</code> (with <code>passwd</code> to create a password for a given user) and <code>groupadd</code>. Also, other useful commands are <code>usermod</code>, <code>userdel</code>, <code>groups</code>, <code>gpasswd</code>, <code>groupdel</code> and more, each used for a basic management of users/groups like modification, deletion, listing (of all existing users/groups), etc.. For more: <a href="https://wiki.archlinux.org/index.php/users_and_groups">Arch Linux Wiki: Users and groups</a>.</p>
<h2>Networking</h2>
<h3>Hosts file</h3>
<p>Located at <code>/etc/hosts</code>, serves as a translator from <strong>hostname</strong> (web addresses or URLs) into IP addresses (think of DNS records), meaning that any URL can be overridden to make it point to whatever IP address it's specified (only locally on the machine affected). The syntax of the file is pretty simple: first column for IP, second for hostname (URL) and third+ for aliases.</p>
<h3>(Some) commands</h3>
<p>These commands serve the sole purpose of showing information about the network and stuff related to it:</p>
<ul>
<li><code>ping</code>: gives information about latency to a given ip/domain.</li>
<li><code>ifconfig</code>: gives similar information to <code>ipconfig</code> on windows, general info of physical network devices with their addresses and properties. An alternative could be <code>ip addr</code>, depending on the linux distribution being used and programs installed.</li>
<li><code>tcpdump</code>: “transmission control protocol dump” gives information on all “packets” being sent and received through the network.</li>
<li><code>netstat</code>: “network statistics” general statistics about network devices usage, display connections to the machine and more.</li>
<li><code>traceroute</code>: shows the route that the packets go through (how the packets jump from one server to another one) when trying to access an IP (or, for example, a website).</li>
<li><code>nmap</code>: “network mapper” explore network available hosts, opened ports, reverse DNS names, can guess the operating system of the device, it's type, MAC address and more.</li>
</ul>
<div class=timestamp>
<hr>
<p>Created: Sat, Mar 13, 2021 @ 22:57 MST</p>
</div>
<footer class="footer">
<i class="fas fa-envelope" alt="Email"></i>
Email
<a href="mailto:david@luevano.xyz">
david@luevano.xyz
</a>
<br>
<i class="fas fa-rss" alt="RSS"></i>
RSS
<a href="https://blog.luevano.xyz/rss.xml">
https://blog.luevano.xyz/rss.xml
</a>
<br>
<i class="fas fa-donate" alt="Donate"></i>
<a href="https://luevano.xyz/donate">Donate</a>
<a href="https://paypal.me/dlvna"><i class="fab fa-paypal" alt="Paypal"></i></a>
</footer>
</body>
</html>
|