Basic Unix Tutorial
So in consideration for some new and/or transfer students who may not
be entirely familiar with UNIX, I created this brief tutorial with some
common commands as well as some concepts that will help you get along.
If you have any other questions, you can send me an email at:
wreasor@ucsd.edu
Common Commands / Quick Ref
Command | Description | Example Usage |
ls | Prints to contents of the current directory | mylogin% ls |
pwd | Shows the current directory | mylogin% pwd |
cp < arg1, arg2 > | Copy file in arg1 to path in arg2 |
mylogin% foo.java ../foo2.java |
rm < file to remove > | Removes the specified file | mylogin% rm ../projects/spam.txt |
mkdir |
Creates a directory to store data .. Same as a 'folder' in Windows | mylogin% mkdir mystuff |
cd < path > | Changes working directory to specified path | mylogin% cd ../../morestuff |
Working with your account
Now we are going to apply some of the commands listed above. For this, let's refer to the diagram below which is a sample
representation of the file structure in a random account.
-------HOME-------
/ \
mystuff assignments--------
| | \
foo.txt ni.java P0
ni.class |
P0.java
P0.class
Or a heirarchial view of the visual representation above is:
HOME
|---- mystuff
| |---- foo.txt
|
|---- assignments
|---- ni.java
| ni.class
|
|---- P0
|---- P0.java
P0.class
Ok, so we are going to start in the 'HOME' directory, and we want to go straight to the P0 directory to do some work there.
We would use the following command. Note that the actual command is in bold:
mylogin% cd assignments/P0
Now, if we type in pwd, we will see that we are indeed in the P0 directory. It is important to note the following when working with
directories in UNIX:
- Spaces matter. Saying cd assignments/P0 is NOT the same as saying cd assignments/ P0
- Capitalization matters. Saying cd assignments/P0 is NOT the same as saying cd assignments/p0
Now we are in the 'P0' directory. Well, we decided that we no longer need the 'P0.class' file, so let's remove it. We would use the
following command:
mylogin% rm P0.class
It's gone now, and our structure looks like this.
-------HOME-------
/ \
mystuff assignments--------
| | \
foo.txt ni.java P0
ni.class |
P0.java
Let's make a backup copy of P0.java and put it in the mystuff directory. Here, I will introduce the ~ shortcut, which refers to your
designated home directory, in this case, it is 'HOME'.
Method 1:
mylogin% cp P0.java ../../mystuff/P0.java
Method 2:
mylogin% cp P0.java ~/mystuff/P0.java
More important notes on working with directories:
- . refers to the current directory.
- .. refers to the parent directory.
- ~ refers to your designated home directory.
Whatever method we use, we now made a backup copy of P0.java, and put it in the 'mystuff' directory, so that the stucture is now as
follows:
-------HOME-------
/ \
mystuff assignments--------
| | \
foo.txt ni.java P0
ni.class |
P0.java P0.java
Well, we made a backup copy of P0.java and put it in mystuff. Now, we want to make another copy of P0.java to be placed
in the P0 directory, change the name of it to P1.java, and then delete the original P0.java that is there. This is what we would do, from
the P0 directory:
mylogin% cp P0.java ./P1.java
mylogin% rm P1.java
Notice how for arg2 in the cp command, you can give it whatever name you want. Anyways, here is our structure:
-------HOME-------
/ \
mystuff assignments--------
| | \
foo.txt ni.java P0
ni.class |
P0.java P1.java
That should get you going on UNIX enough where you can at least perform basic operations needed. Feel free to learn more about this, as it
can only help you in the long run.