Solution to Lab 0 4.1 "Try it Out":
In the examples below, $
is the shell prompt, and anything after #
is
a comment with some additional information about the command.
-
cd
into your home directory. Then usepwd
andls
to "see" where you are, and to list a directory’s contents.$ cd # cd with no argument goes to your home directory $ pwd # should list /home/yourusername/ $ ls
-
Copy the file from
~admin21/public/welcome.txt
into your home directory using thecp
command.The
cp
command takes two command line arguments: the path name of the source file to copy; and the path name of the destination file (cp source dest
). We show two different ways to specify the source and destination file for this operation.$ cp ~admin21/public/welcome.txt welcome.txt
Here is another way of doing this using
./
which is shorthand for the current directory The syntax below copies from the source to current location:$ cp ~admin21/public/welcome.txt ./
-
Run
ls
to see if your copy was successful.$ ls welcome.txt
-
Use
cat
to list the contents of thewelcome.txt
file.$ cat welcome.txt Welcome to CS21! ...
-
If you have successfully run
update21
then try this:-
List the contents of your
cs21/
directory.$ cd # cd into your home directory $ ls cs21 # list contents of your cs21 subidrectory for_staff/ inclass/ labs/
-
Use
cd
to move into yourcs21/inclass
directory. Usepwd
to "see" where you are.$ cd cs21/inclass $ pwd /home/yourusername/cs21/inclass
-
Use
cp
to copy thewelcome.txt
file from your home directory into yourcs21/inclass
directory. Usels
to see if the file was successful copied.The
cp
andmv
commands takes two command line arguments: the path name of the source file to copy/move, and the path name of the destination file (cp source dest
). We show three different ways to specify the source and destination file for this operation.Here is one way to do it. I’m naming the destination file
welcome.txt
in this example, but I could also change its name to something else:$ cp /home/yourusername/welcome.txt welcome.txt
Here is another way to do it using some shorthand notation.
~/
is shorthand for/home/yourusername/
, and./
is shorthand for the current working directory. The syntax below moves the file from your home directory (~/
) into the current directory (./
):$ cp ~/welcome.txt ./
Here is yet another way to do it. The path
../
is shorthand for the parent directory of the current directory, so../../
is the parent of the parent ofcs21/inclass/
, which is your home directory.$ cp ../../welcome.txt ./
-