Linux Basic Commands
Unit - I OS & NW Fundamentals
What is LINUX
• Linux is a freely distributed implementation of a
UNIX-like kernel, the lowlevel core of an operating
system.
The Portable
• Linux was developed by Linus Torvalds at the
Operating
System
InterfaceUniversity of Helsinki, with the help of UNIX
(POSIX) is a
programmers from across the Internet.
family of
• It began as a hobby inspired by Andy Tanenbaum’s
standards
specified by the
Minix, a small UNIX like system, but has grown to
IEEE Computer
Society for
become a complete system in its own right.
maintaining
• The intention is that the Linux kernel will not
compatibility
between
incorporate proprietary code but will contain
operating
systems.
nothing but freely distributable code.
GNU Project and the Free Software Foundation
• The Free Software Foundation was set up by
Richard Stallman, the author of GNU Emacs, one
of the best-known text editors for UNIX and other
systems.
• Stallman is a pioneer of the free software concept
• He started the GNU Project (the name GNU
stands for GNU’s Not Unix), an attempt to create
an operating system and development
environment that would be compatible with UNIX
• But not suffer the restrictions of the proprietary
UNIX name and source code.
GNU Project and the Free Software Foundation
• A few major examples of software from the GNU
Project distributed under the GPL follow:
• GCC: The GNU Compiler Collection, containing the
GNU C compiler
• G++: A C++ compiler, included as part of GCC
• GDB: A source code–level debugger
• GNU make: A version of UNIX make
• Bison: A parser generator compatible with UNIX
yacc
• bash: A command shell
• GNU Emacs: A text editor and environment
LINUX - GNU General Public License
• The Linux community (together with others) supports the
concept of free software
• Software that is free from restrictions, subject to the GNU
General Public License.
• The GNU Project has already provided the software
community with many applications that closely mimic those
found on UNIX systems.
• All these programs, so-called GNU software, are distributed
under the terms of the GNU General Public License (GPL), a
copy of that may be found at http://www.gnu.org. This
license embodies the concept of copyleft (a takeoff on
“copyright”).
• Copyleft is intended to prevent others from placing
restrictions on the use of free software.
LINUX - GNU General Public License
• The GNU General Public License(GPL) is a free, copyleft license
for software and other kinds of works.
• The licenses for most software and other practical works are
designed to take away your freedom to share and change the
works.
• By contrast, the GNU General Public License is intended to
guarantee your freedom to share and change all versions of a
program--to make sure it remains free software for all its users.
• When we speak of free software, we are referring to freedom,
not price.
• Developers that use the GNU GPL protect your rights with two
steps: (1) assert copyright on the software, and (2) offer you
this License giving you legal permission to copy, distribute
and/or modify it.
LINUX – Other software - Opensource license
• Open source licenses are licenses that comply with the Open
Source Definition — in brief, they allow software to be freely
used, modified, and shared. To be approved by the Open
Source Initiative (also known as the OSI), a license must go
through the Open Source Initiative's license review process.
• Apache License 2.0
• BSD 3-Clause "New" or "Revised" license
• BSD 2-Clause "Simplified" or "FreeBSD" license
• GNU General Public License (GPL)
• GNU Library or "Lesser" General Public License (LGPL)
• MIT license
• Mozilla Public License 2.0
• Common Development and Distribution License
• Eclipse Public License
LINUX is a kernel
• Linux is actually just a kernel. You can obtain the
sources for the kernel to compile and install it and then
obtain and install many other freely distributed
software programs to make a complete Linux.
• Linux system from just source code is a major
undertaking.
• Fortunately, many people have put together
distributions (often called flavors), usually on CD-ROM,
that contain not just the kernel but also many other
programming tools and utilities.
• These often include an implementation of the X
Window System, a graphical environment common on
many UNIX systems.
LINUX is a kernel
• Linux is actually just a kernel. You can obtain the
sources for the kernel to compile and install it and then
obtain and install many other freely distributed
software programs to make a complete Linux.
• Linux system from just source code is a major
undertaking.
• Fortunately, many people have put together
distributions (often called flavors), usually on CD-ROM,
that contain not just the kernel but also many other
programming tools and utilities.
• These often include an implementation of the X
Window System, a graphical environment common on
many UNIX systems.
LINUX Distributions
• Linux is actually just a kernel. You can obtain the
sources for the kernel to compile and install it and then
obtain and install many other freely distributed
software programs to make a complete Linux.
• Linux system from just source code is a major
undertaking.
• Fortunately, many people have put together termed as
LINUX distributions (often called flavors), usually on
CD-ROM, that contain not just the kernel but also
many other programming tools and utilities.
• These often include an implementation of the X
Window System, a graphical environment common on
many UNIX systems.
LINUX Distributions
• The distributions usually come with a setup program and
additional documentation (normally all on the CD[s]) to
help you install your own Linux system.
• Some well-known distributions (particularly on the Intel x86
and Pentium families of processors) are Red Hat Linux, SuSE
Linux, and Debian GNU/Linux, but there are many others.
LINUX Distributions
• The distributions usually come with a setup program and
additional documentation (normally all on the
• CD[s]) to help you install your own Linux system. Some well-
known distributions (particularly on the
• Intel x86 and Pentium families of processors) are Red Hat Linux,
SuSE Linux, and Debian GNU/Linux, but there are many others.
LINUX Distributions-BOSS-Indian version–C-DAC
• The distributions usually come with a setup program and
additional documentation (normally all on the
• CD[s]) to help you install your own Linux system. Some well-
known distributions (particularly on the
• Intel x86 and Pentium families of processors) are Red Hat Linux,
SuSE Linux, and Debian GNU/Linux, but there are many others.
LINUX Distributions
• The distributions usually come with a setup program and
additional documentation (normally all on the
• CD[s]) to help you install your own Linux system. Some well-
known distributions (particularly on the
• Intel x86 and Pentium families of processors) are Red Hat Linux,
SuSE Linux, and Debian GNU/Linux, but there are many others.
LINUX Architecture
• Linux has two major layers kernel and shell
• Linux system from just source code is a major
undertaking.
• Fortunately, many people have put together
distributions (often called flavors), usually on
CD-ROM, that contain not just the kernel but
also many other programming tools and
utilities.
• These often include an implementation of the X
Window System, a graphical environment
common on many UNIX systems.
LINUX Architecture
• Hardware layer − Hardware consists of all
peripheral devices (RAM/ HDD/ CPU etc).
• Kernel − It is the core component of Operating
System, interacts directly with hardware, provides
low level services to upper layer components.
• 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.
• Utilities − Utility programs that provide the user
most of the functionalities of an operating systems.
LINUX Architecture
• The distributions usually come with a setup program and
additional documentation (normally all on the
• CD[s]) to help you install your own Linux system. Some well-
known distributions (particularly on the
• Intel x86 and Pentium families of processors) are Red Hat Linux,
SuSE Linux, and Debian GNU/Linux, but there are many others.
LINUX Features
• 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.
LINUX Features
• 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.
LINUX Commands
• The UNIX/LINUX system is command based.
• Grouped into 2 categories
• 1. Internal commands
• 2. External commands
LINUX Commands
• Internal commands:
• Commands which are built into the shell.
• Execution of the same is fast
• The shell doesn’t have to search the given path for them
in the PATH variable
• No process needs to be spawned for executing it.
• Eg: cd, fg
• External Commands :
• The shell looks for its path given in PATH variable
• A new process has to be spawned and the command
gets executed.
• They are usually located in /bin or /usr/bin
• Eg: ls, cat
LINUX Commands - Internal
$ help List internal commands
• Internal commands: 🡪 List of shell built-in commands can be obtained
GNU
usingbash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
help command:
These
• $shell help commands are defined internally. Type `help' to see this list.
A•starGNU (*) next
bash,toversion
a name5.0.3(1)-release
means that the(x86_64-pc-linux-gnu)
command is disabled.
job_spec
• These[&] shell commands are history
defined[-c]internally.
[-d offset] Type
[n] or`help'
hist> to see this
list.
(( expression )) if COMMANDS; then COMMANDS; [ elif C>
Type `help
. •filename name' to find out more
[arguments] about the
jobs [-lnprs] function
[jobspec `name'.
...] or jobs >
: • Use `info bash' to find outsigspec
kill [-s more about the shell
| -n signum in general.
| -sigs>
Use Use `man
• `man -k' or-k' or `info'
`info' to out
to find find more
out moreaboutabout commands
commands not innotthis
in this
list. list.
• A star (*) next to a name means that the command is disabled.
reak [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
• job_spec [&] history [-c] [-d offset] [n] or hist>
caller [expr] pwd [-LP]
• (( expression )) if COMMANDS; then COMMANDS; [ elif
caseC> WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [->
cd• [-L|[-P [-e]] [-@]]
. filename [dir]
[arguments] readarray
jobs [-d delim]
[-lnprs] [-n count]
[jobspec [-O
...] or > >
jobs
command
• : [-pVv] commandkill [arg[-s...]
sigspecreadonly [-aAf]
| -n signum [name[=value] ...] o>
| -sigs>
compgen [-abcdefgjksuv] [-o option] [> return [n]
LINUX Commands–Internal & External command
$ type cd type informs if a given command
• Internal commands: 🡪 List of shell built-in commands Is can
internal be obtained
command or external
cd is a shell builtin
using help command: Command. Shell builtin is internal
$ •type$ echo
help Command.
echo
• GNU is a shell
bash,builtin
version 5.0.3(1)-release (x86_64-pc-linux-gnu)
$ •type mkdir
These shell commands are defined internally. Type `help' to see this
mkdirlist.
is /usr/bin/mkdir
$ •typeType
rm `help name' to find out more about the type informs`name'.
function this command
external command as it displays
• Use `info
rm is /usr/bin/rm bash' to find out more about the shell in general.
the location of the command as
$ •typeUse `man -k' or `info' to find out more about
whatis commands not in this list.
/usr/bin/mkdir
• A star (*) next to a name means that the command is disabled.
whatis is hashed (/usr/bin/whatis)
$ whatis echo whatis - display one-line
• job_spec [&] history [-c] [-d offset]
manual[n]
pageordescriptions
hist>
echo (1) - display a line of text
• (( expression )) if COMMANDS; then COMMANDS; [ elif
$ whatis
C>
mkdir
mkdir
• . (1) - make directories
filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
mkdir
• : (2) - create a directory
kill [-s sigspec | -n signum | -sigs>
LINUX Commands–howto – man,info
$ man whatis Command to display manual pages using man
• Internal commands: 🡪 List of shell built-in commands can be obtained
WHATIS(1)
using help command: Manual pager utils WHATIS(1)
• $ help
NAME
• GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
• whatis
These -shell
display one-lineare
commands manual
definedpage descriptions
internally. Type `help' to see this
list.
• Type `help name' to find out more about the function `name'.
SYNOPSIS
Use `info
• whatis bash' to
[-dlv?V] find out
[-r|-w] [-s more about
list] [-m the shell[-M
system[,...]] in general.
path] [-L lo‐
Use `man
• cale] -k'name
[-C file] or `info'
... to find out more about commands not in this list.
• A star (*) next to a name means that the command is disabled.
DESCRIPTION
• job_spec [&] history [-c] [-d offset] [n] or hist>
Each manual page has a short description available within it. whatis
• (( expression )) if COMMANDS; then COMMANDS; [ elif
searches
C>
the manual page names and displays the manual page
descrip‐
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• tions
:
of any name matched.
kill [-s sigspec | -n signum | -sigs>
LINUX Commands–howto – man,info
$ info whatis Command to display manual pages Using info
• Internal commands: 🡪 List of shell built-in commands can be obtained
WHATIS(1)
using help command: Manual pager utils WHATIS(1)
• $ help
NAME
• GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
• whatis
These -shell
display one-lineare
commands manual
definedpage descriptions
internally. Type `help' to see this
list.
• Type `help name' to find out more about the function `name'.
SYNOPSIS
Use `info
• whatis bash' to
[-dlv?V] find out
[-r|-w] [-s more about
list] [-m the shell[-M
system[,...]] in general.
path] [-L lo‐
Use `man
• cale] -k'name
[-C file] or `info'
... to find out more about commands not in this list.
• A star (*) next to a name means that the command is disabled.
DESCRIPTION
• job_spec [&] history [-c] [-d offset] [n] or hist>
Each manual page has a short description available within it. whatis
• (( expression )) if COMMANDS; then COMMANDS; [ elif
searches
C>
the manual page names and displays the manual page
descrip tions of any name matched.
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
-----Info:
• : (*manpages*)whatis, 145 lines --Top----------------------------------
kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – General commands
$ passwd Command to change new passwd
• Internal commands: 🡪 List of shell built-in commands can be obtained
Changing
using helppassword
command: for gganesh.
(current)
• $ help UNIX password:
Enter
• GNU newbash,
UNIXversion
password: 5.0.3(1)-release (x86_64-pc-linux-gnu)
Retype
• These newshell
UNIXcommands
password:are defined internally. Type `help' to see this
passwd:list. password updated successfully
$ •cal Type `help name' to find outCommand more about the function
to display calendar`name'.
of current month
Use2019
• June `info bash' to find out more about the shell in general.
Su• Mo Use Tu`man
We Th-k'FrorSa
`info' to find out more about commands not in this list.
• A star (*) next to a name means that the command is disabled.
1
2 3 4 5 6 7 8
• job_spec [&] history [-c] [-d offset] [n] or hist>
9 10 11 12 13 14 15
• (( expression )) if COMMANDS; then COMMANDS; [ elif
16 17C>18 19 20 21 22
23• 24. 25 26 27 28
filename 29
[arguments] jobs [-lnprs] [jobspec ...] or jobs >
30• : kill [-s sigspec | -n signum | -sigs>
Each manual page has a short description available within it. whatis
LINUX Utilities – General commands
$ date Command to obtain current date
• Internal commands: 🡪 List of shell built-in commands can be obtained
Wed
usingJunhelp26command:
21:28:47 IST 2019
Syntax:
• $ help date [OPTION]... [+FORMAT]
• %aGNU locale's abbreviated
bash, version weekday name
5.0.3(1)-release (e.g., Sun)
(x86_64-pc-linux-gnu)
• %ATheselocale's full weekday
shell commands arename
defined(e.g., Sunday)Type `help' to see this
internally.
list. locale's abbreviated month name (e.g., Jan)
%b
• %BType locale's
`help name' to findname
full month out more
(e.g.,about the function `name'.
January)
• %cUse `info bash'
locale's dateto and
find time
out more
(e.g.,about
Thu Mar the shell in general.
3 23:05:25 2005)
• %CUse `man -k' orlike
century; `info'
%Y,to find out
except omitmore
last about commands
two digits not in this list.
(e.g., 20)
• A star (*) next to a name means that the command is disabled.
%d day of month (e.g., 01)
%H hour (00..23)
• job_spec [&] history [-c] [-d offset] [n] or hist>
%I hour (01..12)
• (( expression )) if COMMANDS; then COMMANDS; [ elif
%m
C>
month (01..12)
• %M minute
. filename (00..59)
[arguments] jobs [-lnprs] [jobspec ...] or jobs >
• %S : second (00..60) kill [-s sigspec %Y year | -n signum | -sigs>
LINUX Utilities – General commands
$ x=5 Command to assign a value to the variable
• Internal commands: 🡪 List of shell built-in commands can be obtained
$ echo "Hello world" Command to display given message
using help command:
Hello world
• $ help
$ •echo $x Command to display the value of the variable
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
5 • These shell commands are defined internally. Type `help' to see this
$ echolist.'Value of x is $x'
Single quotes display the message as it is
Value of x is $x
• Type `help name' to find out more about the function `name'.
$ •echo
Use "Value of x isto
`info bash' $x"
find out more Double
aboutquotes substitutes
the shell the variable value in msg
in general.
• Use of x`manis 5 -k' or `info'printf
to find out more about commands not in this
Value displays message using format specifiers as inlist.
c
A star
$ •printf "The(*)value
next toofa255
name means
is %o thatand
in octal the%x
command is disabled.
in hexadec1mal \n" 255 255
The value of 255 is 377 in octal and ff in hexadec1mal
$ •bc job_spec [&] calculator
history [-c] [-d offset] [n] or hist>
• (( expression ))
5+4 if COMMANDS; then COMMANDS; [ elif
C>
9
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
quit
• : kill [-s sigspec | -n signum | -sigs>
$
LINUX Utilities – General commands
$ whoami
• Internal commands: 🡪 List of shell built-in commands can be obtained
gganesh
using help command: Command to display the list of all user currently
$ •who$ help logged in
gganesh
• GNU:0 2019-06-26
bash, version 07:48 (:0) (x86_64-pc-linux-gnu)
5.0.3(1)-release
$ •clear Command
These shell commands are defined to clear the
internally. screen
Type `help' to see this
list.
• Type `help name' to find out more about the function `name'.
• Use `info bash' to find out more about the shell in general.
• Use `man -k' or `info' to find out more about commands not in this list.
• A star (*) next to a name means that the command is disabled.
• job_spec [&] history [-c] [-d offset] [n] or hist>
• (( expression )) if COMMANDS; then COMMANDS; [ elif
C>
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – General commands
$ uname -a Command to print all system information
• Internal commands: 🡪 List of shell built-in commands can be obtained
Linux gganesh-VirtualBox 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17
using help command:
15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
• $ help
-s, --kernel-name print the kernel name 🡺 Linux
• GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
-n, --nodename print the network node hostname🡺gganesh-VirtualBox
• These shell commands are defined internally. Type `help' to see this
-r, --kernel-release
list. print the kernel release 🡺 4.15.0-29-generic
-v,• --kernel-version
Type `help name' print the out
to find kernel
moreversion
about🡺the
#31-Ubuntu SMP Tue Jul 17
function `name'.
• 15:39:52
Use `infoUTC 2018
bash' to find out more about the shell in general.
-m,
• --machine
Use `man -k' orprint
`info'the machine
to find hardware
out more aboutname 🡺 x86_64
commands not in this list.
-p,• --processor
A star (*) next print the processor
to a name type
means that the(non-portable) 🡺 x86_64
command is disabled.
$ •tty job_spec [&] Commandhistory
to print[-c] [-d offset]
filename of the[n] or hist>
terminal (teletype)
/dev/pts/1
• (( expression )) if COMMANDS; then COMMANDS; [ elif
C>
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
• A directory is used to store, organize, and
separate files and directories on a computer.
• For example, you could have a directory to
store pictures and another directory to store all
your documents.
• By storing specific types of files in a folder, you
could quickly get to the type of file you wanted
to view. In other words, if only pictures were in
a pictures directory, it's easier to find a picture
than a directory containing all types of files.
LINUX Utilities – File Handling
• A directory is a location for storing files on
your computer. Directories are found in a
hierarchical file system, such as Linux, MS-
DOS, OS/2, and Unix.
• Below is an example of what a directory path
would look like in MS-DOS.
LINUX Utilities – File Handling
• Below is an example of what a directory path
may look like in a Linux or Unix variant.
• It is maintained by the Linux Foundation.
• The latest version is 3.0, released on 3 June
• In the above example, the current directory is
bin, and it is a subdirectory of the usr directory.
• The beginning forward slash is the root directory.
• usr is parent directory.
Directory Files
LINUX Utilities – File Handling
• Below is an example of what a directory path
may look like in a Linux or Unix variant.
• It is maintained by the Linux Foundation.
• The latest version is 3.0, released on 3 June
• In the above example, the current directory is
bin, and it is a subdirectory of the usr directory.
• The beginning forward slash is the root directory.
• usr is parent directory.
LINUX Utilities – File Handling
• The Filesystem Hierarchy Standard (FHS)
defines the directory structure and directory
contents in Linux distributions.
• It is maintained by the Linux Foundation.
• The latest version is 3.0, released on 3 June
2015.
LINUX Utilities – File Handling -FHS
• The Filesystem Hierarchy Standard (FHS)
defines the directory structure and directory
contents in Linux distributions. It is maintained
by the Linux Foundation. The latest version is
3.0, released on 3 June 2015.
LINUX Utilities – File Handling -FHS
• The Filesystem Hierarchy Standard (FHS)
defines the directory structure and directory
contents in Linux distributions. It is maintained
by the Linux Foundation. The latest version is
3.0, released on 3 June 2015.
LINUX Utilities – File Handling
• The file is a container for storing information. it
simply as a sequence of characters.
• If you name a file foo and write three characters
it, a,b and c into it, then foo will contain only the
string abc and nothing else
• UNIX treats directories and devices as files as
well. A directory is simply a folder where you
store filenames and other directories.
• All physical devices like the hard disk, memory,
CD-ROM, printer and modem are treated as files.
• The shell is also a file, and so is the kernel
LINUX Utilities – File Handling – File Types
• UNIX/LINUX divides files into three categories:
• Ordinary file—Also known as regularfile. It
contains only data as a stream of characters.
• Directory file—lt's commonly said that a
directory contains files and other directories,
but strictly speaking, it contains their name:
and a number associated with each name.
• Device file—All devices and peripherals are
represented by files. To read or write a device,
you have to perform these operations on its
associated file
LINUX Utilities – File Handling – File Types
• An ordinary file itself can be divided into two
types:
• 1. Text file contains only printable characters
• 2. Binary file contains both printable and
unprintable characters that cover the entire ASCII
range (0 to 255) ;
• UNIX/LINUX commands are binary files,
• Object code and executables that you produce
by compiling C programs are also binary files.
• Picture, sound and video files are binary files
as well
LINUX Utilities – File Handling
┌──(kali ㉿ kali)-[~] Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
└─$ ls help command:
using
Desktop
• $ help Documents Downloads hello.c hello.o index.html ipfind.py
• Music
GNUPictures Public5.0.3(1)-release
bash, version Templates Videos (x86_64-pc-linux-gnu)
┌──(kali
• These ㉿ kali)-[~]
shell commands are defined internally. Type `help' to see this
Command to list directory contents – long listing
└─$ lslist.
-l
total
• 60 Type `help name' to find out more about the function `name'.
• Use `info
drwxr-xr-x 2 kalibash' to findJan
kali 4096 out8more
10:13about the shell in general.
Desktop
• Use `man
drwxr-xr-x 2 kali-k'
kalior4096
`info'Jan
to find out more
8 10:13 about commands not in this
Documents
list. 2 kali kali 4096 Feb 22 00:36 Downloads
drwxr-xr-x
• A star
-rw-r--r-- (*) kali
1 kali next to70aFeb
name meanshello.c
6 10:04 that the command is disabled.
-rwxr-xr-x 1 kali kali 15952 Feb 6 10:04 hello.o
• job_spec [&] history [-c] [-d offset] [n] or hist>
-rw-r--r-- 1 kali kali 1285 Jan 23 11:41 index.html
• (( expression )) if COMMANDS; then COMMANDS; [ elif
-rw-r--r-- 1 kali kali 95 Feb 10 02:20 ipfind.py
C>
drwxr-xr-x 2 kali kali
• . filename 4096 Jan 8 10:13 Music
[arguments] jobs [-lnprs] [jobspec ...] or jobs >
drwxr-xr-x
• : 2 kali kali 4096 Jankill8[-s10:13 Pictures
sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
• To make a directory in MS-DOS, Linux, Unix, and
most other command line operating systems, use
the "mkdir" command. ex mkdir mydir
• To change a directory in MS-DOS, Linux, Unix, and
most other command line operating systems, use
the "cd" command. ex. cd mydir
• To remove a directory in MS-DOS,Linux/Unix, use
the "rmdir" command. In Linux and Unix, use the
"rm -r" command. ex. rmdir
• To know the current directory location in
Linux/Unix used ‘pwd’ (present working
directory)command
LINUX Utilities – File Handling
• To create an empty file Linux, Unix, use the "touch" command.
eg. touch “myfile.txt”
• To create an non-empty file Linux, Unix, use the "cat>"
command. eg. cat > hello.txt followed by text content and end
by ctrl+d.
• To remove a file in Linux/Unix, use the "rm" command. In Linux
and Unix, use the "rm -r" command. eg rm hello.txt will
remove the file hello.txt
• To copy a file in Linux/Unix use ‘cp orig-filename new-filename’.
cp hello.txt hello1.txt will create a new copy of file hello1.txt
• To move a file in Linux/Unix use ‘mv orig-filename new-
filename’. mv hello.txt hello1.txt will rename the file to
hello1.txt. mv hello.txt /dir1/ will move the file to the new
location dir1
LINUX Utilities – File Handling
• The . is same as saying "current directory".
So ./script means execute script file in current
directory.
• The .. is same as saying "parent directory"
(one directory up).
• The tilde ( ~ ) represents the home directory
of the currently logged in user.
LINUX Utilities – File Handling
Command to know the current working directory
• Internal commands: 🡪 List of shell built-in commands can be obtained
using help command:
┌──(kali• ㉿ kali)-[~]
$ help
└─$ pwd• GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
/home/kali
• These shell commands are defined internally. Type `help' to see this
list.
• Type `help name' to find out more about the function `name'.
• Use `info bash' to find out more about the shell in general.
• Use `man -k' or `info' to find out more about commands not in this
list.
• A star (*) next to a name means that the command is disabled.
• job_spec [&] history [-c] [-d offset] [n] or hist>
• (( expression )) if COMMANDS; then COMMANDS; [ elif
C>
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
┌──(kali
using help㉿ kali)-[~]
command:
└─$• ls $ help
Desktop
• GNUDocuments Downloads
bash, version hello.c (x86_64-pc-linux-gnu)
5.0.3(1)-release hello.o index.html ipfind.py
• Music
These Pictures Public Templates
shell commands are defined Videos
internally. Type `help' to see this
list.
• Type `help name' to find out Command to create a directory
more about the function `name'.
┌──(kali
• Use㉿ `info
kali)-[~]
bash' to find out more about the shell in general.
└─$• mkdir test -k' or `info' to find
Use `man out more
Command about
to list commands
directory contentsnot in this
list. Now test directory is created
• A star (*) next to a name means that the command is disabled.
┌──(kali ㉿ kali)-[~]
└─$• ls job_spec [&] history [-c] [-d offset] [n] or hist>
• (( expression
Desktop Documents)) Downloads hello.c if COMMANDS; then COMMANDS;
hello.o index.html ipfind.py[ elif
C> Pictures Public Templates test Videos
Music
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
┌──(kali
using help㉿ kali)-[~]
command:
└─$• ls $ help
Desktop
• GNUDocuments Downloads
bash, version hello.c (x86_64-pc-linux-gnu)
5.0.3(1)-release hello.o index.html ipfind.py
• Music
These Pictures Public Templates
shell commands are defined testinternally.
Videos Type `help' to see this
list.
• Type `help name' to find out Command to remove a directory
more about the function `name'.
┌──(kali
• Use㉿ `info
kali)-[~]
bash' to find out more about the shell in general.
└─$• rmdir test -k' or `info' to find
Use `man out more
Command about
to list commands
directory contentsnot in this
list. Now test directory is removed
• A star (*) next to a name means that the command is disabled.
┌──(kali ㉿ kali)-[~]
└─$• ls job_spec [&] history [-c] [-d offset] [n] or hist>
• (( expression
Desktop Documents)) Downloads hello.c if COMMANDS; then COMMANDS;
hello.o index.html ipfind.py[ elif
C> Pictures Public Templates Videos
Music
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
┌──(kali ㉿ kali)-[~] Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
└─$ ls help command:
using
Desktop
• $ helpDocuments Downloads hello.c hello.o index.html ipfind.py
• Music
GNUPictures Public5.0.3(1)-release
bash, version Templates Videos
(x86_64-pc-linux-gnu)
• These shell commands areCommand defined internally. Type `help' to see this
to create a directory
list.
┌──(kali
• Type ㉿ kali)-[~]
`help name' to find out more about the function `name'.
└─$
• mkdir test bash' to find outCommand
Use `info more aboutto list
thedirectory
shell incontents
general.
Now test directory is created
• Use `man -k' or `info' to find out more about commands not in this
list.
• A star
┌──(kali (*) next to a name means that the command is disabled.
㉿ kali)-[~]
└─$ ls
• job_spec
Desktop [&] Downloads hello.c
Documents history hello.o
[-c] [-d offset] [n] oripfind.py
index.html hist>
• Music
(( expression ))
Pictures Public Templates if COMMANDS;
test Video then COMMANDS; [ elif
C> Current directory is now test
• . filename
┌──(kali ㉿ kali)-[~][arguments] jobs [-lnprs] [jobspec ...] or jobs >
• cd: test
└─$ kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling
Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
┌──(kali
using help ㉿ kali)-[~]
command:
└─$• ls $ help
Desktop
• GNUDocuments Downloads
bash, version hello.c (x86_64-pc-linux-gnu)
5.0.3(1)-release hello.o index.html ipfind.py
• Music
These Pictures Public Templates
shell commands are defined testinternally.
Videos Type `help' to see this
┌──(kali ㉿ list.
kali)-[~]
Command to create a new file
└─$ cat• > greet.txt
Type `help name' to find out more about the function `name'.
• Use `info bash' to find out more about the shell in general.
Hello world
• Use `man -k' or `info' to find Command to list directory contents
out more about commands not in this
Now greet.txt file is created
┌──(kali ㉿ list.
kali)-[~]
└─$ ls • A star (*) next to a name means that the command is disabled.
Desktop Documents Downloads greet.txt hello.c hello.o index.html ipfind.py
Music •Pictures
job_spec [&]Templates test history
Public Videos [-c] [-d offset] [n] or hist>
• (( expression )) Command toif display the contents
COMMANDS; thenofCOMMANDS;
the file [ elif
C> greet.txt
┌──(kali• ㉿ kali)-[~]
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
└─$ cat greet.txt
LINUX Utilities – File Handling -vi
$ ls Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
Desktop
using helpDownloads
command: Music Public Videos
Documents
• $ help examples.desktop Pictures Templates
$ •ls -lGNU bash, version 5.0.3(1)-release
Command to(x86_64-pc-linux-gnu)
list directory contents – long listing
total
• These44 shell commands are defined internally. Type `help' to see this
list. 2 gganesh gganesh 4096 Sep 11 2018 Desktop
drwxr-xr-x
• Type `help
drwxr-xr-x name'gganesh
2 gganesh to find out more
4096 Sepabout
11 2018 the Documents
function `name'.
• Use `info
drwxr-xr-x bash' togganesh
2 gganesh find out4096
moreSepabout
11 the2018 shell in general.
Downloads
• Use `man
-rw-r--r-- -k' or gganesh
1 gganesh `info' to find
8980outSepmore aboutexamples.desktop
11 2018 commands not in this list.
• A star (*) next to a name means that the command is disabled.
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Music
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Pictures
• job_spec [&] history [-c] [-d offset] [n] or hist>
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Public
• (( expression )) if COMMANDS; then COMMANDS; [ elif
drwxr-xr-x
C>
2 gganesh gganesh 4096 Sep 11 2018 Templates
drwxr-xr-x
• . filename2 gganesh gganesh 4096 Sep
[arguments] 11[-lnprs]
jobs 2018 Videos
[jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling -vi
$ ls Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
Desktop
using helpDownloads
command: Music Public Videos
Documents
• $ help examples.desktop Pictures Templates
$ •ls -lGNU bash, version 5.0.3(1)-release
Command to(x86_64-pc-linux-gnu)
list directory contents – long listing
total
• These44 shell commands are defined internally. Type `help' to see this
list. 2 gganesh gganesh 4096 Sep 11 2018 Desktop
drwxr-xr-x
• Type `help
drwxr-xr-x name'gganesh
2 gganesh to find out more
4096 Sepabout
11 2018 the Documents
function `name'.
• Use `info
drwxr-xr-x bash' togganesh
2 gganesh find out4096
moreSepabout
11 the2018 shell in general.
Downloads
• Use `man
-rw-r--r-- -k' or gganesh
1 gganesh `info' to find
8980outSepmore aboutexamples.desktop
11 2018 commands not in this list.
• A star (*) next to a name means that the command is disabled.
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Music
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Pictures
• job_spec [&] history [-c] [-d offset] [n] or hist>
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Public
• (( expression )) if COMMANDS; then COMMANDS; [ elif
drwxr-xr-x
C>
2 gganesh gganesh 4096 Sep 11 2018 Templates
drwxr-xr-x
• . filename2 gganesh gganesh 4096 Sep
[arguments] 11[-lnprs]
jobs 2018 Videos
[jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling -vi
$ ls Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
Desktop
using helpDownloads
command: Music Public Videos
Documents
• $ help examples.desktop Pictures Templates
$ •ls -lGNU bash, version 5.0.3(1)-release
Command to(x86_64-pc-linux-gnu)
list directory contents – long listing
total
• These44 shell commands are defined internally. Type `help' to see this
list. 2 gganesh gganesh 4096 Sep 11 2018 Desktop
drwxr-xr-x
• Type `help
drwxr-xr-x name'gganesh
2 gganesh to find out more
4096 Sepabout
11 2018 the Documents
function `name'.
• Use `info
drwxr-xr-x bash' togganesh
2 gganesh find out4096
moreSepabout
11 the2018 shell in general.
Downloads
• Use `man
-rw-r--r-- -k' or gganesh
1 gganesh `info' to find
8980outSepmore aboutexamples.desktop
11 2018 commands not in this list.
• A star (*) next to a name means that the command is disabled.
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Music
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Pictures
• job_spec [&] history [-c] [-d offset] [n] or hist>
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Public
• (( expression )) if COMMANDS; then COMMANDS; [ elif
drwxr-xr-x
C>
2 gganesh gganesh 4096 Sep 11 2018 Templates
drwxr-xr-x
• . filename2 gganesh gganesh 4096 Sep
[arguments] 11[-lnprs]
jobs 2018 Videos
[jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File Handling -vi
$ ls Command to list directory contents
• Internal commands: 🡪 List of shell built-in commands can be obtained
Desktop
using helpDownloads
command: Music Public Videos
Documents
• $ help examples.desktop Pictures Templates
$ •ls -lGNU bash, version 5.0.3(1)-release
Command to(x86_64-pc-linux-gnu)
list directory contents – long listing
total
• These44 shell commands are defined internally. Type `help' to see this
list. 2 gganesh gganesh 4096 Sep 11 2018 Desktop
drwxr-xr-x
• Type `help
drwxr-xr-x name'gganesh
2 gganesh to find out more
4096 Sepabout
11 2018 the Documents
function `name'.
• Use `info
drwxr-xr-x bash' togganesh
2 gganesh find out4096
moreSepabout
11 the2018 shell in general.
Downloads
• Use `man
-rw-r--r-- -k' or gganesh
1 gganesh `info' to find
8980outSepmore aboutexamples.desktop
11 2018 commands not in this list.
• A star (*) next to a name means that the command is disabled.
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Music
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Pictures
• job_spec [&] history [-c] [-d offset] [n] or hist>
drwxr-xr-x 2 gganesh gganesh 4096 Sep 11 2018 Public
• (( expression )) if COMMANDS; then COMMANDS; [ elif
drwxr-xr-x
C>
2 gganesh gganesh 4096 Sep 11 2018 Templates
drwxr-xr-x
• . filename2 gganesh gganesh 4096 Sep
[arguments] 11[-lnprs]
jobs 2018 Videos
[jobspec ...] or jobs >
• : kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File - Ownership
• Every file and directory in your UNIX/Linux system has following 3
permissions defined for all the 3 owners discussed above.
• Read: This permission give you the authority to open and read a file.
Read permission on a directory gives you the ability to lists its content.
• Write: The write permission gives you the authority to modify the
contents of a file. The write permission on a directory gives you the
authority to add, remove and rename files stored in the directory.
Consider a scenario where you have to write permission on file but do
not have write permission on the directory where the file is stored.
You will be able to modify the file contents. But you will not be able to
rename, move or remove the file from the directory.
• Execute: In Windows, an executable program usually has an extension
".exe" and which you can easily run. In Unix/Linux, you cannot run a
program unless the execute permission is set. If the execute
permission is not set, you might still be able to see/modify the
program code(provided read & write permissions are set), but not run
it.
LINUX Utilities – File - Ownership
• Every file and directory on your Unix/Linux system is assigned 3 types of
owner, given below.
• User
• A user is the owner of the file. By default, the person who created a file
becomes its owner. Hence, a user is also sometimes called an owner.
• Group
• A user- group can contain multiple users. All users belonging to a group
will have the same access permissions to the file. Suppose you have a
project where a number of people require access to a file. Instead of
manually assigning permissions to each user, you could add all users to a
group, and assign group permission to file such that only this group
members and no one else can read or modify the files.
• Other
• Any other user who has access to a file. This person has neither created
the file, nor he belongs to a usergroup who could own the file.
Practically, it means everybody else. Hence, when you set the permission
for others, it is also referred as set permissions for the world.
LINUX Utilities – File - Ownership
r = read permission
w = write permission
x = execute permission
- = no permission
LINUX Utilities – File - Ownership
• Changing file/directory permissions with
'chmod' command
• Syntax: chmod permissions filename
• There are 2 ways to use the command -
• Absolute mode
• Symbolic mode
LINUX Utilities – File - Ownership
• Symbolic Mode
• The command you use to change the security permissions on
files is called “chmod”, which stands for “change mode”
• The first argument you give to the “chmod” command is ‘u’, ‘g’,
‘o’. We use: u for user g for group o for others,
• Operator Description:+ Adds a permission to a file or directory,
-Removes the permission= Sets the permission and overrides
the permissions set earlier.
• Permissions are read, write or execute r,w or x you want to
change.
• Eg: chmod o+x xyz.txt 🡺 to give “execute” permission to the
world (“other”) for file “xyz.txt”
• chmod ug+rw,o-x abc.mp4 🡺 adds read(r) and write(w)
permission to both user(u) and group(g) and revoke execute(x)
permission from others(o) for the file abc.mp4
LINUX Utilities – File - Ownership
LINUX Utilities – File - Ownership
4=r , 2 = w, 1 = x
chmod 777 file1 🡺 chmod ugo+rwx file1
chmod 435 file1 🡺 chmod u=r,g=wx,o=rx file1
chmod –R 777 . 🡺 Apply chmod recursively
LINUX Utilities – File - Ownership
• chown
• chown command is used to change the owner /
user of the file or directory. This is an admin
command, root user only can change the owner
of a file or directory.
• Syntax:chown [options] newowner
filename/directoryname
• Eg:chown hiox test.txt
• The owner of the 'test.txt' file is root, Change to
new user hiox.
• Eg: chown –R /dir1 🡺 Apply chown recursively
LINUX Utilities – File - Ownership
• chgrp
• chgrp command is used to change the group of the
file or directory. This is an admin command. Root user
only can change the group of the file or directory.
• The Syntax is
• chgrp [options] newgroup filename/directoryname
• Eg:chgrp hiox test.txt
• The group of 'test.txt' file is root, Change to newgroup
hiox.
• chgrp -R hiox test 🡺 Apply chgrp recursively
• The group of 'test' directory is root. With -R, the files
and its subdirectories also changes to newgroup hiox.
LINUX Utilities – File - Link
• Soft Link and Hard Link
• A link in UNIX is a pointer to a file.
• Creating links is a kind of shortcuts to access a
file.
• Links allow more than one file name to refer
to the same file, elsewhere.
• There are two types of links :
• 1.Soft Link or Symbolic links
• 2.Hard Links
LINUX Utilities – File - Link
• 1. Hard Links
• Each hard linked file is assigned the same Inode value as the
original, therefore they reference the same physical file
location. Hard links more flexible and remain linked even if the
original or linked files are moved throughout the file system,
although hard links are unable to cross different file systems
• Hard Links have actual file contents
• Removing any link, just reduces the link count, but doesn’t
affect other links.
• We cannot create a hard link for a directory to avoid recursive
loops.
• If original file is removed then the link will still show the
content of the file.
• $ ln [original filename] [link name]
LINUX Utilities – File Handling -Link
ln [options] existingfile(or directory)name newfile(or directory)name
• Internal commands: 🡪 List of shell built-in commands can be obtained
$using
cat file1
help command: Hard link created with file2 for file1
hello
• $world help
this
• isGNUmy world
bash, version
Notice5.0.3(1)-release
both file has same(x86_64-pc-linux-gnu)
inode value
$ •ln file1
These file2
shell commands are defined internally. Type `help' to see this
$ ls –llist.
• Type
544729 `help name'
-rw-r--r-- to findgganesh
2 gganesh out more29 about
Jul 1the function
23:57 file1 `name'.
• Use-rw-r--r--
544729 `info bash' to find out
2 gganesh more about
gganesh 29 Julthe shell infile2
1 23:57 general.
$ •catUse
file2`man -k' or `info' to find out more about commands not in this list.
• A star (*) next to a name means that the command is disabled.
hello world
this is my world Even after original file deleted linked file
• job_spec [&] history
contents still exists[-c] [-d offset] [n] or hist>
$ rm file1
• (( expression )) if COMMANDS; then COMMANDS; [ elif
$ catC> file2
hello
• .worldfilename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
this
• is: my world kill [-s sigspec | -n signum | -sigs>
LINUX Utilities – File - Link
• 2. Soft Links
• A soft link is similar to the file shortcut feature which is used in
Windows Operating systems. Each soft linked file contains a
separate Inode value that points to the original file. As similar to
hard links, any changes to the data in either file is reflected in the
other. Soft links can be linked across different file systems
• ls -l command shows all links with first column value l? and the
link points to original file.
• Soft Link contains the path for original file and not the contents.
• Removing soft link doesn’t affect anything but removing original
file, the link becomes “dangling” link which points to nonexistent
file.
• A soft link can link to a directory.
• $ ln -s [original filename] [link name]
LINUX Utilities – File Handling - Link
$ ln -s file1 file3
• Internal commands: 🡪 List of shell built-in commands can be obtained
$ cat file3
using help command:
hello world
• $ help Soft link created with file3 for file1
this is my world
• GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
$ •ls –lThese shell commands are defined internally. Type `help' to see this
544729 list.-rw-r--r-- 2 gganesh gganesh 29 Jul 1 23:57 file1
545053
• Type lrwxrwxrwx
`help name' 1 gganesh
to find outgganesh
more about 5 Julthe
2 00:00
functionfile3 -> file1
`name'.
$ •rm Use
file1`info bash' to find out more about the shell in general.
Notice l in the file permissions indicating the type of the file
• Use
hello `man -k' or `info'
world Noticetodifferent
find outinode
morenumbers
about commands
for file1 andnot
file3in this list.
• isA my
this starworld
(*) next to a name means that the command is disabled.
After removing the original file linked file does not exist
$ ls –l and become dangling pointer(nothing to point)
• job_spec
-rw-r--r-- [&] gganesh 29 Jul
1 gganesh history [-c] [-d
1 08:13 offset] [n] or hist>
file2
• (( expression
lrwxrwxrwx )) gganesh if5 COMMANDS;
1 gganesh then
Jul 1 23:43 file3 ->COMMANDS;
file1 [ elif
C>
$ cat file3
• . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
cat: file3: No such file or directory
• : kill [-s sigspec | -n signum | -sigs>
Questions