Project

General

Profile

Linux Beginner Guide » History » Version 5

Marc Auer, 01/23/2019 09:42 AM

1 1 Marc Auer
h1. Linux Beginner Guide
2 2 Marc Auer
3 1 Marc Auer
h2. Basic Commands
4 5 Marc Auer
- *reboot*
5
6
$ reboot
7
Startet den Computer neu
8
9
10
- *poweroff*
11
$ poweroff
12
13
Faehrt den Computer herunter
14
15
- *clear & exit* - 
16
$ clear
17
18
$ exit
19
Terminal leeren (clear) & Terminal schliesen (exit) 
20 2 Marc Auer
21 1 Marc Auer
- *ps aux*
22
$ ps - snapshot of of the current processes.
23
24
a = show processes for all users
25
u = display the process's user/owner
26
x = also show processes not attached to a terminal
27
28
- *ip addr*
29
30
$ ip addr | grep inet
31
32
- *sudo*
33
This SuperUserDo is the most important command Linux newbies will use. Every single command that needs root's permission, need this sudo command. You can use sudo before each command that requires root permissions -
34
35
$ sudo su
36
37
- *ls* (list)
38
The terminal will show you all the files and folders of the directory that you're working in. Let's say I'm in the /home folder and I want to see the directories & files in /home.
39
40
/home$ ls
41
42
- *cd*
43
​Changing directory (cd) is the main command that always be in use in terminal. It's one of the most Linux basic commands. Using this is easy. Just type the name of the folder you want to go in from your current directory. If you want to go up just do it by giving double dots (..) as the parameter.
44
45
/home $ cd usr
46
47
/home/usr $
48
49
- *mkdir*
50
Sometimes you want to create a new folder or subfolder. You can use mkdir command to do that. Just give your folder name after mkdir command in your terminal.
51
52
~$ mkdir folderName
53
54
- *cp*
55
copy-and-paste 
56
57
$ cp source destination
58
Note: If you're copying files into the directory that requires root permission for any new file, then you'll need to use sudo command.
59
60
- *rm*
61
rm is a command to remove your file or even your directory. You can use -f if the file need root permission to be removed. And also you can use -r to do recursive removal to remove your folder.
62
$ rm myfile.txt
63
64
- *apt-get* in Ubuntu | *pacman* in Arch
65
This command differs distro-by-distro. In Debian based Linux distributions, to install, remove and upgrade any package we've Advanced Packaging Tool (APT) package manager. 
66
67
​In other distributions, such as Arch, Centos there are different package managers.
68
 
