SlideShare a Scribd company logo
Table of Content
 File and File System
 Pathnames
 File System Structure and its description
 Definition of IoT
 Navigating the File System
 Test – MCQ
Computer Science & Engineering – 20CS42P
 A file is a collection of related information that is recorded on secondary storage
devices such as hard disks, magnetic disks, optical disks, and tapes.
 File contains a various types of data like source programs, object programs,
executable programs, numeric data, text, payroll records, graphic images, sounds
recordings, video recordings and so on.
 A file has a defined structure according to its type.
Example: Text file, Source File, Object file and Executable file.
File and File System
Computer Science & Engineering – 20CS42P
 File system is the part of the operating system which is responsible for file management.
 A file system (or file management) is a method of organizing and retrieving files from a
storage medium (Example: hard drive).
 File system is a method for storing and organizing computer files and the data they contain, to
make it easy to find and access.
 Windows uses FAT32, exFAT and NTFS,
 Linux uses ext2, ext3, FAT32 and exFAT.
 Unix systems use UFS, ext2, ext3 and ZFS.
 Macs use FAT32, exFAT, HFS+ and APFS.
File System
Computer Science & Engineering – 20CS42P
Pathname is a sequence of symbols and filenames which indicates the location of our file in the hierarchical
file system.
Pathnames are classified into Absolute path name and Relative Path name.
1. Absolute path name
An absolute pathname is a path that describes the location of a file or folder from the root directory (/).
Example: usr/cse/myfile.txt
2. Relative pathname
A relative pathname is a path that describes the location of a file or folder in relative to the
current/present working directory (pwd).
Example: Assuming that we are already present in cse directory then the relative path for the same can be
written as simple myfile.txt
Pathnames
Computer Science & Engineering – 20CS42P
Pathnames
Computer Science & Engineering – 20CS42P
To be more specific let’s take a look
on the figure in which if we are
looking for photos then absolute path
for it will be provided as
/home/jono/photos but assuming that
we are already present in jono
directory then the relative path for the
same can be written as simple photos.
File system structure and its description
File system structure is organized in to several layers.
 Every layer of the file system is responsible for some
activities.
1. Logical file system
2. File organization module
3. Basic file system
4. I/O Control
Computer Science & Engineering – 20CS42P
File system structure and its description
1. Logical file system –
The logical file system contains the Meta data of the file and directory
structure.
File control block (FCB) has information about a file, including
ownership; size, permissions, and location of file contents.
Logical file system is responsible for protection and security.
Computer Science & Engineering – 20CS42P
File system structure and its description
2. File organization Module –
It has information about files, location of files and their logical and
physical blocks.
In order to store and retrieve the files, the logical blocks need to be
mapped to physical blocks. This mapping is done by File organization
module.
It is also responsible for free space management.
Computer Science & Engineering – 20CS42P
File system structure and its description
3. Basic file system –
The basic file system is responsible for issuing the commands to
device driver to read and write physical blocks on disk.
It manages the memory buffers and caches.
A block in buffer can hold the contents of the disk block and cache
stores frequently used file system metadata
Computer Science & Engineering – 20CS42P
File system structure and its description
4. I/O Control level –
I/O controls contain the codes by using which it can access
hard disk. These codes are known as device drivers.
 Device driver’s acts as interface between devices and O.S, they
help to transfer data between disk and main memory.
I/O controls are also responsible for handling interrupts
Computer Science & Engineering – 20CS42P
Navigating the File System
Navigating the file system will helps in moving through the file system
Several commands are provided by Linux/Windows operating systems
to navigate the file system.
The commands to move from one directory to other, list the files
available, copy/create/delete files from one place to other, create/
remove directories and many such operations are provided.
Computer Science & Engineering – 20CS42P
Table of Content
 File Types
 File Attributes
 Access Control List (ACL)
 Adding text to File
 Test – MCQ
Computer Science & Engineering – 20CS42P
 Many operating systems support several types of files. Windows based operating system supports following
types of files:
1. Regular Files and
2. Directories
 UNIX based operating system supports following types of files:
