Home > Unix > UNIX – Lesson 002 – cd, mkdir, rmdir commands

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
Syntax :
cd [directory]

# cd /tmp

You move to the temporary directory


mkdir (make directory)
The “mkdir” command creates directory
Syntax :
mkdir [-mp] [directory]

Key argument:

  • -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

Syntax :
rmdir [-rf] [directory]

Key argument:

  • -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.

Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: