![]() |
Quote:
As for dealing with -r and -i files... as man rm mentions, rm uses getopt() to parse its arguments, so the usual -- option works. rm -rf -- * .[^.] .??*Hmm.. without that, a file named -- might prevent an unpredictable subset of your files from being deleted. Of course, prefixing with ./ works also on systems where rm does not look for --. Back in the olden days when I was learning Unix, I seem to recall that ? would not match a period. My first attempt was rm -rf * .? ..?* ...*but ? doesn't work like that anymore (if it ever actually did). I just thought I'd mention that. This thread seems to be accentuating that every program still has at least one bug, even if the program is a one-liner. Anyone but me remember IEFBR14? Of course you can google it, but do you remember it without looking it up? (I don't know if the fact that today is my 62nd birthday, and I've been programming since I was 19, makes that easier or harder to remember.) |
Quote:
-- I found we can also circumvent the "-i" effect by changing the order so that the bare asterisk is not first. For example... using ls with the -f option (to force it to list items in the order they were submitted): Code:
$ ls -lanf * .[^.] .??*So the -i file isn't shown. Now, reordering... Code:
$ echo .[^.] .??* *As can be seen, I've been playing around with some other weird filenames: .* and .\* |
Quote:
find . -delete Code:
% echo "rm -rf * .[^.] .??*" | wc -c |
That's weird... find . -delete
finds '.' but it doesn't delete '.' How come (no error nothin')? |
Quote:
Code:
if (strcmp(entry->fts_accpath, ".") == 0 || |
:D :D :D Thread Closed! :D :D :D No Further Information Necessary! ^^^ Well, there's still something to be said for the pattern approach: it can be done from *outside* the folder. (I've already added a Bash function to implement it... so it needs to be rationalized). rm -fr foo/{.[^.],.??*,*} will clear foo's content, but folder foo survives. ;) |
Quote:
Code:
Hal: here's a start on your function: Code:
rmstar () Add whatever additional error-checking code you deem appropriate. A nice refinement might be to loop across "$@" instead of just using "$1". Or have it accept files as well as directories. Or just ask yourself how often you're really going to need this. After all: rm -rf someDirectorywill almost always be good enough. |
Quote:
|
Can I ask to go on another tangent? :)
I would like to be able to remove all the thumbnail files iPhoto creates. In each "primary" folder hierarchy ~/Pictures/iPhoto\ Library/<year>/<month>/ there can be a "Thumbs" directory containing these thumbnail files. I've been trying to use a combination of 'find' (to find the "Thumbs" directory and 'xargs' to delete the contents of these folders, but I can't seem to get it to work. As usual, I'm sure I'm overlooking something quite simple... TIA |
This one is very aggressive, the Four Horsemen of `find` annihilating entire directory trees at a stroke:
find . -iname '*thumb*' -exec rm -rf {} \; Only two horses: find . -type d -name thumb -exec rm {}/*jpg \; |
Quote:
find . -type d -name Thumbs -exec rm {}/*jpg \; Simply to guard against the possibility (however unlikely) that there might be a folder with "thumb" somehow in its name. Thanks! |
| All times are GMT -5. The time now is 10:13 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.