0% found this document useful (0 votes)
71 views44 pages

3D Geometry 2018

This document discusses various file handling commands in Unix/Linux such as cat, more, less, cp, mv, rm, pwd and ls. It explains how to use these commands to display, copy, rename, delete and navigate files and directories. The document also discusses the hierarchical structure of files and directories in Unix filesystem and concepts such as absolute and relative pathnames.

Uploaded by

divya suvarna
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)
71 views44 pages

3D Geometry 2018

This document discusses various file handling commands in Unix/Linux such as cat, more, less, cp, mv, rm, pwd and ls. It explains how to use these commands to display, copy, rename, delete and navigate files and directories. The document also discusses the hierarchical structure of files and directories in Unix filesystem and concepts such as absolute and relative pathnames.

Uploaded by

divya suvarna
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/ 44

Nisha Roche

Asst. Prof
Dept of CSE, SJEC
In this chapter
 Initial categorization of files
 Features of unix filename
 Hierarchical structure containing files and directories
 Parent child relationship
 Significance of home directory and HOME variable
 cd and pwd command
 mkdir and rmdir
 Absolute and relative pathnames
 Using ls command
Class Objective
 Understand the meaning of a file and its categories
 Valid filename
 Parent-Child Relationship
 The HOME Variable
 Pwd
 Cd
 mkdir/rmdir
 Absolute Pathnames
The File
 File is a container for storing information
 Unix file doesn’t have eof(enf of file) mark
 All file attributes are kept in a separate area of the hard
disk, accessible by the kernel
Naming File

 In Unix system, a filename can be max of 255


characters.
 May or may not have extensions
 Can consist of any ASCII Character except the / and
the NULL Character(ASCII Value 0).
 Can include control characters as well as unprintable
characters.
Best Practices for filenames
 Alphabetic Characters and numerals
 The period(.), hyphen(-) and underscore(_)

Never use “ –” at the beginning of a filename.

Eg: -p (shell interprets it as option)


Did you Know?
 Unix Does not impose any restrictions on the
extensions, It is the compiler which imposes
restrictions.
 Eg: .c (c files), .txt(text files) .sh(shell programs)
 A file can have as many dots embedded in its name.
 Eg: .a.b.c . , .a.b.c,
 Unix is case sensitive
 Eg: chap02, CHAP02
Three Categories of files
 Ordinary file
All programs that we write belongs to this file
 Directory File
Contains files and other directories
Actually it contains file name and a unique number
 Device File
All devices and peripherals are represented by files.
Eg: device drivers
Three Categories of files
Ordinary file
 Text File
 Contain only printable characters
 C, Java programs, pearl scripts are text files

Binary File
 Contains both printable and unprintable characters
that cover the ASCII range(0 to 255)
 Eg: Unix commands and object codes
Directory File
Every directory consists of filename and a unique
number-inode number
Device Files
 Device files are found under /dev directory
 All devices and peripherals are represented by files.
Eg: device drivers
Class Objective
 Parent child relationship
 Significance of home directory and HOME variable
 cd and pwd command
 mkdir and rmdir
 Absolute and relative pathnames
Parent Child Relationship-The Unix
File System Tree
The Home and PWD command

 The shell variable HOME knows your home directory.

 $ echo $ HOME
 /home/staff

 PWD: Checking your current Directory


 $ pwd (present working Directory)
 /home/staff
cd: changing the current Directory
 Cd command can be used to move around in the file
system.

 When used with an argument it changes the current


directory to the directory specified as argument.

 Cd command can be used without arguments


mkdir: Making Directories
 Directories are created with the mkdir command.
 Eg: mkdir patch

 mkdir patch dbs doc //Three Directories created.

 mkdir rahul rahul/progrs rahul/data //creates the


directory tree.
 mkdir rahul/data rahul/progs
rahul ERROR

Possible reasons for failure of directory creation


 Directory with a particular name might already
exist
 There may be an ordinary file by that name in the
current directory
 Permissions set for the current directory doesn’t
permit the creation of files and directories by the
user.
rmdir: REMOVING DIRECTORIES
 rmdir ( remove directory) command removes
directories.

 rmdir rahul //directory must be empty

