Intro 2

Directory Commands

DIR_NAME /create directory DIR_NAME. DIR_NAME Remove/delete directory DIR_NAME.

Deleting Files

To remove a use the .

The rm command will be used below. A deleted file cannot be un-deleted, there is no Trash that it is put into.

Creating a Directory

The mkdir command is used to create a new directory. the commands:

-l # List your files mkdir New_Dir # Create a directory named New_Dir in the current directory ls -l # New_Dir exists now Since you haven't changed directories you are in your home directory.

The mkdir command created a directory named New_Dir in your home directory. File and directory names should not include any spaces.

Changing the Current Directory - 2 Now we want to work in the New_Dir directory. We need to change our current directory to the New_Dir directory. Type the commands:

# Show the directory you are currently "in" New_Dir # "Go" into New_Dir pwd For demonstration purposes we would like to create a file in this subdirectory. Type the commands:

ls -l # List your files, there are none anewfile # Create an empty file called anewfile ls -l

Changing the Current Directory - 2, continued In each directory there are always two special files. 1. One has the name "." (a single period) that denotes the current directory. 2. The other has the name ".." (two periods immediately after each other) that denotes the parent directory. Now we want to move out of the subdirectory New_Dir and back to our home directory. Type the commands:

pwd cd .. # ".." denotes the parent of the current directory, the directory the current directory is in pwd

Also, you can move directly to your home directory, no matter where you are , by using the cd command by itself.

Files

Data is stored on computer systems in files. Much of the work that we do involves manipulating files. There are various commands to list, rename, and otherwise access files.

Redirecting Output

Output from a command goes to the terminal window by default. It is possible to have the output from a command go into a file instead. Type the commands:

ls # List files, output to terminal window ls > out.txt # List files, output to file out.txt clear # Clear the window out.txt # Show what's in the file By default error messages don't go into a file. By using >& all output will go into the file. Type the commands:

rm out.txt # Delete the file ls out.txt # out.txt was just deleted, error message from ls command ls out.txt > err.txt # Error message from ls command not sent to file clear # Clear the window cat err.txt # Show what's in the file, empty file ls out.txt >& err.txt # Error message from ls command sent to file clear # Clear the window cat err.txt # Show what's in the file, error message rm err.txt # Delete file

Main -- Notes -- Unix_Intro_2 -- Slides