Lab3

advertisement
CMPT 183 Lab 3
Unix Commands & Utilities
OBJECTIVE: At the end of this lab you will be able to do the following:










Transfer files from a network computer to a local PC
Make a directory
Change the current directory
Go to your home directory
Go to the parent of the current directory
Print the full name of the current directory
Delete a file
Remove files & utilize the wild card
Remove a directory
Display a file without using a text editor
1. Transfer your file from your Pegasus account to the A:\ Drive
 Insert your disk into floppy drive A:
 Click “Start”, and then scroll up to “Run”
 Key in “ftp” in the Open field. You can also type
“command” and when the prompt appears type “ftp”.
 After ftp> prompt, key in “open pegasus.montclair.edu”, then
Enter. On campus, you can type just “open pegasus”
 Key in your user name, then press Enter, followed by your
password and Enter.
 After ftp> prompt, key in “lcd a:\” ,then press Enter. (This
changes the “Local Directory” to your A: drive). If you want to
transfer files from the desktop, don’t do this step.
 After ftp> prompt, key in asc, then press Enter. (This changes
the file transfer type to ascii or text files).
 Typing “dir” will list your files.
 After ftp> prompt, key in “get Lincoln.java”, then press Enter.
(This will get your file from pegasus, and place it on your floppy
disk or desktop).
 After ftp> prompt, key in “bye”, then press Enter to close the
FTP window.
2.
How to make a directory:


3.
After prompt type “mkdir filename” then press Enter
EX: “mkdir temp” then press Enter, this will make a
directory in your home directory called “temp”.
How to change the current directory:


After prompt type “cd directoryname” then press Enter.
EX: “cd temp” then press Enter, this will enter into the
directory you just created called “temp”.
4.
How to reach your home directory from anywere:


5.
How to go to the parent of current directory (up one level):


6.


After prompt type “rm filename” then press Enter.
EX: “cd ~” to get to your home directory. Type “rm
Lincoln.class” to remove an uncessary file.
How to use wild card to remove files:


9.
After prompt type “pwd” then press Enter.
EX: type “cd /” to go to the root of the file structure, then
type “pwd” to see this. Type “cd ~” to go home, and type
“pwd” to see this as well.
Another way to print the current directory is to type “cd .”
This is also how to execute files in the current directory.
How to delete a file:


8.
After prompt type “cd ..” then press Enter.
EX: “cd ~/temp” will take you to the temp directory you
created in your home directory. “cd ..” will take you up one
level, to your home directory.
How to print the present working directory:


7.
After prompt type “cd ~” then press Enter.
EX: “cd /” will take you to the root of the file system, but
how can you get back? Type “cd ~” and you will be back
home.
After prompt type “rm” followed by any combination of text
and a “*”.
EX: The “*” should be used in place of something you want
to omit. For example if you want to get rid of “.class” files
you would type “rm *.class”. If you wanted to get rid of a
text file called “script.txt” you could say “rm *.txt” or “rm
script*”. Be aware of what you are doing though! If you
have a lot of “.txt” files and you type “rm *.txt” you will
loose all of them!
How to remove directory:


After prompt type “rmdir directoryname” then press Enter.
EX: To remove the “temp” directory you created in your
home directory, type “rmdir temp” while you are presently
in your home directory.
10. How to concatenate any file :


After prompt type “cat filename” then Enter.
EX: This is just a fast way of displaying a file without needed
to open a text editor (like pico). Type cat Lincoln.java then
press Enter.
11. How to do more on any file :


After prompt type “more filename” then press Enter.
EX: This is much like cat, except “more” will display one
screen of information at a time (press the spacebar to move the
screen). Try typing “less filename” as well.
TO HAND IN:
Using your skills you learned last week in Lab 2, start a script named
“Lab3.txt”, this will be used to record your homework. Get to your home
directory, and create a directory inside of it named “temporary”. Inside of this
new directory, create a text file by the name of “test.txt”. Inside of this file just
type something, include your name in there as well. Display this file using
“more”, “cat”, or “less”. Delete this file “test.txt”, and then delete the
directory “temporary”. Stop the script, and then print it out using the print
command learned last week.
Download