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.
[email protected]:~$ pwd
/home/ih
cd This command is used to change directory. You can enter in any directory by using this command.
[email protected]$ cd /usr/src
[email protected]$ pwd
/usr/src
[email protected]$ cd /home/ih/code
[email protected]$ 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.
[email protected]$ cd /home/ih/code
[email protected]$ pwd
/home/ih/code 
[email protected]$ cd
[email protected]$ pwd
/home/ih
[email protected]$ cd ~
[email protected]$ pwd
/home/ih
cd.. This command is used to go to one directory (parent directory) back.
[email protected]$ pwd
/usr/local/bin
[email protected]$ cd ..
[email protected]$ 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.
[email protected]$ pwd
/home/ih
[email protected]$ cd /usr/src
[email protected]$ pwd
/usr/src
[email protected]$ cd -
/home/ih
[email protected]$ 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.
[email protected]:~$ mkdir folder1
[email protected]:~$ cd folder1

[email protected]:~/folder1$ mkdir dir1
[email protected]:~/folder1$ mkdir dir2
[email protected]:~/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.
[email protected]:~$ mkdir -p games/dir1
rmdir This command is used to remove the directory.
[email protected]:~$ 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.
[email protected]:~$ rmdir -p games/dir1






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.