You are on page 1of 9

What is Linux?

1) Just like Windows and Mac, Linux is an operating system. An operating system is
a software that manages all the resources of a computer. It is first and the most
important program that runs on the computer and remains active till the machine is
on.
2) Free and Open source software which means it is free to download and use. It's
source code is freely available for anyone to view, modify and distribute.
3) It is based on the Unix system. Most of the commands used on Unix and Linux are
same. There is no much differene between them and learning one is eqaully learning
other.

Who Created?

1) Linus Torvalds created it in 1991. He created it as an alternative to the


expensive Unix systems. The name Linux is derived from it's creator.
2) He offered the Linux kernel for free and invited other to contribute to it.
3) It is maintained by a community.

Why use Linux?

1) It is powerful operating system and is popular and widely used because of it's
Effeciency, Reliablity and Security.
2) It is a cross platform compatable. Run on great variety of hardware
platforms(Desktops, Laptops, Servers)
3) Multiuser and multitasking system.
a) Multiuser: means multiple users can work on the system and can access system
resources like printers, memory, hard-disk etc at the same time. There can be
different user accounts that are password protected and each User gets a home
directory for storing the files.
b) Multitasking: which means different applications can run at the same time.

Components of Linux:

The main component of the Linux is the Kernel. It is the lowest level of the OS and
it controls the computer resources like CPU memory and other devices.
It is the core of the system and is actually between the hardware and the software
applications.
The kernel directly communicates with the hardware but it does not directly deals
with the user. It starts a seperate interactive program called SHELL.
Shell acts as the interface between the user and the system.
Shell is a command interpreter that takes a command from user and translate them
into action.
When a user login in the kernel starts a seperate Shell process for the user. So,
Shell interacts with the User and kernel with the hardware.
Different types of Shells were developed for Linux like BASH(Bourne Again shell), C
shell, Korn shell, Z shell. All have different characteristics and we need one of
them.
Most distributions include all shell and by default we run the BASH shell.

Utilities:
Then we have the supporting utilities, system libraries and the application
programs.
Most of the utilites for Linux are written and distributed free by GNU.
Shell is also a special interactive utility.

Linux Distributions:

a) It is a complete Linux system package that contains the Linux kernel, utilities,
libraries and application programs specific to the distribution.
Distributions may include compilers, browsers, text editors, media softwares,
development tools etc.
b) Since, linux is freely re-distributable many distributions are created by many
vendors and communities and each distribution is intended to meet the requriments
of diiferent types of users. We can treat distributions as different versions of
linux that combined linux kernel with their own specialized utilities.
c) Desktop use and Server use
d) Commercial and Non-commercial Distributions
e) one standard version of kernel and many types of distributions.

some popular Linux Distrubutions:


Ubuntu Linux, Linux Mint, Arch Linux, Fedora, OpenSuse, CentOS

We can check the top distribution at the link: distrowatch.com

Graphical Interface:

To interact with the system we need an Interface


Earlier Days - Command Line Interface(CLI) and Text Interface were available.
These days: Graphical User Interface(GUI)

In CLI we interact with the system using commands


In GUI we interact with the system using by Menus, Icons and Windows
GUI is provided through the desktop environment
Popular Desktop Environments: Unity, GNOME, KDE, MATE

For most desktop distributions the GUI is the default interface


CLI is available through terminal consoles
GUI tools are just a front end to the underlying Linux commands

Installing Linux:

- Physical Installation : For physical installation we need to have a spare


computer on which we install and run Linux OS
- Virtual Installation : we can install Linux on our current OS

Virtualization:

It allows you to create virtual computers within your physical computer(we can run
more than one OS on machine at the same time)
The Virtual computer which we created on Physical computer is called as Virtual
Machine
Each Virtual Machine acts as a standalone computer and can run its own OS
The OS of physical computer is called as Host OS and the OS's which run inside OS
are Guest OS.
A Guest OS run in the window of Host OS like an other application
TO implement Virtualization we need a Virtualization software application - Oracle
VM Virtual Box

LInux Directory Structure:

All the files in the Linux OS are organised into Directories. A directory is a
container that contains other directories and files. In windows we use the word
folder and in Linux we call it as Directory.
- The First directory in the directory structure is the Root directory and it
represented by a Forward slash(/).
- All other directories and files in the Linux system are presented inside the Root
directory. So, everything in the Linux system begins with the Root directory.
- Inside the Root directory we will have several directories and some of the common
ones are
a) bin : contains the executable commands and utilities
b) etc : contains system configuration files
c) dev: contains file interfaces for different devices
d) home: contains user home directories
e) opt : contains commercial s/w products that are not installed by default on the
system
f) sbin: contains programs for performing admin level system tasks such as N/W
management and disk partioning
g) tmp: contains temperory files created by various programs, it is generally
cleared on reboot should not store anything which is important
h) usr: contains user related programs and data files
i) var: contains files that change frequently such as log files and DB's

FileSystem Hierarchy standard(FHS) :

