In a shell environment, the current working directory is the directory 'you' are currently in. Unless specified by an absolute path all file references are made relevant to the current working directory. In short, the current working directory is the first place programs will look.
Here are some examples.
The command touch
creates an empty file or updates the last modifed date of an existing one. A quick touch
. Unless given an absolute path, touch
will create the file file relative to the current working directory (CWD).
touch myfile
If the CWD is /home/lee
, then my file's absolute path will be /home/lee/myfile
.
All other commands that operate on files or directories follow this same convention. mkdir
, cat
, tail
, rm
, cp
all reference the CWD.
Make a directory called foo
mkdir foo
Print the text in a ./readme.md file
cat ./README.md
Permanently delete the current directory.
rm -r ./
The working directory can be changed using the command cd
. short for change directory. The cd
command uses the same relative path rules.
To find out which directory you are currently 'working' in. Use the command pwd
which is short for 'print working directory.'
To reference your current working directory, use the dot convention (.). For example, ./myfile
.
To reference the directory above the CWD use the double dot (..). The double dots can be chained together to go all the way up the tree. ../../../