Solved

Use bash script to move all files in home directories.

Posted on 2008-10-10
4
926 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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