- Linux filesystem names are based on the FHS which is updated occasionally. we can
check the names at the site of FHS.
- Like home directory all the directories will have sub-directories. so all the
directories and files are connected in a Hierachial structure.
- The Hierachial structure will be resembles in a inverted tree. so it is also
reffered to as Directory tree.
- Everything in linux can be viewed as file. Linux treats everything as file so the
directory structure is also referred to as FileSystem.

Current Directory and Parent Directory:

- single dot(.) represent current


- double dot (..) represent parent

Pathnames:

- we can access the directories and files of current directory easily


- But if we want to access the files or directories of other directory there are
two ways to access
a) using cd command
b) Pathnames

- If we want to be in current directory and want to access the directories and


files of other directory then we have to specify Pathnames of the files instead of
simple file
- A pathname allows us to identify a file in the system
- Pathnames may be 1) absolute 2) Relative
1) Absolute pathnames: complete pathname beginning with the Root directory.
Absolute pathname starts at the Root directory.
- always begins with a forward slash

2) Relative Pathname: Do not begin with a forward slash

Commands:

file : Display file type of a file


wc : Counts lines, words and characters in a file
eg: wc filename
wc -l - displays no:of lines in file
wc -w - displays words
ec -c - disaplays characters
clear : Clears the screen
echo : Displays whatever is supplied to it
date : Displays the current date and time
cal : Displays the calendar of current month
who : Displays all users logged into system
whoami: Displays the username of the user who runs the command

Linux Commands

Ctrl+A begining and Ctrl+E ending

who command: tell us about user who logged in and the time
cal command: gives the calendar
cal month year command: gives the calendar of that particular year
Eg: cal 4 1991
Eg: cal apr 1991

date command: gives the date


If we want date in a customized format:
date 'DATE:%m-%y%nTIME:%H:%M:%S'

PWD Command: Print Working Directory


Tells about the which directory We are located at

touch command: used to create empty text files


Eg: touch sat1 sat2

Changing Directories:
cd command: used for navigation between directories and folders
cd .. : will takes us to the previous directory
cd / :will take us to the root directory
cd ~/ : takes us to the home directory
cd without any argument, then home directory becomes current directory. So, cd
followed by nothing takes us to home directory.
cd - : take us to the previous working directory

Creating Directories:
mkdir command is used to create directories.
Eg: mkdir followed by directory name creates the directory
mkdir d1
We can make directory trees with single mkdir command
Eg: mkdir d1 d1/d1A d1/d1B
The other way of creating direcorty trees is by using -p option
If we want to create a directory inside directory then we should use the following
command.
Eg: mkdir -p dirA/dirA1/dirA2 (nested directories)
Eg: mkdir -p dir1/dir1A1/dir1B - If the directories are not available it will
create all the directories.

ls command: lists conents of current directory


gives the listing of everything which is in the current directory
Directories - blue
Regular files - white
Executables - green
link files - light blue
If we want color distribution of files in terminal
ls --color=auto

If we want to display each file and directory on a seperate line - ls -1


to display files in reverse order - ls -r

A file who first character is dot is a hidden file (.)


Linux uses hidden files to store configuration information
ls -a : display all the files including hidden files
ls -A : display hidden files but not the current and parent directories
ls -F : a special character will be added to indicate file type
directories with (/) slash
Executable with (*)
Symbolic links with (@)
Ordinary files are not appended with any character
ls -R : recursively display all the sub-directories and files present in the
directory

ls -l : long listing of all files(details)

ls -l direcory: show all the contents of files and directories


ls -ld filename: show the directories itself
ls -lt : orders files by modification time(newest first)
ls -ltr : oldest first
ls -lS : orders files by their size(biggest first)
ls -lSr : smallest first
ls -lh : size in human readable form
ls -li : index number of each file
ls -ln : displays userid and groupid instead of user name and group name

Eg: -rw-rw-r-- 1 owner (group of the file) file size month date time
file name/directory
drwxrwxr-x
First char represents the file type
d for directory
- for ordinary file

After the first character, the remaining 9 characters shows the permissions of the
file.
Number represents the links of the file

mv Command: Used to rename files and same in case of directory


Eg: mv filename(to be renamed) filename(new name)

Moving Files and Directories:


$mv source-file destination-dir
$mv file1 dirA
$mv -i file1 dirA
$mv file1 ../file2 dir/fileX dirA
$mv dir1 dir2 dirA

Renaming Files and Directories:


$mv file-name new name
$mv dirA dirABC

Moving and Renaming:


$mv file-name directory-dir/newname
$mv file1 dirA/mylife
cp command: copys files
$cp source-file destination-file
cp file1 file2 : copies the file1 content to file2
cp file1 folder/ : copies the file from one folder to another folder
cp -rf folder1/ folder2/ : copies folder1 to folder2
cp -i file1 file2 : asks whether to to copy to file2 or not(over writing)

rm command: remove or deletes files


