CS101 Lecture 9 - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

CS101 Lecture 9

Description:

i For each file in the list, the user is asked whether or not to delete. -r Deletes a directory and every file or directory in it. ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 25
Provided by: tomga
Category:

less

Transcript and Presenter's Notes

Title: CS101 Lecture 9


1
Lecture 9
2
What will I learn in this lecture?
How do you copy/move/rename/remove files? How
do you create a directory ? What is redirection
and piping? Readings See CCSOs Unix pages
and
3
Unix file commands (copy) - cp
cp option file1 file2 First Version This
is one version of the cp command. file2 is
created and the contents of file1 are copied into
file2. If file2 already exits, it will be
replaced with a new one. where option is -i
Protects you from overwriting an existing file by
asking you for a yes or no before
it copies a file with an existing name. -r Can
be used to copy directories and all their
contents into a new directory
4
Unix file commands (copy) - cp
cp file1 file2 file3 dirname Second
Version This version copies the files file1,
file2, file3, into the directory dirname.
5
Unix file commands (copy) - cp
cs101
jsmith
data
mp1
pwd
FILES mp1_data.m, mp1.m
Copy the file named mp1_data.m from the
cs101/data directory into the pwd.
gt cp cs101/data/mp1_data.m .
The (.) dot means here, that is, your pwd.
6
Unix file commands (copy) - cp
cs101
jsmith
pwd
data
mp1
FILES mp1_data.m, mp1.m
Copy the file named mp1_data.m from the
cs101/data directory into the mp1 directory.
gt cp cs101/data/mp1_data.m mp1
The (.) dot means here, that is, your pwd.
7
Unix file commands (copy) - cp
Example To create a new directory named temp
and to copy the contents of an existing
directory named mp1 into temp, gt cp -r mp1
temp This is useful to make a backup copy of
your mp1 files.
8
Unix file commands (move) - mv
mv option file1 file2 First Version This
is one version of the mv command. file1 is
renamed file2. where option is -i Protects you
from overwriting an existing file by asking you
for a yes or no before it copies a file with an
existing name.
9
Unix file commands (move) - mv
mv dirname1 dirname2 Second Version In
this version dirname1 is renamed dirname2
10
Unix file commands (move) - mv
mv file1 file2 file3 dirname Third
Version The files file1, file2, file3, are moved
into the directory dirname.
11
Unix mv command
jsmith
pwd
mp2
temp
source
FILES mp2.c, mp2.h
FILES stat.c, input.dat
FILES edit.c
Move all the files with .c suffix from the temp
directory tothe mp2 directory.
gt mv temp/.c mp2
Move the input.dat file into the home directory.
gt mv source/input.dat .
12
Unix file commands (remove) - rm
rm option file1 file2 file3 The rm
command removes (deletes) each file in the
list. where option is -i For each file in the
list, the user is asked whether or not to
delete. -r Deletes a directory and every file
or directory in it. Example To delete a
directory named temp and all its contents, gt rm
-r temp Where temp is a subdirectory of the
present working directory. Be very careful
in using this command!!!
13
Unix file commands (make directory) - mkdir
mkdir dirname The mkdir command makes a
subdirectory named dirname in the present
working directory. Lab assignment Create a
directory named lab2 as a subdirectory of your
home directory. Assuming that you are in your
home directory, type gtmkdir lab2 The mkdir
creates a new directory but it does not cd for
you.
14
Unix find command
jsmith
pwd
workspace
mp2
FILES mp2.c, main.c
mp2
Find all files named mp2.c .
FILES mp2.c, main.c
gt find -name mp2.c -type f
Find all directories named mp2 .
gt find -name mp2 -type d
15
Unix tar command with gzip
mp2
pwd
FILES mp2.c, input.c , stat.c, mp2.h,
You want to email your lab TA and send him/her
all your files in the mp2 directory.
gt tar -czvf blah.tar.gz
creates a file named blah.tar.gz
When your TA receives this file he/she can
extract its contents by typing
gt tar -xzvf blah.tar.gz
16
Piping
Links commands to commands. Pipes are used to
direct the output of one command to the input of
the second. Unix uses the vertical bar
symbol to perform piping. General form gt
command1 command2
17
Piping
Example when you use the ls command to list the
contents of a directory the output may not fit on
one full terminal screen. Since the screen
scrolls you may not see the first part of the
output. Use a pipe to solve this problem gt ls -la
more
18
Redirection
Links commands to a file. Redirection is used to
take information that would normally be seen on
the screen and funnels it to a file or vice
versa. Unix uses the gt or lt symbols to
perform redirection. General form gt command gt
filename output redirected to file filename gt
command lt filename input from file filename
not keyboard
19
Redirection
Example you can send the output from the ls
command to a file screen.txt . You can then
use xemacs to edit the file. gt ls -la gt screen.txt
20
Unix - useful commands
passwd - change your password clear - clears the
terminal screen leaving the prompt gt whoami -
identity of the user man command - manual of
information concerning command for example,
type in man finger to find all the
options available for this command.
21
Unix - alias command
alias abbreviation command provides an alias for
a command. For example, if you type, gt alias
dir ls -la then dir is an alias for ls
-la so if you type, gt dir this is the
same as typing in gt ls -la To make this
change effective each time you login, xemacs the
.cshrc file and type in the alias command. When
you add a line at the end of the .cshrc file
terminate the line by typing ltreturngt.
22
Unix - alias command
alias abbreviation command1 command2
provides an alias for compound commands For
example, if you type, gt alias dir ls -la
more then dir is an alias for ls -la
more so if you type, gt dir this is the
same as typing gt ls -la moreand this command
displays the contents of the pwd one screen at a
time.
23
Unix - alias command
alias abbreviation command1 \! command2
provides an alias for compound commands and
passes an argument. For example, if you type, gt
alias dir ls -la \! more then gt
dir lab1 is the same as typing in gt ls
-la lab1 more and this command displays the
contents of the subdirectory of the pwd named
lab1, one screen at a time.
24
What have I learned in this lecture?
How tocopy- cp/move - mv/rename - mv/remove-rm
files. Use the mkdir command to create a
directory. Redirection - uses the lt or gt
symbol. By default, most commands expect input
data from the keyboard and output data goes to
the monitor. Using redirection symbols, you can
specify that the input comes from a file and
output goes to a file. Piping - uses the
symbol. Output data from one command can be piped
as into to another command.
Write a Comment
User Comments (0)
About PowerShow.com