69
$ sudo apt-get update | apt-get upgrade -y
70
71
$ sudo pacman -Syu
72
73
- *grep*
74
You need to find a file but you don't remember its exact location or the path. grep will help you to solve this problem. You can use the grep command to help finding the file based on given keywords.
75
76
$ grep user /etc/passwd
77
78
- *cat*
79
As a user, you often need to view some of text or code from your script. Again, one of the Linux basic commands is cat command. It will show you the text inside your file.
80
81
$ cat CMakeLists.txt
82
83
- *poweroff*
84
And the last one is poweroff. Sometimes you need to poweroff directly from your terminal. This command will do the task. Don't forget to add sudo at the beginning of the command since it needs root permission to execute poweroff.
85
$ sudo poweroff
86
87
h2. Basic Linux Directories
88 3 Marc Auer
89 1 Marc Auer
** / – The Root Directory 
90
Everything on your Linux system is located under the / directory, known as the root directory.
91
You can think of the / directory as being similar to the C:\ directory on Windows – but this isn’t strictly true, as Linux doesn’t have drive letters. 
92
While another partition would be located at D:\ on Windows, this other partition would appear in another folder under / on Linux.
93
94
** /bin – Essential User Binaries
95
The /bin directory contains the essential user binaries (programs) that must be present when the system is mounted in single-user mode. 
96
Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. 
97
The /usr directory may be stored on another partition – placing these files in the /bin directory ensures the system will have these important 
98
utilities even if no other file systems are mounted. The /sbin directory is similar – it contains essential system administration binaries.
99
100
** /boot – Static Boot Files
101
The /boot directory contains the files needed to boot the system – for example, the GRUB boot loader’s files and your Linux kernels are stored here. 
102
The boot loader’s configuration files aren’t located here, though – they’re in /etc with the other configuration files.
103
104
** /cdrom – Historical Mount Point for CD-ROMs
105
The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. 
106
It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.
107
108
** /dev – Device Files
109
Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. 
110
These are not actual files as we know them, but they appear as files – for example, /dev/sda represents the first SATA drive in the system. 
111
If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.
112
113
This directory also contains pseudo-devices, which are virtual devices that don’t actually correspond to hardware. 
114
For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input – 
115
when you pipe the output of a command to /dev/null, you discard it.
116
117
** /etc – Configuration Files
118
The /etc directory contains configuration files, which can generally be edited by hand in a text editor. 
119
Note that the /etc/ directory contains system-wide configuration files – user-specific configuration files are located in each user’s home directory.
120
121
** /home – Home Folders
122
The /home directory contains a home folder for each user. 
123
For example, if your user name is bob, you have a home folder located at /home/bob. This home folder contains the user’s data files and user-specific configuration files. 
124
Each user only has write access to their own home folder and must obtain elevated permissions (become the root user) to modify other files on the system.
125
126
** /lib – Essential Shared Libraries
127
The /lib directory contains libraries needed by the essential binaries in the /bin and /sbin folder. 
128
Libraries needed by the binaries in the /usr/bin folder are located in /usr/lib.
129
130
** /lost+found – Recovered Files
131
Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. 
132
Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.
133
134
** /media – Removable Media
135
The /media directory contains subdirectories where removable media devices inserted into the computer are mounted. 
136
For example, when you insert a CD into your Linux system, a directory will automatically be created inside the /media directory. 
137
You can access the contents of the CD inside this directory.
138
139
** /mnt – Temporary Mount Points
140
Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. 
141
For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. 
142
However, you can mount other file systems anywhere on the system.
143
144
** /opt – Optional Packages
145
The /opt directory contains subdirectories for optional software packages. 
146
It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy – 
147
for example, a proprietary program might dump its files in /opt/application when you install it.
148
149
** /proc – Kernel & Process Files
150
The /proc directory similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.
151
152
** /root – Root Home Directory
153
The /root directory is the home directory of the root user. Instead of being located at /home/root, it’s located at /root. 
154
This is distinct from /, which is the system root directory.
155
156
** /run – Application State Files
157
The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. 
158
These files can’t be stored in /tmp because files in /tmp may be deleted.
159
160
** /sbin – System Administration Binaries
161
The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.
162
163
** /selinux – SELinux Virtual File System
164
If your Linux distribution uses SELinux for security (Fedora and Red Hat, for example), the /selinux directory contains special files used by SELinux. 
165
It’s similar to /proc. Ubuntu doesn’t use SELinux, so the presence of this folder on Ubuntu appears to be a bug.
166
167
** /srv – Service Data
168
The /srv directory contains “data for services provided by the system.” 
169
If you were using the Apache HTTP server to serve a website, you’d likely store your website’s files in a directory inside the /srv directory.
170
171
** /tmp – Temporary Files
172
Applications store temporary files in the /tmp directory. 
173
These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch.
174
175
** /usr – User Binaries & Read-Only Data
176
The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. 
177 4 Marc Auer
For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. 
178 1 Marc Auer
The /usr directory also contains other directories – for example, architecture-independent files like graphics are located in /usr/share.
179
180
The /usr/local directory is where locally compiled applications install to by default – this prevents them from mucking up the rest of the system.
181
182
** /var – Variable Data Files
183
The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. 
184
Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. 
185
For example, you’ll find log files in /var/log.
186
187
h2. beginner tutorials
188 4 Marc Auer
189 1 Marc Auer
h3. Ping
190 4 Marc Auer
191 1 Marc Auer
1. *ping hostname or domain*
192
193
$ ping google.ch
194
195
PING google.ch(zrh11s02-in-x03.1e100.net (2a00:1450:400a:800::2003)) 56 data bytes
196
64 bytes from zrh11s02-in-x03.1e100.net (2a00:1450:400a:800::2003): icmp_seq=1 ttl=57 time=4.02 ms
197
198
199
2. *ping via IPv4*
200
201
$ ping 10.3.10.37
202
203
PING 10.3.10.37 (10.3.10.37) 56(84) bytes of data.
204
64 bytes from 10.3.10.37: icmp_seq=1 ttl=64 time=0.037 ms
205
206
207
3. *ping via IPv6*
208
209
$ ping 2a00:1450:400a:800::2003
210
211
PING 2a00:1450:400a:800::2003(2a00:1450:400a:800::2003) 56 data bytes
212
64 bytes from 2a00:1450:400a:800::2003: icmp_seq=1 ttl=57 time=5.00 ms