UNIX – Lesson 002 – cd, mkdir, rmdir commands
Working with directories
What is a directory?
- Unix considers a directory as a particular type of file. It contains files and directories sub tree.
What about “ . ” and “ .. ”?
- The entry called dot (.) represents your current directory position.
- The entry called double dot (..) represents the directory immediately above your current directory position, often referred to as “parent directory”.
cd (change directory)
The “cd” command changes working directory
# cd /tmp
You move to the temporary directory
mkdir (make directory)
The “mkdir” command creates directory
mkdir [-mp] [directory]
- -m creates directories with preferred permission mode
- -p creates directories by creating all the non-existing parent directories first
# mkdir -m 700 –p /tmp/test/hat
You create inside “/tmp” directory two directories the first one is “test” the second is “hat” from your current directory with permissions set to 700 (in the next lessons we speak about permission).
rmdir (remove directory)
The “rmdir” command removes directory which must refer to an empty directory
rmdir [-rf] [directory]
- -r recursively removes directories and subdirectories
- -f removes all files (whether write-protected or not) in a directory without prompting the user
# rmdir –rf /tmp/test
You remove a directory called “test” and its subdirectories and/or files.