delete all files and dirs

hello,
when I type this: rm -rf *
it deletes everything but I dont want
to delete the dir called (projects)
how can I do that ?
apleloisAsked:
Who is Participating?
 
xberryConnect With a Mentor Commented:
This tiny shell command should do it:

rm -Rf *[!'projects']*



0
 
ozoCommented:
find . -name projects -prune -or -exec rm {} \;
0
 
apleloisAuthor Commented:
I mean im here /home/user/
and there are around 60 files and dirs inside /home/user/
I want to delete almost all of them exept 1 dir and 1 file
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
ozoCommented:
You could also mv projects out of  /home/user/ , then rm -rf  /home/user/* then mv projects back
0
 
fridomCEO/ProgrammerCommented:
in zsh you could do
rm -rf * TAB
then you go to the stuff you do not want to delete and remove that from the list of files to be removed.

Or you pipe the file listing like this:
ls -l | grep -v "what_I_do_not_want_to_delete" | rm -rf

Regards
Friedrich
0
 
xberryCommented:
As fridom pointed to already, whenever you
use a command for extinguishing dirs/files,
better make a backup of saveworthy data
first before you go on with deletion.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.