0

I use the c shell.

I wish to remove all the files and directories from a USB stick

There are a lot of files and directories. Many of the files and directories start with a period (I.e. they are so-called hidden files and directories.)

Firstly I cd to the stick's mount point. Then the problem is how to use the rm command.

If I run rm -r * I do not delete the hidden files or hidden directories.

If I run rm -r *.* I run into problems with . (current directory) and .. (parent directory)

How can I run rm to delete all files and directories (including the hidden files and directories)?

2 Answers 2

0

Your rm refuses to process .. This does not mean it cannot process the directory. It refuses to process the directory referred to as ..

You can use another name, the "real" name. It can be like ../real_name, or obtained by expanding $PWD:

rm -r "$PWD"

In your case the directory is a mountpoint. Expect device or resource busy when rm tries to remove the mountpoint itself. The exit status will not be 0, still the contents should be removed (assuming sufficient permissions).

0

The surest way to get rid of everything is just to reformat the stick.

This way you do not have to deal with file and folder permissions and attributes - you just nuke everything.

Reformat could also improve slightly the speed of the stick, when starting with everything truly empty.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .