UNIX Commands
( Working with Directories)
1. pwd (Print Working Directory)
The basic tool to move around files and directories is the commandpwd, which prints the name of the directory you are working in.
<machine>% pwdThis says that you are working in the directory cs240B, in the directory usr, which in turn is in the home directory.
/home/usr/cs240B
2.Making a directory
It's always convinient to arrange all the files related to the same project in one directory. You can create a new directory by using the command
mkdir. Typemkdirfollowed by the name of the directory you want to create at the prompt. It is also easier compile all the files using Makefile if they are in the same directory.e.g.: To make a directory "cs561" type
<machine>% mkdir cs5613.Removing a directory
To remove a directory type
rmfollowed by the name of the directory. You can remove a directory if and only if it is empty. If the directory has any contents UNIX will not allow you to remove the directory, you will have to delete all the contents of the directory and then erase it.e.g.:- to remove the directory cs506 type
<machine>% rmdir cs5064.Changing the Directories :
1. To change from one directory to another we use the command
cdwhich stands for change directory.Type cd followed by the directory name if it is in the working directory or by including the full path of the directory you want to change to.e.g. if you want to enter the directory cs240B type
cd /home/usr/cs240Bif the directory is in the current directory then you don’t have to type the whole path just the directory name.
cd cs240B2. To go to the previous directory use the command
cd ..If the current working directory is :
/home/usr/cs240B/project1If we want to go the level above the current directory. At the prompt type
<machine>% cd ..The Current working directory now is :
/home/usr/cs240BIn the above command
..refers to the directory one level closer to the root or to theparent of the working directory. The.signifies the current directory.3. Other cd commands:
Returning to the home directory.
The
cdcommand will take you to the directory where you log in
<machine>% cd
<machine>% pwd
/home/usr/cs240B
<machine>% cd /takes you directly to the root directory.