Home »
Linux
Linux Terminal Directory-related Commands
The following are some of the important Linux directory-related commands:
- pwd
- cd
- cd and cd~
- cd..
- cd .
- cd -
- mkdir
- mkdir -p
- rmdir
- rmdir -p
1. pwd
Prints working directory, shows the path where you are working.
Example
ih@linux:~$ pwd
/home/ih
2. cd
This command is used to change directory. You can enter in any directory by using this command.
Example
ih@linux$ cd /usr/src
ih@linux$ pwd
/usr/src
ih@linux$ cd /home/ih/code
ih@linux$ pwd
/home/ih/code
3. cd and cd ~
The cd and cd ~ do the same work, if you want to go to home directory. You can achieve this by using one of these commands.
Example
ih@linux$ cd /home/ih/code
ih@linux$ pwd
/home/ih/code
ih@linux$ cd
ih@linux$ pwd
/home/ih
ih@linux$ cd ~
ih@linux$ pwd
/home/ih
4. cd..
This command is used to go to one directory (parent directory) back.
Example
ih@linux$ pwd
/usr/local/bin
ih@linux$ cd ..
ih@linux$ pwd
/usr/local
5. cd .
The . (Dot) represent s the current directory, hence there will not any changes in the directory.
6. cd -
It's a very useful and important command. It is used to go one step back.
Example
ih@linux$ pwd
/home/ih
ih@linux$ cd /usr/src
ih@linux$ pwd
/usr/src
ih@linux$ cd -
/home/ih
ih@linux$ cd -
/usr/src
7. mkdir
This command is used to make a directory, you have to give the name of the directory followed by this command.
Example
ih@linux:~$ mkdir folder1
ih@linux:~$ cd folder1
ih@linux:~/folder1$ mkdir dir1
ih@linux:~/folder1$ mkdir dir2
ih@linux:~/folder1$ ls -l
drwxr-x--- 2 ih ih 2015/03/30 01:26:54 dir1
drwxr-x--- 2 ih ih 2015/03/30 01:27:00 dir2
8. mkdir -p
This command is used to create parent directories while you are creating a child directory.
for example, if you want to create a dir1 under the games directory and you don't have games directory, then you will have to use mkdir –p command. You can not create dir1 directly using mkdir command.
Example
ih@linux:~$ mkdir -p games/dir1
9. rmdir
This command is used to remove the directory.
Example
ih@linux:~$ rmdir /home/ih/mydir
10. rmdir -p
This command is used to remove subdirectories with their parent directories, i.e. recursively directory removal is possible by this command.
Example
ih@linux:~$ rmdir -p games/dir1