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

Jonathan D. Poole jpoole at digitaljedi.ca
Tue Jun 18 13:42:57 EDT 2013


I’d personally rename spaces to underscores first, then run the mass move.

    find . -name '* *' | while read fname 

do
        new_fname=`echo $fname | tr " " "_"`

        if [ -e $new_fname ]
        then
                echo "File $new_fname already exists. Not replacing $fname"
        else
                echo "Creating new file $new_fname to replace $fname"
                mv "$fname" $new_fname
        fi
done 
From: R. Brent Clements 
Sent: Tuesday, June 18, 2013 1:26 PM
To: KWLUG discussion 
Subject: Re: [kwlug-disc] Need some advice/assistance on a script

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







      _______________________________________________
      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




--------------------------------------------------------------------------------
_______________________________________________
kwlug-disc mailing list
kwlug-disc at kwlug.org
http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20130618/1a1a4262/attachment.htm>


More information about the kwlug-disc mailing list