rmdir command: delete an empty directory
rm -r "foldername" : to remove non-empty directory

clear command: to clear the screen

man command: manual command


gives the description of all the commands

Cat filename : is used to view the contents of the file

If the content of the file is large means,


we will use more and less command

more filename
less filename

Spacebar - to go forward one page


Enter - to go forward one line
q - to quit

To view the content of file top and bottom we can use head and tail command. Both
the commands displays 10 lines of the file

-n displays any number of files

Eg: head -n 5 filename


tail -n 8 filename

head filename
tail filename

cat > : is used for creating files


cat < : is used to view the content in the file
cat >> : for appending the content in the sigle file

If we want to append the content of two files into a new single file then the
following command is used
cat file1 file2 > file3

If we want to append the content of file1 into file2 then the following command is
used
cat file1 >> file2

nano Editor:

Text Editors: nano, vi and emacs


nano is simple and easy to use

Accessing nano editor:


$ nano filename
Saving a file : ctrl+o -> writing out
Exiting : ctrl+s

Command line options of nano:


$ nano -m filename - Provies mouse support
$ nano -v filename - Opens the file in view mode
$ nano -B filename d - Backs up the file
$ nano -i filename - Automatically indents new line at the same position as the
previous line
$ nano -c filename - Always shows the cursor position
$ nano -k filename - Cut is performed from cursor position instead of the whole
line
$ nano -x filename - File opened in expert mode

WildCards:
Wildcards are special symbols that are used to form patterns that match a group of
file names.
WildCards using sometimes called Globbing
Wildcard characters are called Globs
Globbing - Process of pattern matching with wildcards

* : Matches any combination of zero or more characters


Eg: cat poem1 poem2 poem3 poem4
cat poem*
ls -l ch4 chap1 chap2 chap3 chap4 chap5
ls -l ch*
cp factorial.c number.c stack.c cprograms/
cp *.c
rm -i old lesson oldscript oldfile oldchapter5
rm -i old*

? :Matches exactly one character


Eg: ? - Single character filenames
k? - k followed by any single character km ka k1 k2 k5
k?p - k followed by any single character, followed by p kmp kap k.p
k2p ktp
chap?? - chap followed by two characters chap12 chap 18 chatAB chapX
??? - filenames with three characters
???* - filenames with three or more characters

[]:character class
Eg: Five character filenames that begin with the poem and end in A, B, C, D, E -
poem[A, B, C, D, E]
Filenames that start with a letter from a to k and end with a digit - [a-
k]*[0-9]
Filenames that start with any letter from a to k 0r u to z and end with a
digit - [a-ku-z]*[0-9]
Filenames that don't start with an x,y,z - [!xyz]*
Filenames that don't begin with a digit - [!0-9]*

Links:
ln command allows us to give more than one name to a file
Linux supports two links 1) Hard Link 2) Symbolic/Soft Link
Hard Link : $ln filename linkname
Soft Link : $ln -s filename linkname

Symbolic links are created across different filesystems while Hard links are
created only inside local filesystem.
We cannot create Hard links for directories while Symbolic links are created for
directories

find - -inum inodenumber

Comparing Files:
cmp command: $cmp file1 file2
detail list: $cmp -l file1 file2

comm command: $comm sortedfile1 soretedfile2


firstcolumn: Displays lines that are unique to first file
second column: Displays lines that are unique to second file
third column: Displays lines common to both the files

diff command: $diff file1 file2


$diff -s file1 file2 - shows identical files

sdiff command: used to compare files side by side

Cut and Paste:


cut : Extracting columns or fields of data from a file
paste : join files vertically

Extracting columns using cut:


-c options
$cut -c6 filename : Extract 6th column
$cut -c2,5,8 filename : Extract 2nd,5th and 8th column
$cut -c10-20 filename : Extract columns from 10 to 20

Extracting fields using cut:


-f option : Followed by the field number to extract
-d option : Field delimiter used in the file
$cut -d':' -f1 filename : Extract first field, : is the delimiter
$cut -d':' -f1,3,5 filename : Extract 1st,3rd,5th fields
$cut -d'#' -f2-5,6-8 filename : Extract fields 2,4,5 and 6,7,8
$cut -s -d'#' -f-6 filename : Not print lines that don't contain delimiters
$cut -f-6 filename : Tab is the delimiter

Paste:
$paste file1,file2,file3......
paste -d"|" f1.txt f2.txt f3.txt
-s paste together lines from the same file

Sorting files:
$sort filename

-n sorts according to the numerical value


-r reverses the sort order
-0 file write the sorted o/p to a file
-u removes duplicate lines
-c checks whether the file is sorted
-m filelist merges sorted file
-M sorts on month
du command : is used for how much memory is used by each file
du -s command : gives the total memory used by the files

du -sh command : gives how much memory has been used in MB

df command : datafile system, gives the memory used and how much is left and where
it is mounted

Vi Editor:

Vi filename : this creates a new file, takes us to the vi editor


Press i for entering the text

You might also like