Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use bash script to move all files in home directories.

Posted on 2008-10-10
4
Medium Priority
?
940 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…

719 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