SlideShare a Scribd company logo
Utilities
Checking your Current Directory
pwd (Present Working Directory)
Displays the directory you are currently
placed in.
Example:
$ pwd
/usr/nimal
Output
Note:
pwd displays the absolute path name.
Changing Directory
cd [directory name]
Changes the current directory to the directory
specified as the argument.
Example 1:
$ cd test
$ pwd
/usr/nimal/test
Example 2
If you need to switch to /bin:
$ cd /bin
• The command cd without an argument
switches to the home directory.
• cd .. - Moves you to the next higher level
subdirectory.
Listing the Directory Contents
ls [options] [file list]
Shows all the files in the current directory.
Options
-a All entries (hidden files, . and .. are displayed).
-x Displays multicolumn.
-F Marks executable files with * and directories
with / .
-l Long listing showing 7 attributed.
Example:
$ ls –a
$ ls –l test
Utility
Option
File name
Displaying and Creating Files
Displaying the contents of a file
cat [Option] [file names]
Options:
-n Line numbers
-b Omit line numbers on blank lines used
with –n option
-S Single space. Reduce multiple adjacent
empty lines to a single blank line
Example:
$ cat test1 test2 test3
If you want to view files one after the other,
you can use more utility in place of cat. The
more utility pauses after displaying the
content of a file.
$ more [file names]
Creating a file
The command cat can also be used for
creating a file.
$ cat > abc
…….
……..
…….
[control + d]
Making a Directory
mkdir [option] [directory names]
Option
-p (parent) – If the parent directory of the
directory you are creating does
not exists.
Example 1
$ mkdir test
Example 2
$ mkdir test test/test1 test/test2
Example 3
$ mkdir –p memo/letter
Parent directory
Parent directory
Deleting a File
rm [file names]
Example
$ rm abc
Removing a Directory
rmdir [directory names]
Example
$ rmdir test1 test2
Note:
You cannot remove the working directory or a
directory that contains files and
subdirectories.
File Permissions
Three types of users can access a file.
• Owner – (read, write, execute)
• Group - (read, write, execute)
• Other - (read, write, execute)
There are a total of nine possible ways to
access a file. All these permissions take the
general form:
- r w x r w x r w x
r indicates read permission. w indicates
writes permission and x indicates execute
permission. (ie. The file can be executed as a
program). If any of these permissions don’t
apply to a specific category, then a hyphen
(-) will occupy the respective slot.
- r w x r w x r w x
d : Directory
- : Ordinary file
b/c : I/O device
User (owner)
Group
Others
Note:
For a directory file:
• Read – read the directory (ls)
• Write – create, move, copy, remove a
directory
• Execute– search the directory (cd)
_ r w _ r_ _ r_ _ 1 mala prog 245 May 20 10:15 myfile
1- the file has only one link
mala – The file is owned by Mala
prog – The file belongs to the group prog
245 – File size
May 20 10:15 - Last modified at this time
myfile – The name of the file is myfile
• Note:
Your home directory comes with the following
default permissions set by the system
administrator:
d r w x - - - - - -
These permissions will also be acquired by
any sub directories you create.
Changing Access Permissions
chmod [Category] [Operation] [Permission][Filename]
Category Operation Permission
u- user + : assign
permission
r- read permission
g- group - : remove
permission
w- write permission
o – others x – execute
permission
a- all
Example
$ chmod u +x test
$ ls –l test
- r w x r - - r - -
Examples
1. Assign all categories execute permission, for the
file abc.
2. Remove the read permission of the group and
others of the file test.
3. Remove execute permission of the user and assign
read permission to the group and others of the file
xyz.
4. Assign write and execute permission for the others
in file memo.
Octal Notation –Changing Access
Permission using mode number
$ chmod [mode] [file names]
chmod also takes a numeric argument that
describes both the category as well as the
permission described in the above section.
Read permission is assigned the value: 4
Write : 2
Execute : 1
If a file has read and write permission for the
owner, then according to the above notation:
4 +2 = 6
Example
$ chmod 666 report
$ ls- l report
- r w – r w – r w -
Example:
$ ls -l memo
d r w x r – x r - - 1 nimal mine 20 Feb 12 21:14 memo
1. According to the output shown above, is
memo a file ?
2. Does the group have execute permission?
3. How can you give the others write permission?
Copying a File
cp [options] [source file] [destination file]
Creates an exact image of the file on disk
with a different name.
If the destination file does not exists, it will
be first created before the copying takes
place. Else, the file will be overwritten.
Option
-i (interactive): Warns the user before
overwriting the destination file
Example
$ cp abc xyz
$ cp -i abc xyz
Renaming Files/Directories
mv [option] [existing file name] [new file name]
mv [option] [existing dir name] [new dir name]
The mv command renames a file/directory. The
command does not create a copy of the file. It
just renames the file. If the destination file
exists, then it will be overwritten.
Option
-i (interactive): Warns the user before
overwriting the destination file
Example
$ mv memo letter
Moving a file
mv can be used to move a group of files to a
directory.
Example
$ mv test1 test2 test3 test4 test
Directory
These could be files, directories or both
Printing a File
lpr [options] [file names]
Example
$ lpr report memo letter
lpq – provides status information about jobs
currently in the printer queue.
lprm – removes files from the queue.
Option:
-h : Skip printing the header page with your
login name.
Removing duplicate lines
$ uniq [option] [file name]
Option Description
-c Count each line with number of
occurrences
-d Duplicated lines, display only lines
that are repeated
-u Unique lines, display only lines that
are not repeated
Example:
$ cat sample
abc
abc
xyz
pqr
pqr
pqr
Lines repeated
Lines repeated
1. $ uniq sample
abc
xyz
pqr
2. $ uniq –c sample
2 abc
1 xyz
3 pqr
No. of
repetitions
3. $ uniq –d sample
abc
pqr
4. $ uniq –u sample
xyz
Only the lines that were duplicated
will be displayed
Only the lines that were not
Duplicated will be displayed
Comparing Two Files
cmp command can be used to find out
whether two files are identical in all respect
so that one of them can be deleted.
Example:
$ cmp test1 test2
test1 test2 differ: char 10, line 5
$_
The two files will be compared byte by byte
and the location of the first mismatch will be
displayed on the screen. When the command
is used without options, it does not bother
about possible subsequent mismatches, but
will abort with the message shown above. If
the two files are identical, them cmp will
display no message.
-l option
Example:
$ cat memo1
abc
xyz
$ cat memo2
abe
wxy
$ cmp –l memo1 memo2
3 143 145
5 170 167
6 171 170
7 172 171
Character number
Octal representation
of characters
Example:
The file grocery_list consists of four fields. The
fields are: item, supplier, supplier address and
price/unit.
Item Supplier Address Price/unit
Sugar Sweetprod Ltd Kandy 45.00
Butter SLExporters Colombo 135.00
Carrots ABCFarms.Ltd Nawalapitiya 90.00
a. How can you create the file grocery_list?
b. How can you create a copy of the file grocery_list with name
grocery?
c. How can you tell whether the file grocery_list is the same as
the file grocery?
d. How can you see the grocery_list entries that are repeated?
e. What is the command to print the file grocery_list
f. What is the command to count the number of lines of the file
grocery_list
g. What is the command to view the details of the file grocery
page by page
h. What is the command to create the parent directory STORE
and two sub directories S1 and S2
i. How can you move the files grocery_list and grocery to the
directory STORE
j. How can you confirm that the two files has been moved to
the directory STORE?
k. What is the command to rename the file grocery_list to
grocery?
l. How can you move to the subdirectory S1
m. What is the command to return back to the direcoty STORE
n. What is the command to delete the file grocery?
o. What is the command to delete the directory S2
Using echo to display text on the
terminal
Example:
echo “This is a test message”
This is a test message
$_
Line, Word and Character
counting
$ wc [Options] [File name]
Option Description
-c Count the number of characters.
-l Count the number of lines.
-w Count the number of words
Example:
$ cat memo
This is to test the wc command
$ wc memo
1 7 30 memo
Note:
A character includes all spaces, tabs and
newlines
lines
words
characters
Login details
who - Displays a list of the users currently
logged in.
Example:
$ who
Nimal123 tty01 Aug 12 10:32
Mala342 tty02 Aug 12 10:40
Using man to display the system
manual
The manual utility displays pages from the
system documentation on the terminal.
Example:
$ man who
Special Characters
You should not use any of the special
characters in a file name or as regular
characters.
& ; * ‘ ” [ ] ( ) $ < > { } # ? / 
In addition % ! and ~ are special characters
to the C shell and the Korn shell.
What will happen if special characters are
used as regular characters…
$ echo Hello
Hello
What will be the output for the following?
$ echo *
Quoting Special Characters
To use a special character as a regular
character, you can quote it. To quote a
character precede it will a backslash ().
Example:
rm presentation*
Wild card Significance
* Matches any number of characters
including none.
? Matches a single characters
[ijk] Matches a single character either i, j or k.
[!ikj] Matches a single character which is not
an i, j or k.
[x-z] Matches a single character which is
within the ASCII range of the characters
x and z.
[!x-z] Matches a single character which is not
within the ASCII range of the characters
x and z.
Example:
What command will display the contents of
the current directory whose names start
with the character ‘a’ and end with a period
(‘.’) followed by any one character followed
by either the number 2, 4 or 6?
Using mail to Send and Receive
Electronic mail
I. $ mail nimal
subject: Test message
This is a test message
……
…….
[control + d]
II. mail nimal@…..
To read you mail, run the mail utility
without a user name.
Using diff to compare two file
This command can be used to display file
differences. Unlike cmp command, it tells
you which lines in one file has to be changed
to make the two files identical.
Ie. the output will tell how to make the first
file equal in contents to the second file.
$ diff [Option] [File 1] [File 2]
$ diff [Option] [Directory 1] [Directory 2]
Compares all files in directory 1 with files in
directory 2 that have the same name
Options:
-b (Blank): This option causes diff to ignore
blanks,tabs and spaces.
Example:
$ cat report1
bbbb
cccc
$ cat report2
aaaa
bbbb
cccc
$ diff report 1 report2
0a1
>aaaa