1. Regular files
2. Directories.
3. Character special files and
4. Block Special files
File Types
Computer Science & Engineering – 20CS42P
 Regular/Ordinary files contain user information generally in ASCII form.
 An ordinary file can be either a text file or a binary file.
1. A text file contains only printable characters and you can view and edit them. All C
and Java program sources, shell scripts are text files.
2. A binary file contains both printable and nonprintable characters that cover the
entire ASCII range. The object code, Sound and video files are binary files.
Regular Files
Computer Science & Engineering – 20CS42P
 A directory contains no data, but keeps details of the files and subdirectories that it
contains.
 A directory file contains one entry for every file and subdirectory that it houses.
 Each entry has two components.
1. Filename and
2. A unique identification number of the file or directory (called the inode number).
Directory File
Computer Science & Engineering – 20CS42P
 On UNIX/LINUX systems there are two flavors of special files for each device, character special
files and block special files. Linux systems only provide one special file for each device.
1. Character Special files are related to input/output and used to model serial I/O devices such as
terminals, printers and networks.
 When a character special file is used for device I/O, data is transferred one character at a time.
Example: Line Printers, Modems, and Consoles
2. Block Special files are used to model disks.
 When a block special file is used for device I/O, data is transferred in large fixed-size blocks.
Example: Hard disk drivers and Floppy Disk Drives
Device Files/Special Files
Computer Science & Engineering – 20CS42P
File Type
 In operating systems, the file type is derived from the file extension.
 File type is included as a part of the filename.
 File name is split into two parts- a name and extension separated by a period
character.
Example: only a file with a .com, .exe, or .bat extension can be executed. The .com
and .exe files are two forms of binary executable files, whereas .bat file is a batch file
containing commands in ASCII format to the operating system.
Computer Science & Engineering – 20CS42P
File Types with extensions and functions
Computer Science & Engineering – 20CS42P
File Attributes
1. Name: A file is named for the convenience of the user and is referred by its name. A name is
usually a string of characters.
2. Identifier: This unique tag, usually a number, identifies the file within the file system.
3. Type: Files are of so many types. The type depends on the extension of the file.
Example:
.exe Executable file
.obj Object file
.src Source file
Computer Science & Engineering – 20CS42P
File Attributes Contd..
4. Location: This information is a pointer to a device and to the location of the file on that
device
5. Size: The current size of the file (in bytes, words, blocks).
6. Protection: Access -control information determines who can do reading, writing,
executing and so on.
7. Time, Date, User identification: This information may be kept for creation, last
modification, and last use. These data can be useful for protection, security and usage
monitoring
Computer Science & Engineering – 20CS42P
Access Control List (ACL)
 Access control list (ACL) provides an additional, more flexible permission
mechanism for file systems.
 ACL allows you to give permissions for any user or group to any disc resource.
 Changing permissions using the command chmod or the ACL command setfacl has
the same effect.
 The Shell commands getfacl and setfacl are used to show and set ACL entries
respectively.
Computer Science & Engineering – 20CS42P
Access Control List (ACL) Contd..
 Many systems recognize three classifications of users in connection with each file.
1. Owner 2.Group 3. Others
 Each user had three modes of access are: read (R), write (W) and execute (X).
 In UNIX system the three classes of users are given the following default access
permissions for a file:
1. Owner Access: RWX
2. Group Access: RW
3. Others Access: X
Computer Science & Engineering – 20CS42P
Access Control List (ACL) Contd..
Example:
getfacl test/declarations.h
Output:
# file: test/declarations.h
# owner: mandeep
# group: mandeep
user::rw-
group::rw-
other::r--
Example:
setfacl -m u:mandeep:rwx test/declarations.h
Output:
# file: test/declarations.h
# owner: mandeep
# group: mandeep
user::rwx
group::rw-
other::r--
Computer Science & Engineering – 20CS42P
Adding text to file
 Text can be added to a file in different ways in Linux operating system:
1. Using editors : vi editor, VIM, Nano, Gedit, Text Editor etc
2. Using redirection :
 The operator > writes output to a new file, or to an existing file; in which
