0% found this document useful (0 votes)
3 views18 pages

Using Files

This document provides an overview of file management commands in IBM Power Systems, including how to copy, move, rename, count, link, display, remove, and print files. Key commands discussed are cp, mv, wc, ln, cat, pg, more, rm, and qprt. The document also includes examples and exercises to reinforce understanding of these commands.

Uploaded by

amzianimokrane
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)
3 views18 pages

Using Files

This document provides an overview of file management commands in IBM Power Systems, including how to copy, move, rename, count, link, display, remove, and print files. Key commands discussed are cp, mv, wc, ln, cat, pg, more, rm, and qprt. The document also includes examples and exercises to reinforce understanding of these commands.

Uploaded by

amzianimokrane
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/ 18

Using files

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp 8.1
Unit objectives
IBM Power Systems

After completing this unit, you should be able to:


• Use the cp command to copy files
• Use the mv command to move or rename files
• Use the wc command to count the number of lines, words,
and bytes in a named file
• Use the ln command to allow a file to have more than one
name
• Display the contents of a file using the cat, pg, and more
commands
• Use the rm command to remove files
• Print files

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Copying files
IBM Power Systems

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

before home home


after
team01 team01

doc doc

mon_report
trio_ltr mon_report
walrus programa
trio_ltr
walrus
© Copyright IBM Corporation 2010, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
cp examples
IBM Power Systems

$ cd /home/team01
$ cp doc/programa test1 c
home home
team01 team01
.profile .profile
c doc manuals c manuals
doc
test1 test1
programa programa programa
test1

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

c doc c doc
trio_ltr trio_ltr trio_ltr
© Copyright IBM Corporation 2010, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Moving and renaming files
IBM Power Systems

mv source target
mv file1 file2 ... target_dir

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

home home

team01 team01

c c

trio_ltr t.letter

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
mv examples
IBM Power Systems

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

home home
team01 team01

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

home home
team01 team01

c doc c doc
mon_report mon_report

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Listing file contents
IBM Power Systems

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)

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Displaying files
IBM Power Systems

pg filename
more filename
$ pg 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>
$ 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."
One page at a time walrus (100%) <Enter>

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
wc command
IBM Power Systems

• 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
© Copyright IBM Corporation 2010, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Activity: Working with the wc command
IBM Power Systems

Activity

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Linking files (1 of 2)
IBM Power Systems

ln source_file target_file

• Allows files to have more than one name in the directory structure.
• Both files reference the same i-node.
• Cannot be used with directories. Cannot span file systems.
$ ls –li
63 -rw-r--r-- 2 team01 staff 1910 Nov 21 14:19 man_files

$ ln man_files manuals

$ ls -li
63 -rw-r--r-- 2 team01 staff 1910 Nov 21 14:19 man_files
63 -rw-r--r-- 2 team01 staff 1910 Nov 21 14:19 manuals

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Linking files (2 of 2)
IBM Power Systems

ln –s source_file target_file

• Creates an indirect reference to a file (symbolic link)


• Name references the original file’s name and path.
• Can be used with directories and span file systems.
$ ls –li
63 -rw-r--r-- 2 team01 staff 1910 Nov 21 14:19 man_files

$ ln –s man_files manuals

$ ls -li
63 -rw-r--r-- 1 team01 staff 1910 Nov 21 14:19 man_files
66 lrwxrwxrwx 1 team01 staff 1910 Nov 21 14:19 manuals -> man_files

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Removing files
IBM Power Systems

rm file1 file2 file3 ...

$ ls
mon_report trio_ltr walrus

$ rm mon_report
$ ls
trio_ltr walrus

$ rm –i walrus
rm: remove walrus?y

$ ls
trio_ltr

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Printing files
IBM Power Systems

• qprt: Queue files to the printer


• qchk: Display the current status of a print queue
• qcan: Cancel a print job (specify job number)

$ qprt walrus

$ qchk
Queue Dev Status Job Files User PP% Blks Cp Rnk
lp0 lp0 Running 99 walrus team01 1 1 1 1

$ qcan –x 99

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Checkpoint
IBM Power Systems

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
$ ln newfile myfile

4. List commands that can be used to view the contents of a file.

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Checkpoint solutions
IBM Power Systems
1. What is the effect of the following commands?
$ cd /home/team01
$ cp file1 file2
The answer is the cp command creates a new file, file2, from a copy of file1.
Each copy will have a different name, as shown, file1 and file2. The two
copies are independent of each other. If one file is modified, it does not reflect in
the second file.
2. What is the effect of the following commands?
$ cd /home/team01
$ mv file1 newfile
The answer is these commands will rename file1 to newfile. file1 will no
longer exist, but instead be shown as newfile.
3. What is the effect of the following commands?
$ cd /home/team01
$ ln newfile myfile
The answer is the file called newfile is now know as myfile. An ls -l will
show both files. An ls –li will show that both files share the same node
number. Note that there is still only one physical file on disk. If a change is made
to newfile that change will also be reflected if using myfile.
4. List commands that can be used to view the contents of a file.
The answers are cat, pg, and more.
© Copyright IBM Corporation 2010, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Exercise: Using files
IBM Power Systems

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp
Unit summary
IBM Power Systems

Having completed this unit, you should be able to:


• Use the cp command to copy files
• Use the mv command to move or rename files
• Use the wc command to count the number of lines, words,
and bytes in a named file
• Use the ln command to allow a file to have more than one
name
• Display the contents of a file using the cat, pg, and more
commands
• Use the rm command to remove files
• Print files

© Copyright IBM Corporation 2010, 2013. All Rights Reserved.


US Government Users Restricted Rights - Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp

You might also like