0% found this document useful (0 votes)
35 views7 pages

OSA3

Chapter 3 discusses file systems, defining a file as a named collection of related information stored on secondary storage, with various types including text, source, object, and executable files. It covers path names, file attributes, access control lists, and commands for file manipulation in Linux, such as adding text, comparing files, and processing text. Additionally, it explains commands like cut, paste, and sort for managing file contents and structure.

Uploaded by

9gnxfs7qvx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views7 pages

OSA3

Chapter 3 discusses file systems, defining a file as a named collection of related information stored on secondary storage, with various types including text, source, object, and executable files. It covers path names, file attributes, access control lists, and commands for file manipulation in Linux, such as adding text, comparing files, and processing text. Additionally, it explains commands like cut, paste, and sort for managing file contents and structure.

Uploaded by

9gnxfs7qvx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 3 File system

 A file is a named collection of related information that is recorded on secondary


storage.
 The file name is usually a string of characters, such as example.c.
 Information in a file is defined by its creator.
 Many different types of information may be stored in a file-source programs, object
programs, executable programs, numeric data, text, payroll records, graphic images,
sound recordings, and so on.
 A file has a certain defined Structure which depends on its type.
 Example:
o A text file is a sequence of characters organized into lines (and possibly pages).
o A source file is a sequence of subroutines and functions, each of which is further
organized as declarations followed by executable statements.
o An object file is a sequence of bytes organized into blocks understandable by the
system's linker.
o An executable file is a series of code sections that the loader can bring into
memory and execute.
Path names
Path names can be of two types: absolute and relative.
An absolute path name begins at the root and follows a path down to the specified file,
giving the directory names on the path.
A relative path name defines a path from the current directory.
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.
File types
A file is a named collection of related information that is recorded on secondary storage.
File Attributes
 Name. The symbolic file name is the only information kept in human-readable form.
 Identifier. This unique tag, usually a number, identifies the file within the file system;
it is the non-human-readable name for the file.
 Type. This information is needed for systems that support different types of files.
 Location. This information is a pointer to a device and to the location of the file on that
device.
 Size. The current size of the file (in bytes, words, or blocks) and possibly the maximum
allowed size are included in this attribute.
 Protection. Access-control information determines who can do reading, writing,
executing, and so on.
 Time, date, and 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.
Information about files are kept in the directory structure, which is maintained on the disk
Access Control List (ACL)
 The common approach to the protection problem is to make access dependent on the
identity of the user.
 An Access Control List (ACL) specifies user names and the types of access allowed for
each user.
 When a user requests access to a particular file, the operating system checks the access
list associated with that file. if the user has qualifications to access the file in the mode
requested. The request is either allowed or denied.
 The modes of access are: read, write and execute.
 The main disadvantage of Access List is its length. As we do not know the users of the
resources in advance, and the present directory entry is of varying size leading space
management.
o This is solved by having three classifications of users.
o Owner. The user who created the file is the owner.
o Group. A set of users who are sharing the file and need similar access is a group,
or work group.
o Universe. All other users in the system constitute the universe.
 Example: in UNIX System:
 Three classes of users
RWX

a) owner access 7  1 11

RWX

b) group access 6  11 0

RWX

c) Universe public access 1  0 01

owner group public

chmod 761 game

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.
 E.g.: echo 'text here' >> filename
Pipes
Pipes are useful to connect multiple commands together. Instead of sending the output of a
process to a file with redirect operator ">", user can pass it to another process as input
using the pipe operator "¦".
E.g.: ls –l | less.
In this example the output of the ls command is feed into less.
File Comparison
The file comparison commands compare the files and find the similarities and differences
between these files. The different file comparison commands used in Linux are: cmp,
comm, diff, uniq.
comm: Displays what is common between both the files
Syntax: comm file1 file2 //The contents of input files should be sorted alphabetically.
E.g.: Create 2 files with name f1 and f2
Contents of file f1: apple, mango, orange
Contents of file f2: grape, mango, musk melon
Example: comm f1 f2
apple
grape
mango
muskmelon
orange

Column 1 gives the names which are present in first file but not in second file
Column 2 gives the names which are present in second file but not present in first file
Column 3 gives the names which are present in both the Files

diff: Display file differences. Diff displays which lines in one file have to be changed to
make the file identical to other.
Syntax: diff file1 file2

E.g.:
Contents of file f1: apple, mango, orange
Contents of file f2: grape, mango, musk melon
diff f1 f2

Understanding Output
c – change d – delete a – append
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: likewise can be understood.
Filters / Text Processing Commands
Filters are commands which accept data from standard input manipulate it and write the
results to standard
Output.
head: command displays the top “n” lines of the file. When used without any option it will
display first 10 lines of the file. (Note: Create a file sample.txt using text editor and type
at least 15 lines)
Syntax: head filename
Example: head sample1.txt
/*display first 10 lines*/

tail: command displays the end of the file. By default it will display last 10 lines of the
file.
Syntax: tail filename
Example: head sample1.txt
/*display last 10 lines*/
(Note: Create a file sample.txt using text editor and type at least 15 lines)
tail or head with -n followed by a number will display that many number of lines from last
and from first respectively.
head -n 20 sample1.txt
/* will display first 20 lines*/
tail -n 15 sample1.txt
/* will display last 15 lines */

cut: Cut command in linux is used to select sections of text from each line of files. The
cut command can be used to select fields or columns from a line by specifying a delimiter
or to select a portion of text by specifying the range or characters. Basically the cut
command slices a line and extracts the text.

Syntax: cut -c [numbers delimited by comma or range] <file name>


Here the option available are c : character
f : field
d : delimeter

Example: Create a file using text editor “file.txt” with following data
unix or linux os
is unix good os
is linux good os
cut -c4 file.txt

Displays 4th character from the file

x
u
l

cut -c4,6 file.txt


Displays 4th & 6th characters from the file

xo
ui
ln

cut -c4-7 file.txt

The above cut command prints the characters from fourth position to the seventh position
in each line.

x or
unix
linu

The cut command can be used to extract the fields in a file using a delimiter. The -d option
in cut command can be used to specify the delimiter and -f option is used to specify the
field position.
cut -d' ' -f2 file.txt
or
unix
linux

This command prints the second field in each line by treating the space as delimiter.
More than one field can be printed by specifying the position of the fields in a comma
delimited list.

cut -d' ' -f2,3 file.txt

or linux
unix good
linux good

The above command prints the second and third field in each line.
User can print a range of fields by specifying the start and end position.
cut -d' ' -f1-3 file.txt

The above command prints the first, second and third fields.

To print the first three fields, you can ignore the start position and specify only the end
position.
cut -d' ' -f-3 file.txt

paste:
Paste command will paste the contents of the files side by side
create “file1” with following contents using text editor and contents must be separated by
TAB

sourav 40 male
sachin 45 male
pooja 16 female
suchithra 17 female

create “file2” with following contents using text editor and contents must be separated by
TAB

IV CS NRAMP
II EC KARKALA
VI CE MANIPAL
II EE UDUPI

Syntax: paste file1 file2


Example: paste cutlist1.txt cutlist2.txt
sourav 40 male IV CS NRAMP
sachin 45 male II EC KARKALA
pooja 16 female VI CE MANIPAL
suchithra 17 female II EE UDUPI

sort: Sorts the lines in a text file.


create a “FRUITS” with following contents using text editor
mango
apple
orange
banana
grapes
Syntax: sort [options]... [file]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy