Home » Linux

Linux Terminal Commands - Directory related commands

Working with directories (pwd, cd, mkdir, rmdir commands)

command description example
pwd Print working directory, shows the path where you are working.
ih@linux:~$ pwd
/home/ih
cd This command is used to change directory. You can enter in any directory by using this command.
ih@linux$ cd /usr/src
ih@linux$ pwd
/usr/src
ih@linux$ cd /home/ih/code
ih@linux$ pwd
/home/ih/code
cd
cd ~
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.
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
cd.. This command is used to go to one directory (parent directory) back.
ih@linux$ pwd
/usr/local/bin
ih@linux$ cd ..
ih@linux$ pwd
/usr/local
cd . . (Dot) represent s the current directory, hence there will not any changes in the directory.
cd - It’s a very useful and important command. It is used to go one step back.
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
mkdir This command is used to make a directory, you have to give the name of the directory followed by this command.
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
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.
ih@linux:~$ mkdir -p games/dir1
rmdir This command is used to remove the directory.
ih@linux:~$ rmdir /home/ih/mydir
rmdir -p This command is used to remove subdirectories with their parent directories, i.e. recursively directory removal is possible by this command.
ih@linux:~$ rmdir -p games/dir1




Comments and Discussions!










Copyright © 2023 www.includehelp.com. All rights reserved.