[kwlug-disc] Need some advice/assistance on a script

unsolicited unsolicited at swiz.ca
Tue Jun 18 12:56:59 EDT 2013


Ech!

'rm -fr <mytopdir>'

should probably be 'rmdir -pv <mytopdir>'

Anything left behind is non-empty and needs further investigation.

If you check and don't care about anything left behind, then run the 'rm 
-fr'.

On 13-06-18 12:52 PM, unsolicited wrote:
> Would:
>
> cd <mytopdir>
> find . -type d -execdir "mv -fv * <myparentdir>" \;
> rm -fr <mytopdir>
>
> do it?
>
> i.e. find the directories, within each found directory, execute the
> command.
>
> - don't move under topdir, to facilitate rm <mytopdir>
> (mv <newdir> <mytopdir> after the fact if useful)
>
> - probably want a v or inquire on that last rm, just in case something
> didn't move.
>
> On 13-06-18 12:15 PM, Khalid Baheyeldin wrote:
>> cd /your_directory
>>
>> # Iterate through files
>> for FILE in `find . -type f`
>> do
>>    # Don't move the file if it is already in the root directory
>>    if [ `dirname $FILE` != '.' ]; then
>>      mv $FILE .
>>    fi
>> done
>>
>> # Remove the directories
>> for DIR in `find . -type d`
>> do
>>    if [ `dirname $FILE` != '.' ]; then
>>      rm -rf $DIR
>>    fi
>> done
>>
>> On Tue, Jun 18, 2013 at 11:55 AM, R. Brent Clements
>> <rbclemen at gmail.com>wrote:
>>
>>> I need to do something dramatically destructive.  I want to take a large
>>> directory tree of folders, and collapse them all down to their root
>>> folder.  File collisions are irrelevant.  How would you guys do this?
>>> (assume for the moment that you would).
>>>
>>> _______________________________________________
>>> kwlug-disc mailing list
>>> kwlug-disc at kwlug.org
>>> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>>>
>>>
>>
>>
>>
>>
>> _______________________________________________
>> kwlug-disc mailing list
>> kwlug-disc at kwlug.org
>> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>>
>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org




More information about the kwlug-disc mailing list