Вы находитесь на странице: 1из 16

Unit 5

Using Files

Objectives
After completing this unit, students should be able to:
Copy, rename and remove files
Use the wc command
Link files
Display the contents of a file with different commands
Print files

Copying Files
cp source target
cp file1 file2 ... target_dir
To copy the file /home/team03/pgms/suba to /home/team01/doc and
name it programa:
$ pwd
/home/team01/doc
$ cp /home/team03/pgms/suba programa
home

home

team01

team01

doc

doc
mon_report
trio_ltr
walrus

mon_report
programa
trio_ltr
walrus

Examples cont...
$ cd /home/team01
$ cp doc/programa test1 c
home

home

team01

team01

doc
programa

.profile
manuals
test1

doc
programa

programa
test1

$ cd /home/team01/doc
$ cp trio_ltr ../c

home

home

team01

team01

doc

c
trio_ltr

doc
trio_ltr

trio_ltr

.profile
manuals
test1

Moving and Renaming Files


mv source target

$ pwd
/home/team01/c
$ mv trio_ltr t.letter

home

home

team01

team01

c
trio_ltr

t.letter

Examples cont...
$ pwd
/home/team01/c
$ mv t.letter ../doc/letter
home

home

team01

team01

doc
t.letter

doc
trio_ltr
letter

trio_ltr

$ pwd
/home/team01/c
$ mv ../doc/mon_report .

home

home

team01

team01
doc
mon_report

doc
mon_report

Listing File Contents


cat file1 file2 ...

$ cat walrus
"The time has come," the Walrus said,
"To talk of many things:
Of shoes - and ships - and sealing wax Of cabbages - and kings And why the sea is boiling hot And whether pigs have wings."
From The Walrus And The Carpenter
by Lewis Carroll (1871)

Displaying Files
pg filename
more filename

$ pg walrus

(or)

$ more walrus

"The time has come," the Walrus said,


"To talk of many things:
Of shoes - and ships - and sealing wax Of cabbages - and kings And why the sea is boiling hot And whether pigs have wings."
:
<Enter>

one page at a time

wc Command
The wc command counts the number of lines, words and bytes in a
named file:
$ wc [-c] [-l] [-w] filename

Options:
-c
counts the number of bytes
-l
counts lines
-w
counts words
Example:
$ wc myfile
17

126

1085 myfile
characters
words
lines

Activity: Working with the wc Command

Activity

Linking Files
ln source_file target_file
The ln command allows one file to have more than one
name:
$ pwd
/home/team01
$ ln manuals /home/team02/man_files

Both copies use the same inode

Removing Files
rm file1 file2 file3 ...
$ ls
mon_report

trio_ltr

walrus

$ rm mon_report
$ ls
trio_ltr

walrus

-i: Remove a file interactively


$ rm -i walrus
rm: Remove walrus: y
$ ls
trio_ltr

Printing Files
To queue files to the printer use the qprt command:
$ qprt filename filename2 filename3 ....

The qchk command displays the current status of a print queue:


$ qchk
Queue Dev Status Job Files
lp0
lp0 Running 99 walrus

User
PP %
team01 1

To cancel your print job use the qcan command:


$ qcan -x 99

Job number

Blks
1

Cp
1

Rnk
1

Next Step ...

Exercise 4

Unit 5: Checkpoint
1. What is the effect of the following commands?
$ cd /home/team01
$ cp file1 file2
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
2. What is the effect of the following commands?
$ cd /home /team01
$ mv file1 newfile
_____________________________________________________________
_____________________________________________________________
3. What is the effect of the following commands?
$ cd /home /team01
$ In newfile myfile
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
4. List commands that can be used to view the contents of a file.
_____________________________________________________________

Summary
The cp command can be used to copy files
The mv command can be used to move and rename files
The In command can be used to create additional names
for a file
Display the contents of a file using cat, pg or more
Use the rm command to delete files
Use the qprt command to print files
The wc-command could be used to count words or lines
from files or command output

Вам также может понравиться