Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

05-File Structure and Processing-V2

file management unix

Uploaded by

sibihi2265
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

05-File Structure and Processing-V2

file management unix

Uploaded by

sibihi2265
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

The File System Structure

• To explain the UNIX file concept


• To discuss various types of files supported by UNIX
• To describe attributes of a file
• To explain the notion of pathnames
• To explain the user view of the UNIX file system
• To describe the user’s interface to the UNIX file system -
browsing the file system
• To discuss representation of a file inside the UNIX system
• To describe how a UNIX file is stored on the disk
• To explain the concept of standard files in UNIX
• To cover the commands and primitives ~ , . , .. , / , PATH, cd,
echo, file, ls, mkdir , pwd , rmdir

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Types of Files

• Simple/ ordinary file


• Directory
• Symbolic (soft) link
• Special (device) files – block special
files and character special files
• Named pipe (FIFO)
• Socket

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Types of Files (Contd)
Simple/ Ordinary File

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Types of Files (Contd)
• Link File
– A Link File is created by the system when a symbolic link in
created to an existing file.
• Special (Device) File
– A special File is a means of accessing hardware devices,
including the keyboard, hard disk, CD-ROM drive, tape drive
and printer.
• Character Special Files
– Correspond to character-oriented devices (e.g., Keyboard)
• Block Special Files
– Correspond to block-oriented devices (e.g., a disk)
• Named Pipe (FIFO)
– Tools that enable processes to communicate with each other

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


File System Structure

• File System Organization


• Home and Present Working Directories
– $HOME, ~
– pwd, ., ..
• Pathnames: Absolute and Relative
• Some Standard Directories and Files
– Root directory (/), /bin, /dev, /etc,/lib…

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


A Typical UNIX File System
Structure

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Navigating the File Structure
• Determining the Absolute Pathname for Your Home Directory
– echo [string]
• Browsing the File System
– cd [directory]
– ls [options] [pathname-list]

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Navigating the File Structure
(Contd)

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Navigating the File Structure
(Contd)

• Creating Files
– pico, vi, emacs
• Creating and Removing Directories
– mkdir [options] dirnames, rmdir [options]
dirnames
• Determining File Attributes
ls –l, ls –i , ls –al

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Navigating the File Structure
(Contd)

ls -F
*; executable

/
@
|
=

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Navigating the File Structure (Contd)
$ ls -i
12329 courses 22876 memos 12487 personal
$ ls -al ~/courses/ee446/exams
drwxr-x-- 1 sarwar faculty 512 Mar 16 08:24 .
drwxr-x-- 1 sarwar faculty 512 Jan 29 13:27 ..
-rwxr--r-- 1 sarwar faculty 1863 Mar 16 11:10 mid1
-rwxr--r-- 1 sarwar faculty 459 Apr 11 14:34 mid22
drwxrwxrwx 1 sarwar faculty 512 May 12 23:44 solutions
$ ls -F /
bin/ dev/ etc/ install@ lost+found/ tmp/ usr/ unix*
$ ls -l ~/courses/ee446/lab[^5]*.c
...
$ ls ~/[^0-9]*.[c,C]
...
$

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Determining the Type of a File’s
contents
• file [options] file-list
$ file /*
all.backup: POSIX tar archive
bin: directory
dev: directory
etc: directory
install: symbolic link to var/lib/LST
lost+found: directory
tmp: directory
usr: directory
unix: ELF 32-bit LSB executable
$

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


File Representation and Storage
in UNIX

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


File Representation and Storage in
UNIX

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Standard Files and File
Descriptors

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Standard Files and File
Descriptors (Contd)

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Viewing Contents of Text Files
• Viewing Complete Files
– cat [options][file-list]

• Viewing files One Page at a Time


– more [options][file-list]

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Viewing Contents of Text Files (Contd)
• Viewing the Head or Tail of a File
– head [option][file-list]
– tail [option][file-list]

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Copying, Moving and Removing Files

• Copying Files
– cp [options] file1 file2
• Options: -f, -i , -p, -r

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Copying, Moving and Removing
Files (Contd)
• Moving Files
– mv [options] file1 file2
– mv [options] file-list directory

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Copying, Moving and Removing
Files (Contd)
• Removing/ Deleting Files
– rm [options] file-list

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Copying, Moving and Removing Files
(Contd)

• Determining File Size


– ls –l

– wc [options] file-list

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Appending to Files and Comparing
Files

cat [file-list] >> destination-file


diff [options][file1][file2]

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Comparing Files

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Removing Repeated Lines
uniq [options][+N][input-file][output-file]
$ cat sample
This is a test file for the uniq command.
It contains some repeated and some nonrepeated lines.
Some of the repeated lines are consecutive, like this.
Some of the repeated lines are consecutive, like this.
Some of the repeated lines are consecutive, like this.
And, some are not consecutive, like the following.
Some of the repeated lines are consecutive, like this.
The above line, therefore, will not be considered a repeated
line by the uniq command, but this will be considered repeated!
line by the uniq command, but this will be considered repeated!
$ uniq sample
This is a test file for the uniq command.
It contains some repeated and some nonrepeated lines.
Some of the repeated lines are consecutive, like this.
And, some are not consecutive, like the following.
Some of the repeated lines are consecutive, like this.
The above line, therefore, will not be considered a repeated
line by the uniq command, but this will be considered repeated!
$

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Removing Repeated Lines
uniq [options][+N][input-file][output-file]
$ uniq -c sample
1 This is a test file for the uniq command.
1 It contains some repeated and some nonrepeated lines.
3 Some of the repeated lines are consecutive, like this.
1 And, some are not consecutive, like the following.
1 Some of the repeated lines are consecutive, like this.
1 The above line, therefore, will not be considered a repeated
2 line by the uniq command, but this will be considered repeated!
$ uniq -d sample
Some of the repeated lines are consecutive, like this.
line by the uniq command, but this will be considered repeated!
$ uniq -d sample out
$ cat out
Some of the repeated lines are consecutive, like this.
line by the uniq command, but this will be considered repeated!
$

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.


Reference
Unix: The Textbook 2nd Edition

You might also like