Find the answer to your Linux question:
Results 1 to 3 of 3
After I upgraded Debian to the latest stable the ls command changed and it broke a script I used to sort logs for my game servers. The result is that, ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    42

    Moving Files in Multiple Directories to a Single Directory

    After I upgraded Debian to the latest stable the ls command changed and it broke a script I used to sort logs for my game servers. The result is that, while the logs were supposed to be sorted into a few folders by year, they are now sorted into dozens of folders by time. Is there a way I can move files in multiple folders to a single folder using a script?

    All the folders are located in the same directory. The script would have to iterate through the old folders and move the files in them to the new folder.

  2. #2
    Just Joined! Smither's Avatar
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    58
    Code:
    for i in `find /path/to/old/dir/`; do if (test -f $i); then mv $i /path/to/new/dir/; fi; done
    Iterates through folders, checks if it's a regular file, if it is then move it.

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    42
    Very much appreciated, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...