case it wipes off everything which is previously present in the file.
 The operator >> appends output at the end of an existing file.
Example: echo “text here” >> filename
Computer Science & Engineering – 20CS42P
Table of Content
 Pipes
 File Comparison
 Filters/Text Processing Commands
 Test – MCQ
Computer Science & Engineering – 20CS42P
 A pipe is a way to connect the output of one program to the input of
another program without any temporary file.
 Pipes are unidirectional.
 Syntax: command1 | command2
Pipes
Computer Science & Engineering – 20CS42P
Pipes Contd..
Computer Science & Engineering – 20CS42P
 The file comparison command helps us to compare the files and find the similarities
and differences between these files.
 The different file comparison commands used in Linux are: cmp, comm, and diff.
1. Cmp: This command is used to compare two files byte by byte.
 It displays the byte and line number where first difference is found.
 If no difference is found no output will be displayed.
Syntax :cmp <file1><file2>
Example: $ cmp file1 file2
File Comparison
Computer Science & Engineering – 20CS42P
comm command compares two sorted files line by line .
Syntax: comm file1 file2 //The contents of input files should be sorted alphabetically.
E.g.: Create 2 files with name file1 and file2
Contents of file1: apple, mango, orange
Contents of file2: grape, mango, musk melon
Example: comm file1 file2
apple
grape
mango
muskmelon
orange
File Comparison - comm
Computer Science & Engineering – 20CS42P
File Comparison - diff
diff command is used to find difference between two files.
Diff displays which lines in one file have to be changed to make the file identical to other.
Syntax: diff file1 file2 Example: diff file1 file2
1c1
<apple…
grape>
1c1: 1st line of 1st file to be changed to match 1st line of 2nd file
“<” means 1st file
“>” means 2nd file
3c3:like wise can be understood.
Computer Science & Engineering – 20CS42P
Filters/Text Processing Commands
 Filters are commands which accept data from standard input (keyboard) manipulate it and writes the
results to standard Output (screen).
 Many filters are available in UNIX such as head, tail, cut, paste, sort, uniq, tr, pr.
1. head: This command is used to displays the top of the file.
Syntax : $ head filename // shows first 10 lines
Syntax : $ head –n filename
Create a file sample.txt using text editor and type at least 25 lines.
Example: $ head -n 20 sample1.txt or $ head 20 sample1.txt
Output: /* will display first 20 lines*/
Computer Science & Engineering – 20CS42P
Filters - tail
2. tail: The tail command used to displays the end of the file. By Default it will display
last 10 lines of the file
Syntax :$ tail filename // shows Last 10 lines
Syntax :$ tail –n filename
Example: $ tail -n 20 sample1.txt or $ tail 20 sample1.txt
Output : /* will display last 20 lines*/
Computer Science & Engineering – 20CS42P
Filters - wc
3. wc (statistic of file) : This command is used to count lines, words and characters, Depending on
the option used.
Syntax : wc [options] [file name]
Options : -l: Number of lines
-w: Number of words
-c: Number of characters
Example: $ wc sample1.txt
Output: 65 2776 17333 sample1.txt
Which means sample1.txt file has 65 lines, 2776 words, and 17333 Characters.
Computer Science & Engineering – 20CS42P
Filters - pr
4. pr: paginating files
 This command is used to convert text files for printing type.
