Moving Files Automatically


 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Moving Files Automatically
# 1  
Old 05-13-2012
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
# 2  
Old 05-14-2012
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?
# 3  
Old 05-14-2012
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 05-14-2012
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
# 5  
Old 05-14-2012
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! Smilie

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"

# 6  
Old 05-14-2012
Code:
cd ~/Desktop
mv folder/* ./

# 7  
Old 05-14-2012
Hmm... Didn't seem to work. I'll continue playing, and modifying.

Any other suggestions appreciated!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

2. Shell Programming and Scripting

Delete log files automatically.

Here is the script I want to run to deleted log files after a certain time: touch /usr/WebSphere/AppServer/profiles/AppSrv01/apps/RSA/logs find /usr/WebSphere/AppServer/profiles/AppSrv01/apps/RSA/logs -atime +120 - exec rm -rf {}\; Exerytime I run it, it throws me the error: find: paths must... (2 Replies)
Discussion started by: lennyz04
2 Replies

3. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

4. Shell Programming and Scripting

Copy files by automatically creating directories

I am in a situation where I have some hundreds of thousands of files in a directory (name of directory: big_directory). Now, working on this directory is extremely slow. I now plan to do this: Copy 1000 files in each of the directories by creating the directories automatically. All files have... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. UNIX for Dummies Questions & Answers

Moving Multiple files to destination files

I am running a code like this foreach list ($tmp) mv *_${list}.txt ${chart}_${list}.txt #mv: when moving multiple files, last argument must be a directory mv *_${list}.doc ${chart}_${list}.doc #mv: when moving multiple files, last argument must be a... (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

7. UNIX for Dummies Questions & Answers

Copying files automatically

Ok here is my issue. I have processes which will get screwed up and not run because certain log directories wind up filled too much and a directory will have 100,000 files in it. The only way to fix this is to move files out of this directory until the number of files is small enough that the... (7 Replies)
Discussion started by: MrEddy
7 Replies

8. UNIX for Dummies Questions & Answers

moving logs automatically but not removing

hello all, Need assistance on the subject line above. I have a logserver.log located at /usr/local/logserver. It's NSLOGDEPTH=100. I'm not sure if this is the reason but my log file retention is only up to 100 only.. sample logserver001.log logserver002.log ... ... logserver100.log ... (2 Replies)
Discussion started by: lhareigh890
2 Replies

9. UNIX for Dummies Questions & Answers

How can I automatically find important files???

how can I automatically check if important files exist in a directory and if not, automatically put the important files where they are needed say, I want to put .bashrc and a dozen other important files like it into every user's directory, how can I do this??? how do I check every user's... (4 Replies)
Discussion started by: TRUEST
4 Replies
Login or Register to Ask a Question