In this Blog, we will learn how we can use rm and rmdir in Linux.
rm and rmdir commands are used to remove directory or directory structures.
So, lets see how we can use it and what are the conditions to select one of them command.
First of all open Terminal, Alt+Ctrl+t .
Syntax for rmdir command is:
rmdir -[option] dir_name
Now take one example,
I will create a directory in home directory and then I will remove it or delete it by using rmdir command.
Now if you want to remove whole directory structure and if we use same command then what will happen lets see
First we will create directory structure as: a/b/c/d/e
And then see what is the structure of created directory for that we are using command as ls -R
Now lets use command rmdir a/b/c/d/e
and again use ls -R
You will observe that whatever we directory created remains as it is but last directory get removed.
In order to delete whole directory structure you have to use command with option as:
rmdir -p [Dir_structure]
Now you can see that whole structure get removed.
If you want to see what actually happen when we use our previous command in detail then we will use -v (Verbose) which means detail explanation of process happening in background.
Lets see how it works:
rmdir -pv a/b/c/d/e
Now suppose we are in b directory and we create on text file there and again we are trying to remove whole structure by using same command then what will happen lets see
Error is occurred because directory b is not empty.
In this situation i.e, When directory is non-empty then we will use rm command.
rm -pv [Dir_name]
For any query and suggestions you may contact with me or you may put comment in comment box.
Thank You.
Contact Details:
Phone: +91-8208826234
E-mail: shivampawar1038@gmail.com
rm and rmdir commands are used to remove directory or directory structures.
So, lets see how we can use it and what are the conditions to select one of them command.
First of all open Terminal, Alt+Ctrl+t .
Syntax for rmdir command is:
rmdir -[option] dir_name
Now take one example,
I will create a directory in home directory and then I will remove it or delete it by using rmdir command.
Now if you want to remove whole directory structure and if we use same command then what will happen lets see
First we will create directory structure as: a/b/c/d/e
And then see what is the structure of created directory for that we are using command as ls -R
Now lets use command rmdir a/b/c/d/e
and again use ls -R
You will observe that whatever we directory created remains as it is but last directory get removed.
In order to delete whole directory structure you have to use command with option as:
rmdir -p [Dir_structure]
Now you can see that whole structure get removed.
If you want to see what actually happen when we use our previous command in detail then we will use -v (Verbose) which means detail explanation of process happening in background.
Lets see how it works:
rmdir -pv a/b/c/d/e
Now suppose we are in b directory and we create on text file there and again we are trying to remove whole structure by using same command then what will happen lets see
Error is occurred because directory b is not empty.
In this situation i.e, When directory is non-empty then we will use rm command.
rm -pv [Dir_name]
For any query and suggestions you may contact with me or you may put comment in comment box.
Thank You.
Contact Details:
Phone: +91-8208826234
E-mail: shivampawar1038@gmail.com
Nice one bhai
ReplyDeleteThank You.
Delete