Solved

Use bash script to move all files in home directories.

Posted on 2008-10-10
4
930 Views
Last Modified: 2013-12-26
I have a ftp server that people upload files to in /home/username.

I need a bash script to move files from their home directory to the correct directory.

I will be adding future users so the script must recognize new user folders as they appear.

Under each user directory we have the following folders
normalvideo
widescreen16x9
widescreen3x2
audio
podcastvideo

So the script should look at all the folders in /home and make a list of the usernames then move them according to this for each username

mv /home/username/normalvideo/*.* /home/smartdata/www/html/files/encode/mp4
mv /home/username/widescreen16x9/*.* /home/smartdata/www/html/files/encode/mp4
mv /home/username/widescreen3x2//*.* /home/smartdata/www/html/files/encode/mp4
mv /home/username/audio/*.* /home/smartdata/files/www/html/encode/mp3
mv /home/username/podcastvideo/*.* /home/smartdata/files/www/html/encode/m4v

Thanks in advance!

0
Comment
Question by:toben88
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 22690796
try

cd /home
ls | while read udir
do
   mv /home/$udir/normalvideo/*.* /home/smartdata/www/html/files/encode/mp4
   mv /home/$udir/widescreen16x9/*.* /home/smartdata/www/html/files/encode/mp4
   mv /home/$udir/widescreen3x2/*.* /home/smartdata/www/html/files/encode/mp4
   mv /home/$udir/audio/*.* /home/smartdata/files/www/html/encode/mp3
   mv /home/$udir/podcastvideo/*.* /home/smartdata/files/www/html/encode/m4v
done

I think the below will work as well

mv /home/*/normalvideo/*.* /home/smartdata/www/html/files/encode/mp4
mv /home/*/widescreen16x9/*.* /home/smartdata/www/html/files/encode/mp4
mv /home/*/widescreen3x2/*.* /home/smartdata/www/html/files/encode/mp4
mv /home/*/audio/*.* /home/smartdata/files/www/html/encode/mp3
mv /home/*/podcastvideo/*.* /home/smartdata/files/www/html/encode/m4v
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22690826
omarfarid's last solution is the simplest, so long as you only have userdirs under /home and not files.
0
 

Author Comment

by:toben88
ID: 22733195
what is this going to do to the files in /home/smartdata? This is the folder where files are copied to. Is there a way to skip that folder so the script omits it? Should I just move that folder?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22734437
Does the folder /home/smartdata/*/normalvideo exist?  If so, do you not want to move the files out of it?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now