Solved

Use bash script to move all files in home directories.

Posted on 2008-10-10
4
937 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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 …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

617 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