To delete directory and subdirectory


 rmdir rahul/data rahul/progs rahul
Absolute Pathnames and Relative
Pathnames
 Refer class notes
Using . and ..
 Refer class notes
Reflection on the previous class
 Absolute and relative pathnames
 Using . And ..
 $PATH
Identify the directory?

Ans: Home directory


The ls command
 Used to list all the filenames in the current directory

 Can you list the options for $ ls?


 -a
 -l
 -u
 -r
 -t
Other ls options
 Output in Multiple Columns(-x):
 Allows to display filenames in multiple columns.
 Syntax: ls –x
Other ls options
Identifying Directories and executables (-F):
 Used to identify Directories and executable files in
addition to file names.
 $ls –Fx

 * indicates executable code


 / directory
Other ls options
 Showing hidden files (-a)
 ls command normally doesn’t show hidden files in a
directory. To view the hidden files in the home
directory –a option can be used.

Syntax:$ls –axF
Other ls options
 Listing Directory Contents:
 Syntax: $ ls –x directoryname1,directory name2……
 $ ls –x helpdir progs
Other ls options
 Recursive Listing(-R)
 The –R(recursive) option lists all files and
subdirectories in a directory tree.
 $ ls –Rx
Chapter 5
Handling Ordinary Files
Topics in this chapter
 View text files with cat and more command
 Cat to create file
 Copy,remove and rename commands.
 Count the number of lines , words and characters
 Display ASCII octal value of text with od
The display.txt and display1.txt file
originally contains the following information
 Output of display.txt

 Output of display1.txt
Cat command can be used for the
following purposes
 used to Displaying contents of files
$ cat display.txt

 Display contents of multiple files:


Displays contents of second file immediately after
displaying content of first file
Cat command can be used for the
following purposes
 Used to create new files
cat > foo // blank file foo gets created
$ cat
 Cat is a versatile command . It can be used to create,
display, concatenate and append to files.
 Cat command can also be used to send the data from
one file to anothe
 cat display.txt> display1.txt // if the display1.txt file
already exists then after execution of the above
command the display1.txt content will be overwritten.
$ cat options
There are 2 cat options
1. Displaying Non printing Characters(-v):
 Normally used to display text files
 When used with –v option displays nonprinting ASCII
characters in the input

 Syntax: $ cat -v
$ cat options
2. Numbering Lines(-n): cat –n numbers lines in a
program.
 Helps the programmer while debugging
Copy Command
 Used to copy files or group of files
 Creates a exact duplicate copy with a different file
name
 Requires minimum 2 file names.
Predict the output: Assume the
PWD to be USP

$ cp display.txt play.txt
Copy display.txt to play.txt

$ cp display.txt display.txt

error
The $rm command: Remove files
Uses
 Used to delete a single file
 Used to delete multiple files
 Used to delete files and subdirectories
mv command
 2 distinct features
 It renames a file (directory)
 Eg: mv display.txt screen.txt

 It moves a group of files to a different directory


 mv display.txt discover.txt chap03 kapoor
 Here kapoor is a directory
mv: Renaming files
Can be used to rename a directory
 mv kumar Rao //Assuming Rao directory doesn’t
exist.

 If Rao directory exists then kumar becomes a


subdirectory

 -i and R options are available with mv command also


The Pager Program
 Paging program, is a computer program used to view
(but not modify) the contents of a text file by moving
down the file one line or one screen at a time.

 Not all, pagers allow movement in a file


The Pager Program
 2 types of pager programs
 more
Allows to move one line at a time but cannot move
backwards
PAGER=more;export PAGER
man ls Set the shell variable PAGER to
use less as its pager and export
it. Then run man command
 less
Allows both forward and backwards in text files
PAGER=less;export PAGER
man ls
More: paging output
 Man command displays output one page at a time
 Unix offers more pager
 Linux offers more but less is the standard pager.

 Eg more display.txt

 ----more—(17%)
 which means 17% of the document “display.txt” is
shown on screen.
Navigation
 f or spacebar to move forward
 b to move backward

 Repeat factor:
 10f //10 pages move ahead
 10b //10 pages move backwards
 2f // 2 pages move forward

You might also like