2. LINUX
• Linux is an operating system's kernel. It was actually created by Linus
Torvalds from Scratch. Linux is free and open-source, that means that
you can simply change anything in Linux and redistribute it in your
own name! There are several Linux Distributions, commonly called
“distros”.
• Ubuntu Linux
• Red Hat Enterprise Linux
• Linux Mint
• Debian
• Fedora
3. Linux Shell or “Terminal”
• So, basically, a shell is a program that receives
commands from the user and gives it to the OS to
process, and it shows the output. Linux's shell is
its main part. Its distros come in GUI (graphical
user interface), but basically, Linux has a CLI
(command line interface).
• To open the terminal, press Ctrl+Alt+T in Ubuntu
4. Installation
• Virtual box is free and open-source virtualization software from Oracle. It
enables us to install other operating systems in virtual machines. It is
recommended that our system should have at least 4GB of RAM to get decent
performance from the virtual operating system.
• Then we need to go to the website of Oracle VirtualBox and get the latest
stable version from there.Next, download Ubuntu. We can get this from the
official website of Ubuntu . Now we have installed VirtualBox, and we have
downloaded Ubuntu. We are now set to install Linux in VirtualBox.
5. Shortcut keys to Open
and Close Ubuntu
Terminal
• In Ubuntu the terminal shortcut key is mapped to
ctrl+Alt+T to open the terminal and for closing ctrl+d.
6. Some Basic
Commands
• Echo : echo command in Linux is used to display line of
text/string that are passed as an argument. EX : echo
hello(it will return hello).
• Cal : To display current month's calendar. For all months we
must write cal 2021 then it will show all months of that
year.
• Date : This command will show gives the present date ,
time and year.
• Clear : This command will clear your terminal.Shortcut key
is ctrl+L
• History: To get history of the commands.
• Exit: Exit from terminal
• history –c; history –w : will clear the history of commands.
7. • Ls:- list the contents of the folder
• Cat:- It is used to create a file with content. It can concatenate two or more file contents.
• Touch:- it is used to create a file without content.
• Cp:- copies file from one location to another.
• Cd:- It is used for changing the directory.
• Mv:-It is used to move files from one location to another.
• Pwd:-It prints the current working directory with full path name from terminal
8. • mkdir:- It is used to create new directory.
• Whereis: It is used to locate the source and manual pages
of the command.
• Man:- It provides online documentation for all possible
commands and its options.
• WHOAMI:-It is used to find out the current user of the
terminal.
• Info:- It provides online documentation for all the
commands but in a better structured way.
9. • Bc :-It means the basic calculator, used for the basic calculations.
• Grep :- It searches the given file for lines containing a match to the given strings or
words.
• Head:- It prints the first 10 lines of the given file.
• Tail :-It prints the last 10 lines of the given file.
• Tac :-It prints content of the given file in reverse order.
• Df :- Report disk usages of file system. It is useful for user as well as System
Administrator to keep track of their disk usages.
10. • DU -Estimate files space usage. df only reports usage statistics on file systems,
while ‘du‘, on the other hand, measures directory contents.
• PS - ps (Process) gives the status of running processes with a unique Id called
PID.
• SUDO -It allows a permitted user to execute a command as the super user or
another user.
• SU -It is used to run shell with substitute user and group IDs.It helps to change
login session’s owner without the owner having to first logout of that session.
• PASSWD-It is used for changing the passwd.It is mandatory to know the current
passwd for the security reason.
11. Deleting Files
and
Directories
• rm <file> : Remove a file .e.g., rm ~/Desktop/file1.txt
• rm -r <directory> : Removes a directory. e.g., rm -r
~/newdir
• rm –i : Removes in an interactive manner. This is a good
safety measure.
• rmdir <empty directory> : Only remove empty directories
.e.g., rmdir ~/emptydir
12. Shell
• A shell is a user interface for access to an operating
system's services. Most often the user interacts with
the shell using a command-line interface (CLI).
The terminal is a program that opens a graphical
window and lets you interact with the shell.
• Shell is a program which processes commands and
returns output , like bash in Linux .
• Commands are case sensitive.
13. • We can use this technique to write commands in shell:-
CommandName -options input.
• commandName must be a valid program on the Shell’s Path. To check this, use the which command
like :
which commandName
• If a path is returned, then the commandName is valid and vice versa.
Example:-
• echo $Path: Path of the command Path.
• which cal: cal command was in which folder.
• Date –u/date --universal: gives universal standard time.
14. Short Form:-
• We can specify options for each command to customise the commands behaviour. These can be
either “short-form” options or “long-form” options.
• Each command behaves differently so check the command’s manual (man) page for the specifics of
each command’s behaviour.
• Short-form options are where a letter defines an option. Each option is prepended by a dash “-“
like:
commandName –a –b –c args
• To save typing, you could join together the options: commandName –abc args.
• Both of these formats are equivalent.
Long Form:-
• There are long-form options defined to make options easier to identify.
• Longform options are usually prepended by a double dash “--“.
• Long-form options cannot be joined together like short-form options can.
• If long form options are defined for options “a”, “b” and “c”, then: commandName –a –b -c
arguments is equivalent to commandName --alpha --beta --charlie arguments
15. Bash
Scripting
• Bash is a type of interpreter that processes shell commands. A
command is given in the form of plain text that calls operating
system services to perform a task.
• Commands like ls and cd are frequently used by programmers;
these commands are written in the terminal. The terminal acts as
an interface for the shell interpreter.
• A Bash script is a text file containing a series of commands.
• Bash scripts are given an extension of .sh
16. Piping
• Standard Data Streams can be redirected and are identified using their stream number. Redirection of the
standard output of one command to the standard input of another command is known as piping.
• Redirecting Standard Output: Standard output is stream number 1. There are 2 methods to redirect
standard output. The long form, using the stream number: commandName –options arguments 1>
destination Or the short form, with no stream number: commandName –options arguments >
destination
• Redirecting Standard Error: Standard error is stream number 2. Here is how to redirect standard error
commandName –options arguments 2> destination Standard error can be redirected at the same time as
standard output: commandName –options arguments 1> output_destination 2> error_destination
• Redirecting Standard Input: Standard Input is stream number 0. There are 2 methods to redirect
standard Input. The long form, using the stream number: commandName –options arguments 0<
input_source Or the short form, with no stream number: commandName –options arguments <
input_source
17. Aliases
• It is the nickname for a command/pipeline.
• It is a build in shell command that lets us assign name for a long command or frequently
used command.
• Aliases go in a .bash_aliases file in your home directory. If it does not exist, you need to
create it ,spelled exactly
• Example: alias aliasName=”ABCD”
18. Piping to an
Alias
• If the first command in an alias accepts standard input,
then the alias can be piped to; even if it is an entire
pipeline!
• Our alias is currently: alias calmagic=”cal –A 1 –B 1 12
2017”
• cal is the first command in this alias, but cal doesn’t
accept standard input.Therefore, this would not work:
commandOne –options arguments | calmagic
• However, if we adjust our alias so that it can accept
standard input:
alias calmagic=”xargs cal –A 1 –B 1 12 2017”
• This will now work: commandOne –options arguments |
calmagic
19. File Achieving
and
Compressing
• Archiving and compressing files in Linux is a two-step process.
• 1) Create a Tarball First, you will create what is known as a tar
file or “tarball”. A tarball is a way of bundling together the files
that you want to archive.
• 2) Compress the tarball with a compression
algorithm.Secondly, you will then compress that tarball with
one of a variety of compression algorithms.
• Creating a tarball
• tar –cvf <name of tarball> <file>…
20. • Checking a Tarball’s Contents
• tar –tf <name of tarball>
• Extracting a Tar ball’s Contents
• tar –xv <name of tarball>
• Compressing Tarballs
Tarballs are just containers for files. They don’t by themselves
do any compression, but they can be compressed using a
variety of compression algorithms.The main types of
compression algorithms are gzip and bzip2.
Compressing and Decompressing with gzip
Compressing with gzip:- gzip <name of tarball>
Decompressing with gzip:- gunzip <name of tarball>
21. • Compressing and Decompressing with bzip2
Compressing with bzip2: bzip2 <name of tarball>
Decompressing with bzip2 : bunzip2 <name of tarball>
Doing it all in one step
Creating a tarball and compressing via gzip: tar –cvzf <name of tarball> <file>
Decompressing a tarball and extracting via xzip: tar –xvzf <name of tarball>
Creating a tarball and compressing via bzip2: tar –cvjf <name of tarball> <file>
Decompressing a tarball and extracting via bzip2: tar –xvjf <name of tarball>
Creating a tarball and compressing via xzip : tar –cvJf<name of tarball> <file>
Decompressing a tarball and extracting via xzip : tar –xvJf<name of tarball>