3

I would like to remove all of the archives (.tar, .zip, etc) on my system.

I know how to delete files using rm but I'm wondering if there is a command just for deleting the archives on my system (and not regular files).

Thanks

8

You can delete an archive like you would any regular file you have rights to:

rm /path/to/archive

To delete all the files in a certain directory or a folder with more than one file use the -r flag (recursive).

rm -r /path/to/directory

To delete just .tar and .zip files in /path/to/directory/ use this line:

rm -r /path/to/directory/*.tar  /path/to/directory/*.zip 

Note: If you get permission denied, then run the command again with sudo in front of it.

For more information, check out the rm manual page.

| improve this answer | |
  • 1
    An example of a archive would be a .tar, .zip or even .deb file. Technically, you should be able to delete a archive using just sudo rm /path/to/archive. If you extract the archived file, then you use rm -r to delete it – ldias May 7 at 15:15
  • 1
    @ldias Hence our confusion, archive files (deb, tar, zip etc) are just files and they are removable just as any other file – kurja May 7 at 15:20
  • 2
    depends what is /path/to/directory/ - sudo will help with files that your normal user don't have permissions... I wouldn't run that on / ..... – pLumo May 7 at 15:35
  • 3
    Use sudo when you need it, I cannot tell you if you need sudo to delete your files... if you have to ask, it's probably better not to use sudo ;-) – pLumo May 7 at 15:37
  • 3
    can't see why you should use -r when deleting files. if you want delete file recursive better use find path/ -type f -name '*.zip' -delete or globstar rm path/**/*.zip – bac0n May 7 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.