· 8 years ago · Jun 29, 2018, 12:04 PM
1
2Linux
3 Linux is a family of free and open-source software operating systems built around the Linux kernel. It is a Unix-like, open source and community-developed operating system for computers, servers, mainframes, mobile devices and embedded devices.
4 .
5
6Basic Features
7 Following are some of the important features of Linux Operating System.
8
9 Portable − Portability means software can works on different types of hardware in same way. Linux kernel and application programs supports their installation on any kind of hardware platform.
10
11 Open Source − Linux source code is freely available and it is community based development project. Multiple teams work in collaboration to enhance the capability of Linux operating system and it is continuously evolving.
12
13 Multi-User − Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.
14
15 Multiprogramming − Linux is a multiprogramming system means multiple applications can run at same time.
16
17 Hierarchical File System − Linux provides a standard file structure in which system files/ user files are arranged.
18
19 Shell − Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs. etc.
20
21 Security − Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.
22
23What is a “distribution?"
24 Linux has a number of different versions to suit nearly any type of user. From new users to hard-core users, you’ll find a “flavor†of Linux to match your needs.
25 These versions are called distributions (or, in the short form, “distros.â€) Nearly every distribution of Linux can be downloaded for free, burned onto disk (or USB thumb drive), and installed (on as many machines as you like).
26
27 List of Linux Distributions:
28 Ubuntu Linux
29 Linux Mint
30 Arch Linux
31 Deepin
32 Fedora
33 Debian
34 openSUSE.
35
36Components of Linux System
37 Linux Operating System has primarily three components
38
39 Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It consists of various modules and it interacts directly with the underlying hardware. Kernel provides the required abstraction to hide low level hardware details to system or application programs.
40
41 System Library − System libraries are special functions or programs using which application programs or system utilities accesses Kernel's features. These libraries implement most of the functionalities of the operating system and do not requires kernel module's code access rights.
42
43 System Utility − System Utility programs are responsible to do specialized, individual level tasks.
44
45Linux Architecture:
46 The architecture of a Linux System consists of the following layers −
47
48 Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
49
50 Kernel − It is the core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.
51
52 Shell − An interface to kernel, hiding complexity of kernel's functions from users. The shell takes commands from the user and executes kernel's functions.
53
54 Utilities − Utility programs that provide the user most of the functionalities of an operating systems.
55
56What Is "The Shell"?
57 Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.
58
59 On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Unix shell program, sh, written by Steve Bourne) acts as the shell program.
60
61What's A "Terminal?":
62 It's a program called a terminal emulator. This is a program that opens a window and lets you interact with the shell.
63 .
64
65What are Commands
66 A command is an instruction given to our computer by us to do whatever we want. In Mac OS, and Linux it is called terminal, whereas, in windows it is called command prompt. Commands are always case sensitive.
67
68 Commands are executed by typing in at the command line followed by pressing enter key.
69
70 This command further passes to the shell which reads the command and execute it. Shell is a method for the user to interact with the system. Default shell in Linux is called bash (Bourne-Again Shell).
71
72 Navigation
73 In this lesson, I will introduce your first three commands:
74 pwd (print working directory),
75 cd (change directory), and
76 ls (list files and directories).
77
78 pwd
79 Since a command line interface cannot provide graphic pictures of the file system structure, it must have a different way of representing it. Think of the file system tree as a maze, and you are standing in it. At any given moment, you are located in a single directory. Inside that directory, you can see its files and the pathway to its parent directory and the pathways to the subdirectories of the directory in which you are standing.
80
81 The directory you are standing in is called the working directory. To find the name of the working directory, use the pwd command.
82
83 [me@linuxbox me]$ pwd
84 /home/me
85
86 When you first log on to a Linux system, the working directory is set to your home directory.
87
88
89 cd
90 The "cd" stands for 'change directory' and this command is used to change the current directory i.e; the directory in which the user is currently working.
91
92 [me@linuxbox me]$ cd /usr/bin
93 [me@linuxbox bin]$ pwd
94 /usr/bin
95
96 cd ~ Brings you to your home directory.
97
98 cd - Brings you to your previous directory of the current directory.
99
100
101 cd .. Brings you to the parent directory of current directory.
102
103
104 cd / It takes you to the entire system's root directory.
105
106
107 ls
108 The ls command is used to list the contents of a directory. It is probably the most commonly used Linux command. It can be used in a number of different ways. Here are some examples:
109
110 ls -a - In Linux, hidden files start with . (dot) symbol and they are not visible in the regular directory. The (ls -a) command will enlist the whole list of the current directory including the hidden files.
111
112 ls -l - It will show the list in a long list format.
113
114 ls -lh - This command will show you the file sizes in human readable format. Size of the file is very difficult to read when displayed in terms of byte. The (ls -lh)command will give you the data in terms of Mb, Gb, Tb, etc.
115
116 ls -lah - you can merge tow or more options togather
117
118 ls ~ - It gives the contents of home directory.
119
120 ls ../ - It give the contents of parent directory.
121
122 ls --version - It checks the version of ls command.
123
124 less
125 less is a program that lets you view text files. This is very handy since many of the files used to control and configure Linux are human readable.
126
127 less file.txt
128
129 Once started, less will display the text file one page at a time. You may use the Page Up and Page Down keys to move through the text file. To exit less, type "q". Here are some commands that less will accept:
130
131 G - Go to the end of the text file
132
133 1G - Go to the beginning of the text file
134
135 /characters - Search forward in the text file for an occurrence of the specified characters
136
137 n - Repeat the previous search
138
139 h - Display a complete list less commands and options
140
141 q - Quit
142
143
144 file
145 As you wander around your Linux system, it is helpful to determine what kind of data a file contains before you try to view it. This is where the file command comes in. file will examine a file and tell you what kind of file it is.
146
147 To use the file program, just type:
148
149 file name_of_file.txt
150
151 Manipulating Files
152 This lesson will introduce you to the following commands:
153
154 cp - copy files and directories
155 mv - move or rename files and directories
156 rm - remove files and directories
157 mkdir - create directories
158 rmdir - create directories
159
160 These four commands are among the most frequently used Linux commands. They are the basic commands for manipulating both files and directories.
161
162
163 cp
164 The cp program copies files and directories. In its simplest form, it copies a single file:
165
166 [me@linuxbox me]$ cp file1 file2
167 Copies the contents of file1 into file2. If file2 does not exist, it is created; otherwise, file2 is silently overwritten with the contents of file1.
168
169
170 [me@linuxbox me]$ cp -i file1 file2
171 Like above however, since the "-i" (interactive) option is specified, if file2 exists, the user is prompted before it is overwritten with the contents of file1.
172
173 [me@linuxbox me]$ cp file1 dir1
174 Copy the contents of file1 (into a file named file1) inside of directory dir1.
175
176 [me@linuxbox me]$ cp -R dir1 dir2
177 Copy the contents of the directory dir1. If directory dir2 does not exist, it is created. Otherwise, it creates a directory named dir1 within directory dir2.
178
179 mv
180 The mv command moves or renames files and directories depending on how it is used. It will either move one or more files to a different directory, or it will rename a file or directory. To rename a file, it is used like this:
181
182 [me@linuxbox me]$ mv file1 file2
183 If file2 does not exist, then file1 is renamed file2. If file2 exists, its contents are silently replaced with the contents of file1.
184
185 [me@linuxbox me]$ mv -i file1 file2
186 Like above however, since the "-i" (interactive) option is specified, if file2 exists, the user is prompted before it is overwritten with the contents of file1.
187
188 [me@linuxbox me]$ mv file1 file2 file3 dir1
189 The files file1, file2, file3 are moved to directory dir1. If dir1 does not exist, mv will exit with an error.
190
191 [me@linuxbox me]$ mv dir1 dir2
192 If dir2 does not exist, then dir1 is renamed dir2. If dir2 exists, the directory dir1 is moved within directory dir2.
193
194 rm
195 The rm command removes (deletes) files and directories.
196
197 [me@linuxbox me]$ rm file..
198
199 It can also be used to delete directories:
200 [me@linuxbox me]$ rm -r directory...
201
202 rm file1 file2
203 Delete file1 and file2.
204
205 rm -i file1 file2
206 Like above however, since the "-i" (interactive) option is specified, the user is prompted before each file is deleted.
207
208 rm -r dir1 dir2
209 Directories dir1 and dir2 are deleted along with all of their contents.
210
211
212 Be careful with rm!
213 Linux does not have an undelete command. Once you delete something with rm, it's gone. You can inflict terrific damage on your system with rm if you are not careful, particularly with wildcards.
214
215 mkdir
216 Now let's learn how to create your own directory with the help of command prompt.
217
218 The mkdir stands for 'make directory'. With the help of mkdir command, you can create a new directory wherever you want in your system. Just type "mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and then press enter.
219
220 mkdir <dirname>
221
222 ls to check created directory
223
224 rmdir
225 This command is used to delete a directory. But will not be able to delete a directory including a sub-directory. It means, a directory has to be empty to be deleted.
226
227 rmdir <dirname>
228
229 Working With Commands
230 Up until now you have seen a number of commands and their mysterious options and arguments. In this lesson, we will try to remove some of that mystery. This lesson will introduce the following commands.
231
232 type - Display information about command type
233 which - Locate a command
234 help - Display reference page for shell builtin
235 man - Display an on-line command reference
236
237
238 What Are "Commands?"
239 Commands can be one of 4 different kinds:
240
241 1. An executable program like all those files we saw in /usr/bin. Within this category, programs can be compiled binaries such as programs written in C and C++, or programs written in scripting languages such as the shell, Perl, Python, Ruby, etc.
242 2. A command built into the shell itself. bash provides a number of commands internally called shell builtins. The cd command, for example, is a shell builtin.
243 3. A shell function. These are miniature shell scripts incorporated into the environment. We will cover configuring the environment and writing shell functions in later lessons, but for now, just be aware that they exist.
244 4. An alias. Commands that you can define yourselves, built from other commands. This will be covered in a later lesson.
245 Identifying Commands
246 It is often useful to know exactly which of the four kinds of commands is being used and Linux provides a couple of ways to find out.
247
248 type
249 The type command is a shell builtin that displays the kind of command the shell will execute, given a particular command name. It works like this:
250
251 [me@linuxbox me]$ type command
252 where “command†is the name of the command you want to examine. Here are some
253
254 examples:
255 [me@linuxbox me]$ type type
256 type is a shell builtin
257
258 [me@linuxbox me]$ type ls
259 ls is aliased to `ls --color=tty'
260
261 [me@linuxbox me]$ type cp
262 cp is /bin/cp
263
264 Here we see the results for three different commands. Notice that the one for ls (taken from a Fedora system) and how the ls command is actually an alias for the ls command with the “-- color=tty†option added. Now we know why the output from ls is displayed in color!
265
266 which
267 Sometimes there is more than one version of an executable program installed on a system. While this is not very common on desktop systems, it's not unusual on large servers. To determine the exact location of a given executable, the which command is used:
268
269 [me@linuxbox me]$ which ls
270 /bin/ls
271
272 which only works for executable programs, not builtins nor aliases that are substitutes for actual executable programs.
273
274
275 Getting Command Documentation
276 With this knowledge of what a command is, we can now search for the documentation available for each kind of command.
277
278 help
279 bash has a built-in help facility available for each of the shell builtins. To use it, type “help†followed by the name of the shell builtin. Optionally, you may add the -m option to change the format of the output. For example:
280
281 [me@linuxbox me]$ help -m cd
282
283 I/O Redirection
284 In this lesson, we will explore a powerful feature used by many command line programs called input/output redirection. As we have seen, many commands such as ls print their output on the display. This does not have to be the case, however. By using some special notations we can redirect the output of many commands to files, devices, and even to the input of other commands.
285
286 Standard Output
287 Most command line programs that display their results do so by sending their results to a facility called standard output. By default, standard output directs its contents to the display. To redirect standard output to a file, the ">" character is used like this:
288
289 [me@linuxbox me]$ ls > file_list.txt
290
291 In this example, the ls command is executed and the results are written in a file named file_list.txt. Since the output of ls was redirected to the file, no results appear on the display.
292
293 Each time the command above is repeated, file_list.txt is overwritten from the beginning with the output of the command ls. If you want the new results to be appended to the file instead, use ">>" like this:
294
295 [me@linuxbox me]$ ls >> file_list.txt
296
297 Standard Input
298 Many commands can accept input from a facility called standard input. By default, standard input gets its contents from the keyboard, but like standard output, it can be redirected. To redirect standard input from a file instead of the keyboard, the "<" character is used like this:
299
300 [me@linuxbox me]$ sort < file_list.txt
301
302 In the example above, we used the sort command to process the contents of file_list.txt. The results are output on the display since the standard output was not redirected. We could redirect standard output to another file like this:
303
304 [me@linuxbox me]$ sort < file_list.txt > sorted_file_list.txt
305
306 Pipelines
307 The most useful and powerful thing you can do with I/O redirection is to connect multiple commands together with what are called pipelines. With pipelines, the standard output of one command is fed into the standard input of another. Here is my absolute favorite:
308
309 [me@linuxbox me]$ ls -l | less
310
311 In this example, the output of the ls command is fed into less. By using this "| less" trick, you can make any command have scrolling output. I use this technique all the time.
312
313 By connecting commands together, you can acomplish amazing feats. Here are some examples you'll want to try:
314
315 [me@linuxbox me]$ ls -lt | head - Displays the 10 newest files in the current directory.
316
317 [me@linuxbox me]$ du | sort -nr - Displays a list of directories and how much space they consume, sorted from the largest to the smallest.
318
319 [me@linuxbox me]$ find . -type f -print | wc -l - Displays the total number of files in the current working directory and all of its subdirectories.
320
321 Filters
322 One kind of program frequently used in pipelines is called filters. Filters take standard input and perform an operation upon it and send the results to standard output. In this way, they can be combined to process information in powerful ways. Here are some of the common programs that can act as filters:
323
324 sort - Sorts standard input then outputs the sorted result on standard output.
325
326 uniq - Given a sorted stream of data from standard input, it removes duplicate lines of data (i.e., it makes sure that every line is unique).
327
328 grep - Examines each line of data it receives from standard input and outputs every line that contains a specified pattern of characters.
329
330 fmt - Reads text from standard input, then outputs formatted text on standard output.
331
332 pr - Takes text input from standard input and splits the data into pages with page breaks, headers and footers in preparation for printing.
333
334 head - Outputs the first few lines of its input. Useful for getting the header of a file.
335
336 tail - Outputs the last few lines of its input. Useful for things like getting the most recent entries from a log file.
337
338 tr - Translates characters. Can be used to perform tasks such as upper/lowercase conversions or changing line termination characters from one type to another (for example, converting DOS text files into Unix style text files).
339
340 sed - Stream editor. Can perform more sophisticated text translations than tr.
341
342 Permissions
343 The Unix-like operating systems, such as Linux differ from other computing systems in that they are not only multitasking but also multi-user.
344
345 What exactly does this mean? It means that more than one user can be operating the computer at the same time. While your computer only has one keyboard and monitor, it can still be used by more than one user. For example, if your computer is attached to a network, or the Internet, remote users can log in via ssh (secure shell) and operate the computer. In fact, remote users can execute graphical applications and have the output displayed on a remote computer. The X Window system supports this.
346
347 This lesson will cover the following commands:
348
349 chmod - modify file access rights
350 su - temporarily become the superuser
351 sudo - temporarily become the superuser
352 chown - change file ownership
353 chgrp - change a file's group ownership
354
355
356 File Permissions
357 On a Linux system, each file and directory is assigned access rights for the owner of the file, the members of a group of related users, and everybody else. Rights can be assigned to read a file, to write a file, and to execute a file (i.e., run the file as a program).
358
359 To see the permission settings for a file, we can use the ls command. As an example, we will look at the bash program which is located in the /bin directory:
360
361 [me@linuxbox me]$ ls -l /bin/bash
362 -rwxr-xr-x 1 root root 316848 Feb 27 2000 /bin/bash
363
364 Here we can see:
365 The file "/bin/bash" is owned by user "root"
366 The superuser has the right to read, write, and execute this file
367 The file is owned by the group "root"
368 Members of the group "root" can also read and execute this file
369 Everybody else can read and execute this file
370
371 In the diagram below, we see how the first portion of the listing is interpreted. It consists of a character indicating the file type, followed by three sets of three characters that convey the reading, writing and execution permission for the owner, group, and everybody else.
372
373 file_permissions.png
374
375 chmod
376 The chmod command is used to change the permissions of a file or directory. To use it, you specify the desired permission settings and the file or files that you wish to modify. There are two ways to specify the permissions. In this lesson we will focus on one of these, called the octal notation method.
377
378 It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works:
379
380 rwx rwx rwx = 111 111 111
381 rw- rw- rw- = 110 110 110
382 rwx --- --- = 111 000 000
383
384 and so on...
385
386 [me@linuxbox me]$ chmod 600 some_file
387
388 777 - (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
389
390 755 - (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
391
392 700 - (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
393
394 666 - (rw-rw-rw-) All users may read and write the file.
395
396 644 - (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
397
398 600 - (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
399
400 Directory Permissions
401 The chmod command can also be used to control the access permissions for directories. Again, we can use the octal notation to set permissions, but the meaning of the r, w, and x attributes is different:
402
403 r - Allows the contents of the directory to be listed if the x attribute is also set.
404 w - Allows files within the directory to be created, deleted, or renamed if the x attribute is also set.
405 x - Allows a directory to be entered (i.e. cd dir).
406 Here are some useful settings for directories:
407
408 777 - (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.
409
410 755 - (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.
411
412 700 - (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
413
414 su
415 It is often necessary to become the superuser to perform important system administration tasks, but as you have been warned, you should not stay logged in as the superuser.
416
417 [me@linuxbox me]$ su
418 Password:
419 [root@linuxbox me]#
420
421 sudo
422 In some distributions, most notably Ubuntu, an alternate method is used. Rather than using su, these systems employ the sudo command instead.
423
424 [me@linuxbox me]$ sudo some_command
425 Password:
426 [me@linuxbox me]$
427
428 chown
429 You can change the owner of a file by using the chown command. Here's an example: Suppose I wanted to change the owner of some_file from "me" to "you". I could:
430
431 [me@linuxbox me]$ su
432 Password:
433 [root@linuxbox me]# chown you some_file
434 [root@linuxbox me]# exit
435 [me@linuxbox me]$
436
437 chgrp
438 The group ownership of a file or directory may be changed with chgrp. This command is used like this:
439
440 [me@linuxbox me]$ chgrp new_group some_file
441
442Linux file system
443 The table below lists some interesting places to explore. This is by no means a complete list, but it should prove to be an interesting adventure. For each of the directories listed below, do the following:
444
445 cd into each directory.
446 Use ls to list the contents of the directory.
447 If you see an interesting file, use the file command to determine its contents.
448 For text files, use less to view them.
449 Interesting directories and their contents
450
451 Directory Description
452 / - The root directory where the file system begins. In most cases the root directory only contains subdirectories.
453 /boot - This is where the Linux kernel and boot loader files are kept. The kernel is a file called vmlinuz.
454 /etc - The /etc directory contains the configuration files for the system. All of the files in /etc should be text files. Points of interest:
455 /etc/passwd - The passwd file contains the essential information for each user. It is here that users are defined.
456 /etc/fstab - The fstab file contains a table of devices that get mounted when your system boots. This file defines your disk drives.
457 /etc/hosts - This file lists the network host names and IP addresses that are intrinsically known to the system.
458 /etc/init.d - This directory contains the scripts that start various system services typically at boot time.
459
460 /bin, /usr/bin - These two directories contain most of the programs for the system. The /bin directory has the essential programs that the system requires to operate, while /usr/bin contains applications for the system's users.
461
462 /sbin, /usr/sbin - The sbin directories contain programs for system administration, mostly for use by the superuser.
463
464 /usr - The /usr directory contains a variety of things that support user applications. Some highlights:
465 /usr/share/X11 - Support files for the X Window system
466 /usr/share/dict - Dictionaries for the spelling checker. Bet you didn't know that Linux had a spelling checker. See look and aspell.
467 /usr/share/doc - Various documentation files in a variety of formats.
468 /usr/share/man - The man pages are kept here.
469 /usr/src - Source code files. If you installed the kernel source code package, you will find the entire Linux kernel source code here.
470
471 /usr/local - /usr/local and its subdirectories are used for the installation of software and other files for use on the local machine. What this really means is that software that is not part of the official distribution (which usually goes in /usr/bin) goes here.
472
473 When you find interesting programs to install on your system, they should be installed in one of the /usr/local directories. Most often, the directory of choice is /usr/local/bin.
474 /var - The /var directory contains files that change as the system is running. This includes:
475 /var/log - Directory that contains log files. These are updated as the system runs. You should view the files in this directory from time to time, to monitor the health of your system.
476 /var/spool - This directory is used to hold files that are queued for some process, such as mail messages and print jobs. When a user's mail first arrives on the local system (assuming you have local mail), the messages are first stored in /var/spool/mail
477
478 /lib - The shared libraries (similar to DLLs in that other operating system) are kept here.
479 /home /home is where users keep their personal work. In general, this is the only place users are allowed to write files. This keeps things nice and clean :-)
480
481 /root - This is the superuser's home directory.
482
483 /tmp - /tmp is a directory in which programs can write their temporary files.
484
485 /dev - The /dev directory is a special directory, since it does not really contain
486 files in the usual sense. Rather, it contains devices that are available to the system. In Linux (like Unix), devices are treated like files. You can read and write devices as though they were files. For example /dev/fd0 is the first floppy disk drive, /dev/sda (/dev/hda on older systems) is the first hard drive. All the devices that the kernel understands are represented here.
487
488 /proc - The /proc directory is also special. This directory does not contain files. In fact, this directory does not really exist at all. It is entirely virtual. The /proc directory contains little peep holes into the kernel itself. There are a group of numbered entries in this directory that correspond to all the processes running on the system. In addition, there are a number of named entries that permit access to the current configuration of the system. Many of these entries can be viewed. Try viewing /proc/cpuinfo. This entry will tell you what the kernel thinks of your CPU.
489
490 /media,/mnt - Finally, we come to /media, a normal directory which is used in a special way. The /media directory is used for mount points. As we learned in the second lesson, the different physical storage devices (like hard disk drives) are attached to the file system tree in various places. This process of attaching a device to the tree is called mounting. For a device to be available, it must first be mounted.
491 When your system boots, it reads a list of mounting instructions in the file /etc/fstab, which describes which device is mounted at which mount point in the directory tree. This takes care of the hard drives, but you may also have devices that are considered temporary, such as CD-ROMs, thumb drives, and floppy disks. Since these are removable, they do not stay mounted all the time. The /media directory is used by the automatic device mounting mechanisms found in modern desktop oriented Linux distributions. On systems that require manual mounting of removable devices, the /mnt directory provides a convenient place for mounting these temporary devices. You will often see the directories /mnt/floppy and /mnt/cdrom. To see what devices and mount points are used, type mount.