Unix/Linux Go Back    


OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

Moving Files Automatically

OS X (Apple)


Tags
automatically, files, move

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-13-2012
abudis abudis is offline
Registered User
 
Join Date: May 2012
Last Activity: 30 June 2013, 7:20 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Bug Moving Files Automatically

I'm looking to find/create a script so that when a download is complete, I can run the script in order for it to automatically move a file such as...

'example.avi' into my videos folder

I'm a novice when it comes to scripting, any advice/help would be greatly appreciated!

Thanks
Andrew
Sponsored Links
    #2  
Old Unix and Linux 05-14-2012
glev2005 glev2005 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 19 July 2014, 10:56 PM EDT
Posts: 276
Thanks: 20
Thanked 6 Times in 6 Posts
What will the constants be? Will the file be moved from /Users/<yourUserName>/Downloads to /Users/<yourUserName>/Movies ?
Will it always be a .AVI file?
Sponsored Links
    #3  
Old Unix and Linux 05-14-2012
abudis abudis is offline
Registered User
 
Join Date: May 2012
Last Activity: 30 June 2013, 7:20 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Constants will always be the directory. For example file downloaded to Downloads Folder, and be moved to Movies, or Music.

.avi, .mp4, or .mp3

and move to the according folder
    #4  
Old Unix and Linux 05-14-2012
glev2005 glev2005 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 19 July 2014, 10:56 PM EDT
Posts: 276
Thanks: 20
Thanked 6 Times in 6 Posts
Kind of a simple approach, assumes you know how to save a bash shell script and make it executable, and to run it.

Code:
#!/bin/bash
for i in ~/Downloads/*.avi
do
mv "$i" ~/Movies
done

for i in ~/Downloads/*.mp4
do
mv "$i" ~/Movies
done

for i in ~/Downloads/*.mp3
do
mv "$i" ~/Music
done

---------- Post updated at 05:53 PM ---------- Previous update was at 05:51 PM ----------

Basically, save the code to a text file on your desktop named Whatever.sh

Open Terminal and do: chmod +x ~/Desktop/Whatever.sh

To run it in Terminal: sh ~/Desktop/Whatever.sh
Sponsored Links
    #5  
Old Unix and Linux 05-14-2012
abudis abudis is offline
Registered User
 
Join Date: May 2012
Last Activity: 30 June 2013, 7:20 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks for the quick response! I really appreciate it.

It did in fact work, and I must say will save me a lot of silly time.

I am starting to read a book on shell scripting, so this is an awesome little start to it. I am familiar with C++ and Java, but am obviously new to this.

For educational purposes, would you mind explaining what "i' represents in the code?

Cheers!

---------- Post updated at 06:26 PM ---------- Previous update was at 06:08 PM ----------

Did the obvious editing necessary. One last question to make this script simply PERFECT! Linux

If I wanted to take a group of folders on my Desktop and move all the content of those folders to the desktop (in a non organized fashion) how would I do that? Or if you can respond with guidance... I'm more then happy to continue the learning process.

Thanks again!




Code:
#!/bin/bash
for i in ~/Desktop/*.avi
do
mv "$i" /Volumes/Drobo/Movies
done

#!/bin/bash
for i in ~/Desktop/*.mp4
do
mv "$i" /Volumes/Drobo/Movies
done

for i in ~/Desktop/*.mp3
do
mv "$i" /Volumes/Drobo/iTunes/iTunes Media/Automatically Add to iTunes.localized
done

echo "\nSCRIPT COMPLETE\n"

Sponsored Links
    #6  
Old Unix and Linux 05-14-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 19 September 2017, 5:41 PM EDT
Location: Saskatchewan
Posts: 22,391
Thanks: 1,126
Thanked 4,230 Times in 3,911 Posts

Code:
cd ~/Desktop
mv folder/* ./

Sponsored Links
    #7  
Old Unix and Linux 05-14-2012
abudis abudis is offline
Registered User
 
Join Date: May 2012
Last Activity: 30 June 2013, 7:20 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Hmm... Didn't seem to work. I'll continue playing, and modifying.

Any other suggestions appreciated!
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding files with wc -l results = 1 then moving the files to another folder Dj Moi Shell Programming and Scripting 5 04-26-2012 08:09 AM
Moving Multiple files to destination files animesharma UNIX for Dummies Questions & Answers 3 08-11-2011 03:05 AM
Copying files automatically MrEddy UNIX for Dummies Questions & Answers 7 06-20-2010 11:05 PM
moving logs automatically but not removing lhareigh890 UNIX for Dummies Questions & Answers 2 03-08-2010 07:23 AM
How can I automatically find important files??? TRUEST UNIX for Dummies Questions & Answers 4 04-18-2002 11:15 AM



All times are GMT -4. The time now is 06:50 AM.