LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2006, 10:36 AM   #1
alexweb
LQ Newbie
 
Registered: Sep 2005
Distribution: Mandriva 2006 Power Pack
Posts: 8

Rep: Reputation: 0
Move huge amount of folders with bash


HI!

I have about 10000 folders on my server that needs to be moved onto another folder. But I have also 10-15 folders that don't have to be moved.
I've created a text file with folders list (not for removing). And want to know if there is any way to write a bash script wich will move folder only is case there is no such folder in this text file.

folderslist.txt
Code:
/path/to/folder
/path/to/folder
.....
/path/to/folder
So I want to move alll folders that are NOT in file above. Let me know if this is possible. Thanks.
Sorry for my english.
 
Old 10-26-2006, 05:16 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
I think that I would move the folders to keep in place to a temporary location. Then I would move the folders that need to be moved. Then I would put the folders that needed to be kept in place back to where they should be. This should be easy to do interactively. You shouldn't need a script.
Code:
mkdir /temporary
mv /path/to/folder /temporary
mv /path/to/folder /temporary
...
mv /folders/to/move /path/to/destination
mv /folders/to/move /path/to/destination
...
mv /temporary/whatever /path/to/original/location
mv /temporary/whatever /path/to/original/location
If there are only about fifteen directories to keep in place then it isn't worth writing a script for them. You can do it interactively faster than it takes to write a script.
 
Old 10-27-2006, 03:27 AM   #3
ebasi
Member
 
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
Here is my idea:
Code:
#!/bin/bash                                                                                         
WP="/root/aaa"                                     # the path where you'll work                 
DIRLIST="/root/dirlist"                            # list with protected dirs
DESTDIR="/root/bbb"                                # directory where will move dirs
                                                      
for LINES in `find "$WP" -type d`                  # searching for dirs
   do
      MOVE=`grep -x $LINES $DIRLIST`               # check if found dir is in protected dir list
         if [ -z $MOVE ]                           # if is not
            then                                   # then
               mv $LINES $DESTDIR                  # move this dir
            else                                   # else 
               echo $LINES is in protected list    # tell you something
         fi                                    
done
Test this script with some useless directories.

Make sure that if you want to add some sub folder in protect list, there is added and it's parent folder. As example:
if you want to protect /data/music/group/album1/ and /data/music/group/album2/ you should add
/data/
/data/music/
/data/music/group/
/data/music/group/album1/
/data/music/group/album2/

If you don't the script will first find directory data and if /data/ is not in protect list will move it...

excuse my English...

Last edited by ebasi; 10-27-2006 at 03:45 AM.
 
Old 10-27-2006, 03:42 AM   #4
alexweb
LQ Newbie
 
Registered: Sep 2005
Distribution: Mandriva 2006 Power Pack
Posts: 8

Original Poster
Rep: Reputation: 0
great! thanks ebasi!
Thas is really what I wanted to get. Maybe you can make second advice and point me ok good bash tutorial. thanks again!
 
Old 10-27-2006, 04:06 AM   #5
ebasi
Member
 
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
Quote:
Originally Posted by ebasi
/data/
/data/music/
/data/music/group/
/data/music/group/album1/
/data/music/group/album2/
This should be:
Code:
                                                        
/data
/data/music
/data/music/group
/data/music/group/album1
/data/music/group/album2
Without slashes "/" at the end, because find will return the result without slash at the end.

About tutorial, I have one in Bulgarian, that's my native language, but I think this is a good one in English.
http://tille.xalasys.com/training/bash/
remember toy can always use man bash ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping times grow HUGE after X amount of time Shade General 2 05-11-2005 11:03 PM
move files in tar.gz back to into original folders GUIPenguin Linux - General 1 05-09-2005 12:11 PM
Bash Scripting - Waiting for a certain amount of data welby Programming 12 05-12-2004 12:40 PM
Applications consume huge memory amount in kernel-2.6.4 l2g Red Hat 3 04-09-2004 09:49 AM
Huge amount of stuff needs to be listed but how? Totoro Linux - Newbie 2 03-20-2004 02:10 AM


All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration