You can use directory commands to create and remove directories, list their contents and more.
List the Contents of a Directory
Note: The directory must be empty in order for you to successfully delete the directory.
To recursively delete a directory and all the files and subdirectories below that directory, type:
rm -r <directory>
rm -r comp101
Display the Current Working Directory
You can also view your current working directory by typing:
This command will move you down into the specified directory. The specified directory must be a subdirectory of the directory you are currently in.
This command will move you up one directory level from your current directory:
This command will move you into the specified users home directory:
This directory will be readable only if you have read permissions for it.
This command will move you into the specified directory starting from the root and following the path:
The command by itself will take you back to your top level (home) directory.
Note: "/" represents the root directory. "~" represents users' home directories. ".." represents the parent directory.
This command will make a copy of the specified file and put it in the specified directory leaving the original file intact:
cp <filename> <directory>
cp essay1 comp101
This command will do one of two things. If the target directory already exists, a copy of the source directory will be put into the target directory. If the target directory does not already exist, the target directory will be created and it will contain all the files and subdirectories that the source directory contains.
cp -r <directory> <directory>
cp -r comp101 comp102
This command will move the specified file from your current directory to the specified directory. No copy of the file will be left in its original directory.
mv <filename> <directory>
mv essay1 comp101
This command will do one of two things. If the target directory already exists, the source directory will be moved into the target directory. If the target directory does not already exist, the source directory will be renamed with the target directory name.
mv <directory> <directory>
mv comp101 comp102
This command will push a directory onto the directory stack. With a <directory> option, it will push the current working directory onto the stack and change to <directory>. With an <n> option, it will rotate the <n>th entry to the top of the stack and change to that directory. With no arguments it will exchange the top two elements.
This command will pop the directory stack and cd to the new top directory. The elements of the directory stack are numbered from 0 starting at the top. With an <n> option, it will discard the <n>'th entry in the stack.
Print the Directory Stack
This command will print the directory stack with the most recent directory shown on the left; the first directory shown is the current directory. With the - l option, it will produce an unabbreviated printout. Use of the ~ notation is suppressed.