More Related Content

PPTX
various shell commands in unix operating system.pptx
PDF
Basic unix commands
PPTX
Ai module
PDF
basic-unix.pdf
PPT
Linux ppt
PPTX
Unix training session 1
PDF
Command Line Tools
PPT
Sandy Report
various shell commands in unix operating system.pptx
Basic unix commands
Ai module
basic-unix.pdf
Linux ppt
Unix training session 1
Command Line Tools
Sandy Report

Similar to 2.Utilities.ppt (20)

PPT
Sandy Report
PPT
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
PDF
Basic unix commands_1
PDF
Basic linux commands
DOC
58518522 study-aix
PDF
linux commands.pdf
PPTX
Linux System commands Essentialsand Basics.pptx
PPT
Online Training in Unix Linux Shell Scripting in Hyderabad
PPTX
os lab commanaaaaaaaaaaaaaaaaaaaaaads.pptx
PPT
03 browsing the filesystem
PPTX
Linux Command.pptx
PPT
Unix fundamentals
PPTX
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
PPT
8.1.intro unix
PPTX
PPTX
Commands and shell programming (3)
DOCX
Directories description
TXT
DOCX
Chapter 4 Linux Basic Commands
Sandy Report
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
Basic unix commands_1
Basic linux commands
58518522 study-aix
linux commands.pdf
Linux System commands Essentialsand Basics.pptx
Online Training in Unix Linux Shell Scripting in Hyderabad
os lab commanaaaaaaaaaaaaaaaaaaaaaads.pptx
03 browsing the filesystem
Linux Command.pptx
Unix fundamentals
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
8.1.intro unix
Commands and shell programming (3)
Directories description
Chapter 4 Linux Basic Commands

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Well-logging-methods_new................
PDF
PPT on Performance Review to get promotions
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Welding lecture in detail for understanding
PPTX
Lecture Notes Electrical Wiring System Components
DOCX
573137875-Attendance-Management-System-original
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
UNIT 4 Total Quality Management .pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
OOP with Java - Java Introduction (Basics)
bas. eng. economics group 4 presentation 1.pptx
Well-logging-methods_new................
PPT on Performance Review to get promotions
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Welding lecture in detail for understanding
Lecture Notes Electrical Wiring System Components
573137875-Attendance-Management-System-original
Operating System & Kernel Study Guide-1 - converted.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
UNIT 4 Total Quality Management .pptx
R24 SURVEYING LAB MANUAL for civil enggi
Embodied AI: Ushering in the Next Era of Intelligent Systems
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026

