[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: script help



On Mon, Dec 01, 2008 at 08:35:15PM -0500, RGH wrote:
> Gordon Messmer wrote:
>> Dave Ihnat wrote:
>>> On Mon, Dec 01, 2008 at 04:10:50PM -0500, RGH wrote:
>>>>    ls -1d *log | xargs rm -Rf
>>>> Note that the first option is a one, not an el.
>>>
>>> Or for that matter, just "echo *log" instead of ls.
>>
>> Neither of those are reliable.  If there are enough matches to require  
>> xargs, then both ls and echo will fail.  xargs also doesn't care  
>> whether or not each entry is printed on its own line, so "ls -1" isn't  
>> better than "ls" with no argument.
>>
> It is better, because "ls -1" doesn't print all the junk. This wasn't
> meant to deal with the spaces-in-filenames problem. The IFS reset I
> mentioned in another post is what's needed to deal with that, isn't it?
> Combined with `ls -1` of course.

One important tool is:

	find dir -type f -print0 | xargs -0  somecommand

The -print0 and -0 pair are key.
I find myself using it for the most simple searches
for the simple reason that WindowZ users are always
adding spaces and other unix shell meta characters 
like ""')(*&^%$# !~`=';:"?/><,." to their file names 
and for me this includes Music titles...

Also the 'type -f' is interesting in this discussion because 
the OP did not specify if dirs or files were interesting.

Find also has date tools that I use a lot to find out
what fiddles with what.

	touch /tmp/now
	/usr/sbin/*configure*something
	find / -type f -newer /tmp/now -print

There are good reasons that the -1 flag exists for 'ls' and
yes there are reasons that 'xargs' exists too.


-- 
	T o m  M i t c h e l l 
	Found me a new hat, now what?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]