Solved

Use bash script to move all files in home directories.

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

735 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