2.Utilities.ppt

  • 3. pwd (Present Working Directory) Displays the directory you are currently placed in. Example: $ pwd /usr/nimal Output Note: pwd displays the absolute path name.
  • 5. cd [directory name] Changes the current directory to the directory specified as the argument. Example 1: $ cd test $ pwd /usr/nimal/test
  • 6. Example 2 If you need to switch to /bin: $ cd /bin • The command cd without an argument switches to the home directory. • cd .. - Moves you to the next higher level subdirectory.
  • 8. ls [options] [file list] Shows all the files in the current directory. Options -a All entries (hidden files, . and .. are displayed). -x Displays multicolumn. -F Marks executable files with * and directories with / . -l Long listing showing 7 attributed.
  • 9. Example: $ ls –a $ ls –l test Utility Option File name
  • 11. Displaying the contents of a file cat [Option] [file names] Options: -n Line numbers -b Omit line numbers on blank lines used with –n option -S Single space. Reduce multiple adjacent empty lines to a single blank line
  • 12. Example: $ cat test1 test2 test3 If you want to view files one after the other, you can use more utility in place of cat. The more utility pauses after displaying the content of a file. $ more [file names]
  • 13. Creating a file The command cat can also be used for creating a file. $ cat > abc ……. …….. ……. [control + d]
  • 15. mkdir [option] [directory names] Option -p (parent) – If the parent directory of the directory you are creating does not exists. Example 1 $ mkdir test
  • 16. Example 2 $ mkdir test test/test1 test/test2 Example 3 $ mkdir –p memo/letter Parent directory Parent directory
  • 17. Deleting a File rm [file names] Example $ rm abc
  • 19. rmdir [directory names] Example $ rmdir test1 test2 Note: You cannot remove the working directory or a directory that contains files and subdirectories.
  • 21. Three types of users can access a file. • Owner – (read, write, execute) • Group - (read, write, execute) • Other - (read, write, execute) There are a total of nine possible ways to access a file. All these permissions take the general form: - r w x r w x r w x
  • 22. r indicates read permission. w indicates writes permission and x indicates execute permission. (ie. The file can be executed as a program). If any of these permissions don’t apply to a specific category, then a hyphen (-) will occupy the respective slot.
  • 23. - r w x r w x r w x d : Directory - : Ordinary file b/c : I/O device User (owner) Group Others
  • 24. Note: For a directory file: • Read – read the directory (ls) • Write – create, move, copy, remove a directory • Execute– search the directory (cd)
  • 25. _ r w _ r_ _ r_ _ 1 mala prog 245 May 20 10:15 myfile 1- the file has only one link mala – The file is owned by Mala prog – The file belongs to the group prog 245 – File size May 20 10:15 - Last modified at this time myfile – The name of the file is myfile
  • 26. • Note: Your home directory comes with the following default permissions set by the system administrator: d r w x - - - - - - These permissions will also be acquired by any sub directories you create.
  • 28. chmod [Category] [Operation] [Permission][Filename] Category Operation Permission u- user + : assign permission r- read permission g- group - : remove permission w- write permission o – others x – execute permission a- all
  • 29. Example $ chmod u +x test $ ls –l test - r w x r - - r - -
  • 30. Examples 1. Assign all categories execute permission, for the file abc. 2. Remove the read permission of the group and others of the file test. 3. Remove execute permission of the user and assign read permission to the group and others of the file xyz. 4. Assign write and execute permission for the others in file memo.
  • 31. Octal Notation –Changing Access Permission using mode number
  • 32. $ chmod [mode] [file names] chmod also takes a numeric argument that describes both the category as well as the permission described in the above section. Read permission is assigned the value: 4 Write : 2 Execute : 1
  • 33. If a file has read and write permission for the owner, then according to the above notation: 4 +2 = 6 Example $ chmod 666 report $ ls- l report - r w – r w – r w -
  • 34. Example: $ ls -l memo d r w x r – x r - - 1 nimal mine 20 Feb 12 21:14 memo 1. According to the output shown above, is memo a file ? 2. Does the group have execute permission? 3. How can you give the others write permission?
  • 36. cp [options] [source file] [destination file] Creates an exact image of the file on disk with a different name. If the destination file does not exists, it will be first created before the copying takes place. Else, the file will be overwritten.
  • 37. Option -i (interactive): Warns the user before overwriting the destination file Example $ cp abc xyz $ cp -i abc xyz
  • 39. mv [option] [existing file name] [new file name] mv [option] [existing dir name] [new dir name] The mv command renames a file/directory. The command does not create a copy of the file. It just renames the file. If the destination file exists, then it will be overwritten.
  • 40. Option -i (interactive): Warns the user before overwriting the destination file Example $ mv memo letter
  • 41. Moving a file mv can be used to move a group of files to a directory. Example $ mv test1 test2 test3 test4 test Directory These could be files, directories or both
  • 43. lpr [options] [file names] Example $ lpr report memo letter lpq – provides status information about jobs currently in the printer queue. lprm – removes files from the queue.
  • 44. Option: -h : Skip printing the header page with your login name.
  • 46. $ uniq [option] [file name] Option Description -c Count each line with number of occurrences -d Duplicated lines, display only lines that are repeated -u Unique lines, display only lines that are not repeated
  • 48. 1. $ uniq sample abc xyz pqr 2. $ uniq –c sample 2 abc 1 xyz 3 pqr No. of repetitions
  • 49. 3. $ uniq –d sample abc pqr 4. $ uniq –u sample xyz Only the lines that were duplicated will be displayed Only the lines that were not Duplicated will be displayed
  • 51. cmp command can be used to find out whether two files are identical in all respect so that one of them can be deleted. Example: $ cmp test1 test2 test1 test2 differ: char 10, line 5 $_
  • 52. The two files will be compared byte by byte and the location of the first mismatch will be displayed on the screen. When the command is used without options, it does not bother about possible subsequent mismatches, but will abort with the message shown above. If the two files are identical, them cmp will display no message.
  • 53. -l option Example: $ cat memo1 abc xyz $ cat memo2 abe wxy
  • 54. $ cmp –l memo1 memo2 3 143 145 5 170 167 6 171 170 7 172 171 Character number Octal representation of characters
  • 55. Example: The file grocery_list consists of four fields. The fields are: item, supplier, supplier address and price/unit. Item Supplier Address Price/unit Sugar Sweetprod Ltd Kandy 45.00 Butter SLExporters Colombo 135.00 Carrots ABCFarms.Ltd Nawalapitiya 90.00
  • 56. a. How can you create the file grocery_list? b. How can you create a copy of the file grocery_list with name grocery? c. How can you tell whether the file grocery_list is the same as the file grocery? d. How can you see the grocery_list entries that are repeated? e. What is the command to print the file grocery_list f. What is the command to count the number of lines of the file grocery_list g. What is the command to view the details of the file grocery page by page h. What is the command to create the parent directory STORE and two sub directories S1 and S2 i. How can you move the files grocery_list and grocery to the directory STORE
  • 57. j. How can you confirm that the two files has been moved to the directory STORE? k. What is the command to rename the file grocery_list to grocery? l. How can you move to the subdirectory S1 m. What is the command to return back to the direcoty STORE n. What is the command to delete the file grocery? o. What is the command to delete the directory S2
  • 58. Using echo to display text on the terminal Example: echo “This is a test message” This is a test message $_
  • 59. Line, Word and Character counting
  • 60. $ wc [Options] [File name] Option Description -c Count the number of characters. -l Count the number of lines. -w Count the number of words
  • 61. Example: $ cat memo This is to test the wc command $ wc memo 1 7 30 memo Note: A character includes all spaces, tabs and newlines lines words characters
  • 62. Login details who - Displays a list of the users currently logged in. Example: $ who Nimal123 tty01 Aug 12 10:32 Mala342 tty02 Aug 12 10:40
  • 63. Using man to display the system manual The manual utility displays pages from the system documentation on the terminal. Example: $ man who
  • 65. You should not use any of the special characters in a file name or as regular characters. & ; * ‘ ” [ ] ( ) $ < > { } # ? / In addition % ! and ~ are special characters to the C shell and the Korn shell.
  • 66. What will happen if special characters are used as regular characters… $ echo Hello Hello What will be the output for the following? $ echo *
  • 67. Quoting Special Characters To use a special character as a regular character, you can quote it. To quote a character precede it will a backslash (). Example: rm presentation*
  • 68. Wild card Significance * Matches any number of characters including none. ? Matches a single characters [ijk] Matches a single character either i, j or k. [!ikj] Matches a single character which is not an i, j or k. [x-z] Matches a single character which is within the ASCII range of the characters x and z. [!x-z] Matches a single character which is not within the ASCII range of the characters x and z.
  • 69. Example: What command will display the contents of the current directory whose names start with the character ‘a’ and end with a period (‘.’) followed by any one character followed by either the number 2, 4 or 6?
  • 70. Using mail to Send and Receive Electronic mail
  • 71. I. $ mail nimal subject: Test message This is a test message …… ……. [control + d] II. mail nimal@….. To read you mail, run the mail utility without a user name.
  • 72. Using diff to compare two file
  • 73. This command can be used to display file differences. Unlike cmp command, it tells you which lines in one file has to be changed to make the two files identical. Ie. the output will tell how to make the first file equal in contents to the second file.
  • 74. $ diff [Option] [File 1] [File 2] $ diff [Option] [Directory 1] [Directory 2] Compares all files in directory 1 with files in directory 2 that have the same name
  • 75. Options: -b (Blank): This option causes diff to ignore blanks,tabs and spaces. Example: $ cat report1 bbbb cccc $ cat report2 aaaa bbbb cccc
  • 76. $ diff report 1 report2 0a1 >aaaa