How I remove a directory in Linux Operating System?

Asked By 10 points N/A Posted on -
qa-featured

I tried with rm command to delete directory, file is deleted but directory did not delete, why that? 

Please help.

SHARE
Best Answer by Britnu Salu
Best Answer
Best Answer
Answered By 0 points N/A #134148

How I remove a directory in Linux Operating System?

qa-featured

Hi  Baker,

I think you did not put the right command for deletion.

Here ram command has many options, for directory deletion you need to put one option before your argument.

An example is given below.
#ram –r [file/directory name]

If you want to delete without confirmation prompt then you type
#ram –rf  [file/directory name]

Britnu Salu

Answered By 0 points N/A #134149

How I remove a directory in Linux Operating System?

qa-featured

Hi Mich,

You cannot delete a directory if it contains a file.

You must delete first the file within the directory so that you can delete the directory.

Ram – for deleting directory

Del – for deleting file/s

Hope it helps.

Answered By 590495 points N/A #134150

How I remove a directory in Linux Operating System?

qa-featured

The command you used to delete the file and directory in Linux is correct but the only problem in the command you used is that you did not add the proper switches so the command will also delete the folder where it is stored. This problem is the same when deleting files in Microsoft Windows using the command line.

Here’s an example of a scenario in Microsoft Windows. For example, a file called “blog.txt” is stored in the folder “7-Zip”. This file can be deleted even without going inside the folder.

To delete the file, we can use “del 7-Zip” and the file will be deleted but not the 7-Zip folder. If you want to delete its folder as well, you need to apply a different command: “rmdir /s 7-Zip” or “rd /s 7-Zip”. In Linux, since you already used the “rm” command, it was only able to delete the file but not the folder.

To include the folder in the deletion, apply the command “$ rm -rf <directory>/”. The “-r” switch will attempt to remove the files and subfolders in the specified directory. The “-f” switch will delete everything in the specified directory without prompting for confirmation.

For example, you have “.png” files inside the folder “Pictures”. To delete them, apply the command: “$ rm -rf Pictures/”.

Answered By 10 points N/A #134151

How I remove a directory in Linux Operating System?

qa-featured

Hello guys, I am really glad to land here and solve my problem. I love Linux so I have installed Ubuntu Linux in my PC.

While using the command “rm”, I tried to delete a directory but did not succeed.

It gave me a great problem whenever I start to operate my PC.

After reading the explanation by Sharath Reddy, I have understood everything clearly about how to delete a directory.

I love his comment very much. It was very charming that just using the “-f” command worked fine! Now I am happy because I successfully removed the unwanted directory.

Thanks Sharath and Techyv.com for establishing this nice post.

Related Questions