Linux Delete All Directory Using Command Line

Linux Delete All Directory Using Command Line

In this tutorial guide, you will learn how to remove empty directories and nonempty directories linux using the command line. And as well as how to remove/file files linux using the command line.

How to Delete All Directory Using Command Line in Linux

You can use the rmunlink, and rmdir commands to remove or delete all directories and files in Linux without confirmation.

  • Delete empty directory linux
  • Remove non-empty directory Linux
  • Delete multiple directories linux
  • Delete a file linux command
  • Remove multiple files in linux using rm command

Delete empty directory linux

If you want to remove (or delete) a directories in Linux from the command line. So, you can use the rmdir and rm command.

Using the rmdir or rm -d command, you can remove directory in linux:

rm -d dirname

rmdir dirname

Remove non empty directory linux

If you want to remove non empty directory in linux. So, you can use with the-r (recursive) option, as shown below:

rm -r dirname
  • Delete non empty directory linux without prompt

To delete non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:

rm -rf dirname
  • Delete non empty directory linux without prompt

To delete non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:

rm -rf dirname

Delete multiple directories linux

If you want to delete multiple directories at once in linux. So, you can use the rm -r command, as shown below:

rm -r dirname1 dirname2 dirname3

Delete a file linux command

If you want to remove (or delete) a file in Linux from the command line. So, you can use the rm (remove) or unlink command.

Note that, The unlink command allows you to delete only a single file, while with rm you can delete multiple files at once.

You can use the rm and unlink command to delete single file in linux. See the uses of rm and unlink command given below:

unlink filename
rm filename

If the file is write-protected, you will be prompted for confirmation on your terminal or command prompt, as shown below.

rm: remove write-protected regular empty file 'filename'?

Note that, Otherwise, if the file is not write-protected, it will be deleted without prompting.

Remove multiple files in linux using rm command

You can use the rm command to remove multiple file in linux. See the uses of rm command with multiple options, as shown below:

  • To delete multiple files at once using rm command:
rm filename1 filename2 filename3
  • Wildcard (*) and regular expansions to delete files

If you want to remove all .txt files in the current directory, use the following command:

rm *.pdf
  • Delete file with confirmation

You can use the rm with the -i option to confirm each file before deleting it:

rm -i filename(s)
  • Delete files in linux without confirmation

You can use the rm with the -f option to without prompting even:

rm -f filename(s)

Conclusion

In this tutorial guide, you have learned how to use the Linux rmrmdir and unlink commands to remove or delete files and directories in linux. And as well as how to remove or delete empty and non empty directories in linux.

Recommended Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *