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

unsolicited unsolicited at swiz.ca
Tue Jun 18 12:52:46 EDT 2013


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
>




More information about the kwlug-disc mailing list