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.
-
cdinto your home directory. Then usepwdandlsto "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.txtinto your home directory using thecpcommand.The
cpcommand 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.txtHere 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
lsto see if your copy was successful.$ ls welcome.txt -
Use
catto list the contents of thewelcome.txtfile.$ cat welcome.txt Welcome to CS21! ... -
If you have successfully run
update21then 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
cdto move into yourcs21/inclassdirectory. Usepwdto "see" where you are.$ cd cs21/inclass $ pwd /home/yourusername/cs21/inclass -
Use
cpto copy thewelcome.txtfile from your home directory into yourcs21/inclassdirectory. Uselsto see if the file was successful copied.The
cpandmvcommands 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.txtin this example, but I could also change its name to something else:$ cp /home/yourusername/welcome.txt welcome.txtHere 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 ./
-