Syntax: pr [OPTION]... [FILE]…
Computer Science & Engineering – 20CS42P
Filters - cut
Computer Science & Engineering – 20CS42P
5. cut is used for slitting the file vertically. This command can be used to cut the columns from a file with -
c option.
Syntax: $ cut -c [numbers delimited by comma or range] <file name>
Option: -f option you can cut the fields delimited by some character.
-d option is used to specify the delimiter and
-f option used to specify the field number.
Example: $ cut -c 6-22, 24-32 students.txt $ cut - f 2-3 cut.txt
$ cut -c -3, 6-22, 28-34, 55- students.txt
The expression 55- indicates column number 55 to end of line. Similarly, -3 is the same as 1-3.
Filters - paste
6.paste command will paste the contents of the file side by side.
Syntax : $ paste <file1 name> <file2 name>…..<filen name>
Example: $ paste file1.txt file2.txt
Computer Science & Engineering – 20CS42P
Filters - sort
Computer Science & Engineering – 20CS42P
7. sort command orders a file line by line.
Syntax : sort [-options] filename
sort.txt (use tab after each word)
01 joe
02 marie
03 albert
Filters – sort Example
Computer Science & Engineering – 20CS42P
SN Example Output
1 $ sort sort.txt sorts the content of the file sort.txt
01 joe
02 marie
03 albert
2 $ sort - r sort.txt sorts the content of the file sort.txt in reverse order
03 albert
02 marie
01 joe
3 $ sort - k 2 sort.txt sorts the content of the file sort.txt based on the key (k)
2 represents the second coloumn
03 albert
01 joe
02 marie
Filters - uniq
Computer Science & Engineering – 20CS42P
8. uniq command will locate repeated and non-repeated lines in file. Filter out repeated
lines in a file.
Syntax :$ uniq [options] filename
uniq options
–u: Selecting the Non repeated Lines
–d: Selecting the Duplicate Lines
–c: Counting the frequency of Occurrences
Filters – uniq Example
Computer Science & Engineering – 20CS42P
u.txt
this is a line
this is a line
this is a line
this is also a line
this is also a line
this is also also a line
SN Example Output
1 $ uniq u.txt displays only single copy of each line present
in u.txt
this is a line
this is also a line
this is also also a line
2 $ uniq - c u.txt displays only single copy of each line present
in u.txt along with their count
3 this is a line
2 this is also a line
1 this is also also a line
3 $ uniq - d u.txt displays only the lines at are duplicate in u.txt
this is a line
this is also a line
Filters - tr
Computer Science & Engineering – 20CS42P
 9. tr command is used to translate, delete or squeeze characters.
Syntax: tr options expression1 expression2 standard input
 The tr filter manipulates individual characters in a line.
 tr takes input only from standard input; it does take a filename as arguments.
Example: $echo "linux dedicated server" | tr "[a-z]" "[A-Z]"
LINUX DEDICATED SERVER
Filters - grep
Computer Science & Engineering – 20CS42P
10. grep command is used to search files for lines that match a given pattern.
Syntax : grep pattern file
Example : grep pattern sample.txt
Options
-v Print all lines that do not match pattern.
-n Print the matched line and its line number.
-l Print only the names of files with matching lines (letter "l")
-c Print only the count of matching lines.
-i Match either upper- or lowercase.
Filters – grep Example
Computer Science & Engineering – 20CS42P

More Related Content

PPTX
The Operating System concepts.. -os.pptx
PPTX
The Operating System concepts.. -os.pptx
PDF
Chapter 5
PDF
Chapter 5
PPTX
Rishav Mishra final presentation on UNIX Final.pptx
PPTX
Rishav Mishra final presentation on UNIX Final.pptx
PPTX
Unix / Linux Operating System introduction.
PPTX
Unix / Linux Operating System introduction.
The Operating System concepts.. -os.pptx
The Operating System concepts.. -os.pptx
Chapter 5
Chapter 5
Rishav Mishra final presentation on UNIX Final.pptx
Rishav Mishra final presentation on UNIX Final.pptx
Unix / Linux Operating System introduction.
Unix / Linux Operating System introduction.

Similar to various commands in linux operating systems (20)

