[colug-432] help with a command

Brian Miller bnmille at gmail.com
Tue Aug 12 18:34:09 EDT 2014


On 08/10/2014 11:38 PM, Rick Hornsby wrote:
>
> On Aug 10, 2014, at 21:20, Stephen Potter <spp at unixsa.net> wrote:
>
>> On 8/10/2014 10:16 PM, Chris Embree wrote:
>>> I guess I misread your requirements.   I think Pat had the right
>>> solution for deleting dirs.
>>>
>>> The only difference might be addring -rf...
>>>
>>> find /dir/to/serach -type d -name "*.PA" -exec rm -rf {} \;
>>>
>>> Untested.  But seems the right direction.
>>
>> No, Keith said he wanted to keep the directories and only delete the
>> files within.
>
> Right.  Also turned out that the directories are named '*.PA’ and the files are randomly named.
>
> find . -type f -mindepth 2 -delete
>
> One way to test away from your spool directory -
>
> $ mkdir /tmp/findtest; cd /tmp/findtest
> $ mkdir 1.PA 2.PA 3.PA
> $ touch ./foo 1.PA/foo 2.PA/foo 3.PA/foo
>
> which gives you
>
> $ ls -lR
> total 0
> drwxr-xr-x  3 rhornsby  staff  102 Aug 10 22:32 1.PA
> drwxr-xr-x  3 rhornsby  staff  102 Aug 10 22:32 2.PA
> drwxr-xr-x  3 rhornsby  staff  102 Aug 10 22:32 3.PA
> -rw-r--r--  1 rhornsby  staff    0 Aug 10 22:32 foo     ### file in current directory that we won’t touch
>
> ./1.PA:
> total 0
> -rw-r--r--  1 rhornsby  staff  0 Aug 10 22:32 foo
>
> ./2.PA:
> total 0
> -rw-r--r--  1 rhornsby  staff  0 Aug 10 22:32 foo
>
> Now you can run the find command to make sure it worked:
>
> $ find . -type f -mindepth 2
> ./1.PA/foo
> ./2.PA/foo
> ./3.PA/foo
>
>
>
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432
> .
>

This may be a little late, but I understand he does NOT want to delete 
files in the starting directory.  If all directories end in .PA, then 
how about this:

cd /top/level/directory
for each in `ls *.PA`
do cd /top/level/directory/$each
rm -f *
done

You could test it by replacing rm -rf * with ls -l



More information about the colug-432 mailing list