delete all files and dirs

Posted on 2006-05-26
Medium Priority
Last Modified: 2010-04-20
when I type this: rm -rf *
it deletes everything but I dont want
to delete the dir called (projects)
how can I do that ?
Question by:aplelois
LVL 85

Expert Comment

ID: 16773192
find . -name projects -prune -or -exec rm {} \;

Author Comment

ID: 16773207
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
LVL 85

Expert Comment

ID: 16773267
You could also mv projects out of  /home/user/ , then rm -rf  /home/user/* then mv projects back
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

LVL 24

Expert Comment

ID: 16774298
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

LVL 14

Accepted Solution

xberry earned 2000 total points
ID: 16774882
This tiny shell command should do it:

rm -Rf *[!'projects']*

LVL 14

Expert Comment

ID: 16774891
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.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question