11

I would like to clear out my /bin folder in my project directory. How can I do this?

I tried rm -rf ~/bin but no luck

3 Answers 3

21

~ is a shorthand to a current user home directory. So unless it's also your project directory you are doing something wrong. Other than that, clearing a directory would be

rm -rf ~/bin/*

And if you also want to clear the hidden files

rm -rf ~/bin/* ~/bin/.[a-zA-Z0-9]*

Make sure you are not doing

rm -rf ~/bin/.*

especially as root as it will also try to delete the parent directory.

UPD

Why? Since wildcard (*) is interpreted by shell as zero or more characters of any kind the .* will also match . (current directory) and .. (parent directory).

Sign up to request clarification or add additional context in comments.

Comments

13

You should say "... my bin folder", not "my /bin folder". /bin is an absolute path, bin is a relative path.

rm -rf ~/bin removes $HOME/bin, so not what you want either.

Now, it depends on where you are: if you are in your project directory when you type the command, just type rm -rf bin.

1 Comment

is -rf necessary? wouldn't rm ~/bin/* suffice
3

rm -rf ~/bin/{*,.[^.]*}

would delete all files and directories in ~/bin/, including hidden ones (name starts with .), but not the parent directory (i.e. ..).

The .[^.]* matches all hidden files and directories whose name starts with a dot, the second char is NOT a dot, and with or without more chars.

1 Comment

Totally works for me. I was using {*,.*} but it shows an error message about directories .and ... The .[^.]* does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.