DOCX
linux file sysytem& input and output
DOCX
linux file sysytem& input and output
DOCX
File systemimplementationfinal
DOCX
File systemimplementationfinal
PPTX
Shells commands, file structure, directory structure.pptx
PPTX
Shells commands, file structure, directory structure.pptx
DOCX
file management
DOCX
File system interface Pre Final
DOCX
File systeminterface-pre-final-formatting
DOCX
file management
DOCX
File system interface Pre Final
DOCX
File systeminterface-pre-final-formatting
PPT
Chapter 10 - File System Interface
PPT
Chapter 10 - File System Interface
DOCX
Linux File System.docx
DOCX
Linux File System.docx
PPTX
File Input/output, Database Access, Data Analysis with Pandas
PPTX
File Input/output, Database Access, Data Analysis with Pandas
DOCX
Filesystemimplementationpre final-160919095849
DOCX
Filesystemimplementationpre final-160919095849
linux file sysytem& input and output
linux file sysytem& input and output
File systemimplementationfinal
File systemimplementationfinal
Shells commands, file structure, directory structure.pptx
Shells commands, file structure, directory structure.pptx
file management
File system interface Pre Final
File systeminterface-pre-final-formatting
file management
File system interface Pre Final
File systeminterface-pre-final-formatting
Chapter 10 - File System Interface
Chapter 10 - File System Interface
Linux File System.docx
Linux File System.docx
File Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with Pandas
Filesystemimplementationpre final-160919095849
Filesystemimplementationpre final-160919095849
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
web development for engineering and engineering
PDF
PPT on Performance Review to get promotions
PPT
Project quality management in manufacturing
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Artificial Intelligence
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Current and future trends in Computer Vision.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Sustainable Sites - Green Building Construction
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Mechanical Engineering MATERIALS Selection
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
web development for engineering and engineering
PPT on Performance Review to get promotions
Project quality management in manufacturing
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
OOP with Java - Java Introduction (Basics)
Artificial Intelligence
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Current and future trends in Computer Vision.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Sustainable Sites - Green Building Construction
Ad

various commands in linux operating systems

  • 1. Table of Content  File and File System  Pathnames  File System Structure and its description  Definition of IoT  Navigating the File System  Test – MCQ Computer Science & Engineering – 20CS42P
  • 2.  A file is a collection of related information that is recorded on secondary storage devices such as hard disks, magnetic disks, optical disks, and tapes.  File contains a various types of data like source programs, object programs, executable programs, numeric data, text, payroll records, graphic images, sounds recordings, video recordings and so on.  A file has a defined structure according to its type. Example: Text file, Source File, Object file and Executable file. File and File System Computer Science & Engineering – 20CS42P
  • 3.  File system is the part of the operating system which is responsible for file management.  A file system (or file management) is a method of organizing and retrieving files from a storage medium (Example: hard drive).  File system is a method for storing and organizing computer files and the data they contain, to make it easy to find and access.  Windows uses FAT32, exFAT and NTFS,  Linux uses ext2, ext3, FAT32 and exFAT.  Unix systems use UFS, ext2, ext3 and ZFS.  Macs use FAT32, exFAT, HFS+ and APFS. File System Computer Science & Engineering – 20CS42P
  • 4. Pathname is a sequence of symbols and filenames which indicates the location of our file in the hierarchical file system. Pathnames are classified into Absolute path name and Relative Path name. 1. Absolute path name An absolute pathname is a path that describes the location of a file or folder from the root directory (/). Example: usr/cse/myfile.txt 2. Relative pathname A relative pathname is a path that describes the location of a file or folder in relative to the current/present working directory (pwd). Example: Assuming that we are already present in cse directory then the relative path for the same can be written as simple myfile.txt Pathnames Computer Science & Engineering – 20CS42P
  • 5. Pathnames Computer Science & Engineering – 20CS42P To be more specific let’s take a look on the figure in which if we are looking for photos then absolute path for it will be provided as /home/jono/photos but assuming that we are already present in jono directory then the relative path for the same can be written as simple photos.
  • 6. File system structure and its description File system structure is organized in to several layers.  Every layer of the file system is responsible for some activities. 1. Logical file system 2. File organization module 3. Basic file system 4. I/O Control Computer Science & Engineering – 20CS42P
  • 7. File system structure and its description 1. Logical file system – The logical file system contains the Meta data of the file and directory structure. File control block (FCB) has information about a file, including ownership; size, permissions, and location of file contents. Logical file system is responsible for protection and security. Computer Science & Engineering – 20CS42P
  • 8. File system structure and its description 2. File organization Module – It has information about files, location of files and their logical and physical blocks. In order to store and retrieve the files, the logical blocks need to be mapped to physical blocks. This mapping is done by File organization module. It is also responsible for free space management. Computer Science & Engineering – 20CS42P
  • 9. File system structure and its description 3. Basic file system – The basic file system is responsible for issuing the commands to device driver to read and write physical blocks on disk. It manages the memory buffers and caches. A block in buffer can hold the contents of the disk block and cache stores frequently used file system metadata Computer Science & Engineering – 20CS42P
  • 10. File system structure and its description 4. I/O Control level – I/O controls contain the codes by using which it can access hard disk. These codes are known as device drivers.  Device driver’s acts as interface between devices and O.S, they help to transfer data between disk and main memory. I/O controls are also responsible for handling interrupts Computer Science & Engineering – 20CS42P
  • 11. Navigating the File System Navigating the file system will helps in moving through the file system Several commands are provided by Linux/Windows operating systems to navigate the file system. The commands to move from one directory to other, list the files available, copy/create/delete files from one place to other, create/ remove directories and many such operations are provided. Computer Science & Engineering – 20CS42P
  • 12. Table of Content  File Types  File Attributes  Access Control List (ACL)  Adding text to File  Test – MCQ Computer Science & Engineering – 20CS42P
  • 13.  Many operating systems support several types of files. Windows based operating system supports following types of files: 1. Regular Files and 2. Directories  UNIX based operating system supports following types of files: 1. Regular files 2. Directories. 3. Character special files and 4. Block Special files File Types Computer Science & Engineering – 20CS42P
  • 14.  Regular/Ordinary files contain user information generally in ASCII form.  An ordinary file can be either a text file or a binary file. 1. A text file contains only printable characters and you can view and edit them. All C and Java program sources, shell scripts are text files. 2. A binary file contains both printable and nonprintable characters that cover the entire ASCII range. The object code, Sound and video files are binary files. Regular Files Computer Science & Engineering – 20CS42P
  • 15.  A directory contains no data, but keeps details of the files and subdirectories that it contains.  A directory file contains one entry for every file and subdirectory that it houses.  Each entry has two components. 1. Filename and 2. A unique identification number of the file or directory (called the inode number). Directory File Computer Science & Engineering – 20CS42P
  • 16.  On UNIX/LINUX systems there are two flavors of special files for each device, character special files and block special files. Linux systems only provide one special file for each device. 1. Character Special files are related to input/output and used to model serial I/O devices such as terminals, printers and networks.  When a character special file is used for device I/O, data is transferred one character at a time. Example: Line Printers, Modems, and Consoles 2. Block Special files are used to model disks.  When a block special file is used for device I/O, data is transferred in large fixed-size blocks. Example: Hard disk drivers and Floppy Disk Drives Device Files/Special Files Computer Science & Engineering – 20CS42P
  • 17. File Type  In operating systems, the file type is derived from the file extension.  File type is included as a part of the filename.  File name is split into two parts- a name and extension separated by a period character. Example: only a file with a .com, .exe, or .bat extension can be executed. The .com and .exe files are two forms of binary executable files, whereas .bat file is a batch file containing commands in ASCII format to the operating system. Computer Science & Engineering – 20CS42P
  • 18. File Types with extensions and functions Computer Science & Engineering – 20CS42P
  • 19. File Attributes 1. Name: A file is named for the convenience of the user and is referred by its name. A name is usually a string of characters. 2. Identifier: This unique tag, usually a number, identifies the file within the file system. 3. Type: Files are of so many types. The type depends on the extension of the file. Example: .exe Executable file .obj Object file .src Source file Computer Science & Engineering – 20CS42P
  • 20. File Attributes Contd.. 4. Location: This information is a pointer to a device and to the location of the file on that device 5. Size: The current size of the file (in bytes, words, blocks). 6. Protection: Access -control information determines who can do reading, writing, executing and so on. 7. Time, Date, User identification: This information may be kept for creation, last modification, and last use. These data can be useful for protection, security and usage monitoring Computer Science & Engineering – 20CS42P
  • 21. Access Control List (ACL)  Access control list (ACL) provides an additional, more flexible permission mechanism for file systems.  ACL allows you to give permissions for any user or group to any disc resource.  Changing permissions using the command chmod or the ACL command setfacl has the same effect.  The Shell commands getfacl and setfacl are used to show and set ACL entries respectively. Computer Science & Engineering – 20CS42P
  • 22. Access Control List (ACL) Contd..  Many systems recognize three classifications of users in connection with each file. 1. Owner 2.Group 3. Others  Each user had three modes of access are: read (R), write (W) and execute (X).  In UNIX system the three classes of users are given the following default access permissions for a file: 1. Owner Access: RWX 2. Group Access: RW 3. Others Access: X Computer Science & Engineering – 20CS42P
  • 23. Access Control List (ACL) Contd.. Example: getfacl test/declarations.h Output: # file: test/declarations.h # owner: mandeep # group: mandeep user::rw- group::rw- other::r-- Example: setfacl -m u:mandeep:rwx test/declarations.h Output: # file: test/declarations.h # owner: mandeep # group: mandeep user::rwx group::rw- other::r-- Computer Science & Engineering – 20CS42P
  • 24. Adding text to file  Text can be added to a file in different ways in Linux operating system: 1. Using editors : vi editor, VIM, Nano, Gedit, Text Editor etc 2. Using redirection :  The operator > writes output to a new file, or to an existing file; in which case it wipes off everything which is previously present in the file.  The operator >> appends output at the end of an existing file. Example: echo “text here” >> filename Computer Science & Engineering – 20CS42P
  • 25. Table of Content  Pipes  File Comparison  Filters/Text Processing Commands  Test – MCQ Computer Science & Engineering – 20CS42P
  • 26.  A pipe is a way to connect the output of one program to the input of another program without any temporary file.  Pipes are unidirectional.  Syntax: command1 | command2 Pipes Computer Science & Engineering – 20CS42P
  • 27. Pipes Contd.. Computer Science & Engineering – 20CS42P
  • 28.  The file comparison command helps us to compare the files and find the similarities and differences between these files.  The different file comparison commands used in Linux are: cmp, comm, and diff. 1. Cmp: This command is used to compare two files byte by byte.  It displays the byte and line number where first difference is found.  If no difference is found no output will be displayed. Syntax :cmp <file1><file2> Example: $ cmp file1 file2 File Comparison Computer Science & Engineering – 20CS42P
  • 29. comm command compares two sorted files line by line . Syntax: comm file1 file2 //The contents of input files should be sorted alphabetically. E.g.: Create 2 files with name file1 and file2 Contents of file1: apple, mango, orange Contents of file2: grape, mango, musk melon Example: comm file1 file2 apple grape mango muskmelon orange File Comparison - comm Computer Science & Engineering – 20CS42P
  • 30. File Comparison - diff diff command is used to find difference between two files. Diff displays which lines in one file have to be changed to make the file identical to other. Syntax: diff file1 file2 Example: diff file1 file2 1c1 <apple… grape> 1c1: 1st line of 1st file to be changed to match 1st line of 2nd file “<” means 1st file “>” means 2nd file 3c3:like wise can be understood. Computer Science & Engineering – 20CS42P
  • 31. Filters/Text Processing Commands  Filters are commands which accept data from standard input (keyboard) manipulate it and writes the results to standard Output (screen).  Many filters are available in UNIX such as head, tail, cut, paste, sort, uniq, tr, pr. 1. head: This command is used to displays the top of the file. Syntax : $ head filename // shows first 10 lines Syntax : $ head –n filename Create a file sample.txt using text editor and type at least 25 lines. Example: $ head -n 20 sample1.txt or $ head 20 sample1.txt Output: /* will display first 20 lines*/ Computer Science & Engineering – 20CS42P
  • 32. Filters - tail 2. tail: The tail command used to displays the end of the file. By Default it will display last 10 lines of the file Syntax :$ tail filename // shows Last 10 lines Syntax :$ tail –n filename Example: $ tail -n 20 sample1.txt or $ tail 20 sample1.txt Output : /* will display last 20 lines*/ Computer Science & Engineering – 20CS42P
  • 33. Filters - wc 3. wc (statistic of file) : This command is used to count lines, words and characters, Depending on the option used. Syntax : wc [options] [file name] Options : -l: Number of lines -w: Number of words -c: Number of characters Example: $ wc sample1.txt Output: 65 2776 17333 sample1.txt Which means sample1.txt file has 65 lines, 2776 words, and 17333 Characters. Computer Science & Engineering – 20CS42P
  • 34. Filters - pr 4. pr: paginating files  This command is used to convert text files for printing type. Syntax: pr [OPTION]... [FILE]… Computer Science & Engineering – 20CS42P
  • 35. Filters - cut Computer Science & Engineering – 20CS42P 5. cut is used for slitting the file vertically. This command can be used to cut the columns from a file with - c option. Syntax: $ cut -c [numbers delimited by comma or range] <file name> Option: -f option you can cut the fields delimited by some character. -d option is used to specify the delimiter and -f option used to specify the field number. Example: $ cut -c 6-22, 24-32 students.txt $ cut - f 2-3 cut.txt $ cut -c -3, 6-22, 28-34, 55- students.txt The expression 55- indicates column number 55 to end of line. Similarly, -3 is the same as 1-3.
  • 36. Filters - paste 6.paste command will paste the contents of the file side by side. Syntax : $ paste <file1 name> <file2 name>…..<filen name> Example: $ paste file1.txt file2.txt Computer Science & Engineering – 20CS42P
  • 37. Filters - sort Computer Science & Engineering – 20CS42P 7. sort command orders a file line by line. Syntax : sort [-options] filename sort.txt (use tab after each word) 01 joe 02 marie 03 albert
  • 38. Filters – sort Example Computer Science & Engineering – 20CS42P SN Example Output 1 $ sort sort.txt sorts the content of the file sort.txt 01 joe 02 marie 03 albert 2 $ sort - r sort.txt sorts the content of the file sort.txt in reverse order 03 albert 02 marie 01 joe 3 $ sort - k 2 sort.txt sorts the content of the file sort.txt based on the key (k) 2 represents the second coloumn 03 albert 01 joe 02 marie
  • 39. Filters - uniq Computer Science & Engineering – 20CS42P 8. uniq command will locate repeated and non-repeated lines in file. Filter out repeated lines in a file. Syntax :$ uniq [options] filename uniq options –u: Selecting the Non repeated Lines –d: Selecting the Duplicate Lines –c: Counting the frequency of Occurrences
  • 40. Filters – uniq Example Computer Science & Engineering – 20CS42P u.txt this is a line this is a line this is a line this is also a line this is also a line this is also also a line SN Example Output 1 $ uniq u.txt displays only single copy of each line present in u.txt this is a line this is also a line this is also also a line 2 $ uniq - c u.txt displays only single copy of each line present in u.txt along with their count 3 this is a line 2 this is also a line 1 this is also also a line 3 $ uniq - d u.txt displays only the lines at are duplicate in u.txt this is a line this is also a line
  • 41. Filters - tr Computer Science & Engineering – 20CS42P  9. tr command is used to translate, delete or squeeze characters. Syntax: tr options expression1 expression2 standard input  The tr filter manipulates individual characters in a line.  tr takes input only from standard input; it does take a filename as arguments. Example: $echo "linux dedicated server" | tr "[a-z]" "[A-Z]" LINUX DEDICATED SERVER
  • 42. Filters - grep Computer Science & Engineering – 20CS42P 10. grep command is used to search files for lines that match a given pattern. Syntax : grep pattern file Example : grep pattern sample.txt Options -v Print all lines that do not match pattern. -n Print the matched line and its line number. -l Print only the names of files with matching lines (letter "l") -c Print only the count of matching lines. -i Match either upper- or lowercase.
  • 43. Filters – grep Example Computer Science & Engineering – 20CS42P