Linux Commands
OK, in this
lesson we are going to learn many common UNIX commands. You are going
to learn by doing. Make sure you answer the questions as you go along.
- Login to your practice account. If you forgot how to do this, go
back to Lesson One.
- Do an "ls" to see the files you have in your directory.
- Type in "pwd" . What do you see?
- Type in "uname -a" . What do you see?
- Now, type in "clear" . What happens?
- Please type in "man pwd" . What do you see? Use the spacebar
to scroll through, and press "q" to quit.
- Now type in "mkdir" . What happens?
- Now type "mkdir labpractice"
- Type "ls". Now what do you see?
- Type "cd labpractice".
- Type "pwd". Where are you now?
- Type "touch lab3file".
- Type "ls". What do you see now?
- Type ls with an -al switch. What do you see? Can you tell how big
the file is?
- Type "cp lab3file lab3file2" . Again, type "ls".
What do you see now?
- Type "rm lab3file2". Again, type "ls". What
is there?
- Repeat the "rm" command on the other file. Do an "ls
-al" to see what's in the directory. Hint: It should be empty.
- Type in "cd .." Take note. That is cd plus a space, plus
two periods. This should bring you back up one directory and put you
in your home directory.
- Type "ls" and then type "rm labpractice" . What
happens?
- Type "rm -r labpractice" and then do an "ls".
What happens this time?
- Type "mkdir public_html".
- Type "mkdir Desktop".
- Type "cd Desktop", and then type "touch file1 file2 file3 file4 file5".
- You are done.
The following is a list of
this lesson's commands. You can use this as a reference for the practice
lab.
| ls |
Lists files. The equivalent of "dir" in DOS. Common switches are -al which will list all files with a long description, including their permissions, size, and datestamp. You can also type in ls -al followed by a specific filename to learn information about that specific file. This is helpful if you have many files within a directory and you only want information on one of them. You can even use wildcards. For example, ls *.html show only files with extension .html
|
| uname -a |
Show info about current machine and operative system |
| pwd |
Print Working Directory. Wonder which directory you're currently in? This reveals full path. |
| clear |
clear the screen |
| touch |
touch filename.
If filename doesn't exist it gets created (0 byte). If filename already exists, touch alters its timestamp to the current time. Please note, in UNIX we can not easily name files with spaces in them, so words should use underscores or a capital letter to separate them. For example, touch my file will not work. You must write either touch myFile or touch my_file . This applies to creating directories as well. |
| mkdir |
makes a directory. You can put files in a directory :) |
| rmdir |
removes an empty directory. If it is not empty,
you can use rm -rf instead. |
| rm |
removes files. You can use it with wildcards too.
For example rm -f *.html will remove all html files in the directory. You can use it to remove a directory with an -rf switch. However, this is not the ideal way to remove directories.
|
| cp |
cp originalFile newFile Creates a copy of the first file having the name of the second. If the paths are not specificied, then cp assumes you mean the current working directory. You can also copy a file to another location. For example, cp OriginalFile /home/someDirectory/newFile will copy a file from the current directory to another directory with "NewFile" as it's name. If no name is specified, and you are copying the file to another directory, then the original filename will be used. |
Now for the Lab Assignment:
Log on to your UNIX account. Make a directory named using your first and last name. Inside that directory, create 2 files, one for your first name and one using your second name. Issue a command to see these files' time stamps. After that, update the timestamps.
NEXT LESSON
|