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

Khalid Baheyeldin kb at 2bits.com
Tue Jun 18 13:38:35 EDT 2013


Don't understand what you are trying to say.

How about this, which simplifies the first part (moving files). Ignore the
errors of file cannot be moved to itself.

cd /your_directory

find . -type f -exec mv "{}" . \;

# 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 1:26 PM, R. Brent Clements <rbclemen at gmail.com>wrote:

> Khalid:  by inserting an "echo $FILE" in the if statement, I am seeing
> "Wanted/SFMW894/SFMW894-09"  Every part of the directory name is being
> truncated differently. The lowest directory is "SFMW891 to SFMW920 - Sunfly
> Most Wanted", the next one is correct in this case, but possibly only
> because it includes no spaces, and then the filename is truncated after the
> first space.
>
> Is this possibly a shell issue?  I am using the default shell in xubuntu.
>
> Brent
>
>
> On Tue, Jun 18, 2013 at 12:56 PM, unsolicited <unsolicited at swiz.ca> wrote:
>
>> 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<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<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<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<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
>
>


-- 
Khalid M. Baheyeldin
2bits.com, Inc.
Fast Reliable Drupal
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
For every complex problem, there is an answer that is clear, simple, and
wrong." -- H.L. Mencken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20130618/99310a5a/attachment.html>


More information about the kwlug-disc mailing list