LINUX OS Linux is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Components of Linux System Linux Operating System has primarily three components 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. 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. System Utility − System Utility programs are responsible to do specialized, individual level tasks
LINUX OS Linux is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Components of Linux System Linux Operating System has primarily three components 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. 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. System Utility − System Utility programs are responsible to do specialized, individual level tasks
Basic Features Following are some of the important features of Linux Operating System. 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. 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. Multi-User − Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time. Multiprogramming − Linux is a multiprogramming system means multiple applications can run at same time. Hierarchical File System − Linux provides a standard file structure in which system files/ user files are arranged. 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. Security − Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.
Basic Linus Commands Linux commands are case sensitive hence you need to be careful about what you are keying in . 1. ls – List directory contents. If you know windows you would know that the command dir is used to list the contents in a directory. In Linux, the ls command is used to list out files and directories. $ ls -l filename 2. cd / var /log – Change the current directory. The forward slash is to be used in Linux. The example is a Linux directory that comes with all versions of Linux $ cd/ var /log
. 3. grep – Find text in a file. The grep command searches through many files at a time to find a piece of text you are looking for . $ grep ‘failed’ transaction.log The above command will find all of the words in the files that matched the word ‘failed ’. 4. su / sudo command – There are some commands that need elevated rights to run on a Linux system. So you run them as a System Administrator which normal users cannot do. su command changes the shell to be used as a super user and until you use the exit command you can continue to be the super user sudo – if you just need to run something as a super user, you can use the sudo command. This will allow you to run the command in elevated rights and once the command is executed you will be back to your normal rights and permissions. Example – shutdown command the shutdown command safely turns off the computer system. sudo shutdown 2 – shutdown and turns of the computer after 2 minutes sudo shutdown –r 2 – shuts down and reboots in 2 minutes Using ctrl C or shutdown –c helps in stopping the shutdown process. $ sudo shutdown 2 $ sudo shutdown –r 2
. 5. pwd – Print Working Directory One way to identify the directory you are working in is the pwd command It displays the current working directory path and is useful when directory changes are often. $ pwd 6. passwd – This command is used to change the user account password. $ passwd admin 7. mv – Move a file To move a file or rename a file you would use the mv command . Here the file name gets changed from first.txt to second.txt. $ mv first.txt second.txt
. 8. cp – Copy a file cp source file destination file . In case you need a copy of the file second.txt in the same directory you have to use the cp command $ cp second.txt third.txt 9. rm – This command is used to remove files in a directory or the directory itself. A directory cannot be removed if it is not empty. rm [name of the file] rm –r removes all the contents in a directory and the directory as well. $ rm file1 $ rm –r myprojects 10. mkdir – to make a directory. mkdir [directory name] if you would like to create a directory in the name ‘ myproject ’ type mkdir myproject $ mkdir myprojects
. 11. chmod – To change mode of a file system object. Files can have r – read, w- write and x-execute permissions. For example: chmod mode FILE chmod 744 script.sh The first number stands for the user who is associated with the file The second number is for the group associated with the file The third number is associated with everyone else who is not a part of the user or group $ chmod 744 script.sh 12. chown – This command is used to change the ownership of a file/folder or even multiple files/folders for a specified user/group. chown owner_name file_name $ chown user1 script.sh
. 13. cat - The cat command (short for “concatenate “) is one of the most frequently used commands in Linux. cat command allows you to create single or multiple files, view contents of file, concatenate files and redirect output in terminal or files. $ cat file.txt $ cat file1.txt file2.txt 14. echo – This command is used to display a text or a string to the standard output or a file. $ echo “This is an article on basic linux commands” The echo –e option acts as an interpretation of escape characters that are back-slashed . $ echo –e “This is an article is for beginners. \ nIt is on basic linux commands Output is This is an article is for beginners. It is on basic linux commands
. 15. wc - The wc (word count) command in Linux operating system is used to find out the number of new lines, word count, byte and characters count in a file specified by the file arguments . $ wc -1 readme.txt Shows the output as - 120 readme.txt wc -l : Prints the number of lines in a file. wc -w : prints the number of words in a file. wc -c : Displays the count of bytes in a file. wc -m : prints the count of characters from a file. wc -L : prints only the length of the longest line in a file 16. man – This command is used to view the on-line reference manual pages for commands/programs. $ man grep 17. history – This command is used to show previously used commands or to get information about the commands executed by a user. $ history
. 18. clear – This command lets you clear the terminal screen. $ clear 19. apt –get apt -get is a powerful and free front-end package manager for Debian /Ubuntu systems. It is used to install new software packages, remove available software packages, upgrade existing software packages as well as upgrade the entire operating system. apt – stands for advanced packaging tool. $ sudo apt-get update 20. reboot – This command may be used to halt, power-off or reboot a system as follows. $ reboot
. Directory Description / (root filesystem ) The root filesystem is the top-level directory of the filesystem . It must contain all of the files required to boot the Linux system before other filesystems are mounted. It must include all of the required executables and libraries required to boot the remaining filesystems . After the system is booted, all other filesystems are mounted on standard, well-defined mount points as subdirectories of the root filesystem . /bin The /bin directory contains user executable files. /boot Contains the static bootloader and kernel executable and configuration files required to boot a Linux computer. / dev This directory contains the device files for every hardware device attached to the system. These are not device drivers, rather they are files that represent each device on the computer and facilitate access to those devices. / etc Contains the local system configuration files for the host computer /home Home directory storage for user files. Each user has a subdirectory in /home. /lib Contains shared library files that are required to boot the system. Linux File system
. /media A place to mount external removable media devices such as USB thumb drives that may be connected to the host. / mnt A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is repairing or working on a filesystem . /opt Optional files such as vendor supplied application programs should be located here. /root This is not the root (/) filesystem . It is the home directory for the root user. / sbin System binary files. These are executables used for system administration. / tmp Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without prior notice. / usr These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation. / var Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files, email inboxes, and much more.
A shell in a Linux A shell in a Linux operating system takes input from you in the form of commands, processes it, and then gives an output. It is the interface through which a user works on the programs, commands, and scripts. A shell is accessed by a terminal which runs it. ... Hence the name Shell. File Permissions 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. [ me@linuxbox me]$ ls -l / bin/bash - rwxr - xr -x 1 root root 1113504 Jun 6 2019 / bin/bash Here we can see: The file "/bin/bash" is owned by user "root" The superuser has the right to read, write, and execute this file The file is owned by the group "root" Members of the group "root" can also read and execute this file Everybody else can read and execute this file
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.
VI Editor Vi or the Visual Editor is the default text editor that comes with most Linux systems. It is a Terminal-based text editor that users need to learn, essentially when more user-friendly text editors are not available on the system. ... Vi editor creates small size files making it light on your storage . VI editor works on two mode: Command Mode and Insert Mode Command Mode The vi editor opens in this mode, and it only understands commands In this mode, you can, move the cursor and cut, copy, paste the text This mode also saves the changes you have made to the file
vi Editor Insert mode: This mode is for inserting text in the file. You can switch to the Insert mode from the command mode by pressing ' i ' on the keyboard Once you are in Insert mode, any key would be taken as an input for the file on which you are currently working. To return to the command mode and save the changes you have made you need to press the Esc key How to use vi editor To launch the VI Editor -Open the Terminal (CLI) and type vi < filename_NEW > or < filename_EXISTING > And if you specify an existing file, then the editor would open it for you to edit. Else, you can create a new file.
VI Editing commands i - Insert at cursor (goes into insert mode ), a - Write after cursor (goes into insert mode) A - Write at the end of line (goes into insert mode ), ESC - Terminate insert mode u - Undo last change, U - Undo all changes to the entire line o - Open a new line (goes into insert mode ), dd - Delete line 3dd - Delete 3 lines ., D - Delete contents of line after the cursor C - Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion. dw - Delete word 4dw - Delete 4 words cw - Change word x - Delete character at the cursor r - Replace character R - Overwrite characters from cursor onward s - Substitute one character under cursor continue to insert S - Substitute entire line and begin to insert at the beginning of the line ~ - Change case of individual character
. Moving within a file k - Move cursor up j - Move cursor down h - Move cursor left l - Move cursor right Saving and Closing the file Shift+zz - Save the file and quit :w - Save the file but keep it open :q - Quit without saving : wq - Save the file and quit
X Window System The X Window System ( X11 , or simply X ) is a windowing system for bitmap displays, common on Unix-like operating systems. X provides the basic framework for a GUI environment: drawing and moving windows on the display device and interacting with a mouse and keyboard. The X Window System TM provides the base technology for developing graphical user interfaces. At a very basic level, X draws the elements of the GUI on the user's screen and builds in methods for sending user interactions back to the application.
Filter Commands A filter is a program that reads standard input, performs an operation upon it and writes the results to standard output. 1. Awk Command Awk is a remarkable pattern scanning and processing language, it can be used to build useful filters in Linux $ man awk 2. Sed Command sed is a powerful stream editor for filtering and transforming text . The sed man page has added control options and instructions : $ man sed 3. Grep , Egrep , Fgrep , Rgrep Commands These filters output lines matching a given pattern. They read lines from a file or standard input, and print all matching lines by default to standard output . $ egrip =grip -E
. 4. head Command : head is used to display the first parts of a file, it outputs the first 10 lines by default . tecmint@Tecmint ~ $ head / var /log/auth.log It displays the tecmint file information. 5. tail Command tail outputs the last parts ( 10 lines by default) of a file . Use –n num switch to specify the number of lines to be displayed . tecmint@Tecmint ~ $ tail –n 5 / var /log/auth.log 6. sort Command sort is used to sort lines of a text file or from standard input. Below is the content of a file named domains.list : tecmint@Tecmint ~ $ cat domains.list 7. uniq Command uniq command is used to report or omit repeated lines, it filters lines from standard input and writes the outcome to standard output .
. tecmint@TecMint ~ $ sort domains.list linuxsay.com linuxsay.com news.tecmint.com news.tecmint.com tecmint@TecMint ~ $ sort domains.list | uniq -c 2 linuxsay.com 2 news.tecmint.com 8. fmt Command fmt simple optimal text formatter, it reformats paragraphs in specified file and prints results to the standard output . tecmint@TecMint ~ $ sort domains.list 1. linuxsay.com 2.linuxsay.com tecmint@TecMint ~ $ fmt –w 1 domains.list.text 1. linuxsay.com 2.linuxsay.com
. 9. pr Command pr command converts text files or standard input for printing. tecmint@TecMint ~ $ dpkg -l | pr --columns 3 -l 20 --columns : defines number of columns created in the output . -1 : specifies page length (default is 66 lines ). 10. tr Command This tool translates or deletes characters from standard input and writes results to standard output. tr options set1 set2 This set1 means upper case letter changed into set2 i.e . lower case. $
Process As with any multitasking operating system, Linux executes multiple, simultaneous processes. Well, they appear simultaneous, anyway. Actually, a single processor core can only execute one process at a time but the Linux kernel manages to give each process its turn at the processor and each appears to be running at the same time. There are several commands that are used to control processes. They are : ps - list the processes running on the system kill - send a signal to one or more processes (usually to "kill" a process) jobs - an alternate way of listing your own processes bg - put a process in the background fg - put a process in the foreground
What are Shell Scripts? In the simplest terms, a shell script is a file containing a series of commands. The shell reads this file and carries out the commands as though they have been entered directly on the command line . To successfully write a shell script, we have to do three things: Write a script Give the shell permission to execute it Put it somewhere the shell can find it Writing a Script A shell script is a file that contains ASCII text. To create a shell script, we use a text editor . A text editor is a program, like a word processor, that reads and writes ASCII text files.
O ur first script as follows: #!/bin/bash # My first script echo "Hello World !“ This is a traditional "Hello World" program . We save it as Hello_World . The first line of the script is /bin/bash. It is a special construct, called a shebang , given to the system indicating what program is to be used to interpret the script . The second line is a comment . Everything that come after # symbol is ignored by bash. The last line is the echo command. This command simply prints its arguments on the display.
Setting Permissions The next thing we have to do is give the shell permission to execute our script. This is done with the chmod command. [ me@linuxbox me]$ chmod 755 hello_world The "755" will give us read, write, and execute permission. Everybody else will get only read and execute permission. To make the script private, (i.e., only we can read and execute), use "700" instead . Putting It in Our Path At this point, our script will run. [ me@linuxbox me]$ ./ hello_world We should see "Hello World!" displayed.