Quick Start Guide

7.3.1 Examples for Working with Files and Directories
Suppose you want to copy a le located somewhere in your home directory to a
subdirectory of /tmp that you need to create rst.
Procedure 7.1 Creating and Changing Directories
From your home directory create a subdirectory in /tmp:
1 Enter
mkdir /tmp/test
mkdir stands for “make directory”. This command creates a new directory
named test in the /tmp directory. In this case, you are using an absolute path
to create the test directory.
2 To check what happened, now enter
ls -l /tmp
The new directory test should appear in the list of contents of the /tmp direc-
tory.
3 Switch to the newly created directory with
cd /tmp/test
Procedure 7.2 Creating and Copying Files
Now create a new le in a subdirectory of your home directory and copy it to /tmp/
test. Use a relative path for this task.
IMPORTANT: Overwriting of Existing Files
Before copying, moving or renaming a le, check if your target directory already
contains a le with the same name. If yes, consider changing one of the lenames
or use cp or mv with options like -i, which will prompt before overwriting an ex-
isting le. Otherwise Bash will overwrite the existing le without conrmation.
1 To list the contents of your home directory, enter
ls -l ~
It should contain a subdirectory called Documents by default. If not, create this
subdirectory with the mkdir command you already know:
mkdir ~/Documents
Shell Basics 91