Skip to content Skip to sidebar Skip to footer

How to Delete Files and Folders in Ubuntu Using Terminal

Delete Files and Folders Using Linux Terminal

How to Delete Files and Folders Using Ubuntu Linux Terminal - To become a Linuxer, we must learn how to manipulate the data in the hard drive. One way to manipulate data is to delete files or folders.

How to Delete Files and Folders in Ubuntu Using Terminal

In this article, the linux that I use is a derivative of Debian > Ubuntu, Elementary OS. This  can also use on linux with other Debian or Ubuntu variants.

There are at least 3 commands that are used to delete data, both files and folders on Linux using the terminal, namely rm, unlink and rmdir.

  • rm or unlink is used to delete files
  • rm or rmdir is used to delete a folder

A. How to Delete Files

  1. How to delete 1 file?
    To delete a file in linux use the rm and unlink commands followed by the file name:
    $ rm fileName.extension
    
    or
    
    $ unlink fileName.extension
    For example we want to delete the zoom application with the file name zoom_amd64.deb. So to delete the file is to use the command:
    $ rm zoom_amd64.deb
    
    or
    
    $ unlink zoom_amd64.deb

  2. How to delete multiple file?
    What kind of delete method do you want?
    1. If you want to delete only some files use the command:
      $ rm fileName1.extension fileName2.extension fileName3.extension 
      
      or
      
      $ unlink fileName1.extension fileName2.extension fileName3.extension
      Don't forget every filename and other files are separated by a space ' '.

      For example, we want to delete the files zoom_amd64.deb, learn_linux.jpg and guide_linux.pdf. So the command we use is:
      $ rm zoom_amd64.deb learn_linux.jpg guide_linux.pdf
      
      or
      
      $ unlink zoom_amd64.deb learn_linux.jpg guide_linux.pdf
    2. To delete multiple files, use to add a star character (*).
      If you want to delete the entire file in the same file extension type use the command:
      $ rm *.extension
      For example we want to delete all pdf files, then the command is:
      $ rm *.pdf
      If you want to delete all files, all of them use the command:
      $ rm *
      Warning!! using the $rm * command will delete any files!

B. How to Delete Folders

  1. To delete a folder that does not have a file in it, the command used is:
    $ rm -d folderName
    
    or 
    
    $ rmdir folderName

  2. To delete a folder that contains files, the command used is:
    $ rm -r folderName

  3. To delete multiple folders, use a command like the sequence number 2 above, but by adding the folder name and separated by a space ' ', as follows:
    $ rm -r folderName1 folderName2 folderName3

  4. To delete all folders entirely, use the asterisk character (*) in the following command:
    $ rm -r *
    Warning!! using the $rm -r * command will remove whatever it is!
If you think How to Delete Files and Folders in Ubuntu Using Terminal is useful, please share it with others using the share button below.

Post a Comment for "How to Delete Files and Folders in Ubuntu Using Terminal"