-1

I have a VPS. I want to delete some specific folder inside. /var/BACKUP 01

I want to delete all files in BACKUP 01

How can I do it with SSH access? I'm using linux,please type a command here.

8

To delete a file in Linux, you use the 'rm' command.

You need to be careful as you have a space in that directory name - Ideally, you should name your directories and files with no spaces in the names. It's not mandatory to do this, but it makes life easier, and is less prone to accidentally deleting something. If there are spaces in the filename, it's best to use quotes around the name.

rm -fr "/var/BACKUP 01/"

If you want to see what files this will delete before you run it you could use this command

ls "/var/BACKUP 01/"
5
  • 2
    ls -r "/var/BACKUP 01/*" would recursively list the directories, just as rm -r recursively removes them.
    – stib
    May 31 '11 at 11:16
  • 2
    Do not use * inside quotes (unless you have a file named * in there). Just give the directory name.
    – user1686
    May 31 '11 at 18:30
  • @grawity - good catch - I've edited the post.
    – barryj
    May 31 '11 at 18:56
  • Oh, don't use it outside the quotes either. It would miss .dotfiles, and given many files it might even cause a "Command line too long" error. Just give the directory name.
    – user1686
    May 31 '11 at 18:58
  • @grawity Another good point. I was focussing on deleting the contents of the directory, but not the directory, which I think is what was asked for. A find with a -delete option might be better for that I guess - put probably overkill for what the OP wanted.
    – barryj
    May 31 '11 at 19:03
2

If you are logged in to your VPS then

cd "/var/BACKUP 01"
rm -r *

should do the trick. You need to put quotes around the path because of the space in the BACKUP 01 directory name.

0

I found a great article while googling, i recommend it.

http://www.discusswire.com/delete-entire-directory-ssh/

1
  • 2
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Ivo Flipse
    Apr 25 '12 at 12:48
0

Before deleting file ensure that you want to delete it really - if needed, make a back up copy.

1] With SSH use the following command to enter the directory where the file(you want to delete) is located:

cd foldername

2] After going to the particular folder use the following command(s):

To delete a single file:

rm filename.extension

rm readme.txt (Example to deleting readme.txt file)

To delete entire files of the folder after you entered the directory using the command mentioned in STEP 1 - use the following command:

rm -r *

NOTE: STEP 2 is irreversible if you don't create any back up.

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.