Watch directory and move specific file extensions


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Watch directory and move specific file extensions
# 1  
Old 07-25-2010
Watch directory and move specific file extensions

Hi all,

This is actually more for my lazyness then anything else, but I think others might find it useful to use as well. Basically this is what I am trying to achieve...

In my ubuntu home dir under Downloads is where firefox saves everything by default, now I know that you can manually specify anywhere that you want things saved to but, this would just be not lazy enough as I love the convenience of hitting download etc.

So, I have created a basic little mv script that moves certain file types out and sorts them in directories throughout my home dir. ie. .torrent files get placed in a directory called Torrents, avi/mpg/wmv get placed in Videos and .mp3 get placed in Music (hmm gotta take that further also).

So, currently this script is just running as a every minute cron, however, this still isn't soon enough, I want it to be instant! using watch or sumthing like that. Problem is I use uTorrent webUI and when I save a file I go to upload it through the interface but it isn't in the torrents directory yet, so I go back to the Downloads folder but it's now moved... gets rather annoying.

So yeah if anyone can help me out on how to watch a directory for files and when something matches criteria (ie. .mp3) then move it to directory X, would be mighty appreciated.

Thanks,
Aaron.
# 2  
Old 07-25-2010
yum -y install inotify-tools

while true; do inotifywait -r -e MODIFY dir/ && <script>; done;

Tweak as necessary.
HTH.
This User Gave Thanks to Habitual For This Post:
# 3  
Old 07-25-2010
Sweet, thanks Habitual!

Didn't know of the inotify-tools package.

I assume that dir/ is directory to watch...?
# 4  
Old 07-25-2010
Thank me if it works.

Yes, dir/ is the directory to watch.

Monitor Linux file system events with inotify
Mostly covering what appears to be programming issues with this tool.

I got this gem another Kung-Fu site that I won't mention here (Google is your friend), but I trust its user's input as much as I do those here.

Peace.

Last edited by Habitual; 07-25-2010 at 11:11 PM.. Reason: updated with RTFM url
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to move specific files to directory based on match to file

I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

Move specific folders and subfolders in a directory

I am trying to move specific folders and subfolders within a directory using the below. I can see the folders to move and they are at the location, but I am getting an error. Thank you :). mv -v /home/cmccabe/Desktop/NGS/API/6-10-2016{bam/{validation,coverage},bedtools /media/cmccabe/"My... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

5. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies

6. UNIX for Dummies Questions & Answers

look for file size greater than "0" of specific pattern and move those to another directory

Hi , i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory.. Ex... abc_0702, abc_0709, abc_782 abc_1234 ...etc need to find out which is having the size >0 and move those to target directory..... (7 Replies)
Discussion started by: dssyadav
7 Replies

7. Shell Programming and Scripting

List directory name (only once) after multiple file extensions found

Here is a simplified example of my problem. Say I have the following 3 sub-directories; ./folder1 A.txt A.sh ./folder2 B.txt ./folder3 C.txt C.sh I would like to list the directory names which contain both '.txt' & '.sh' type extensions. I have came up with the following code;... (8 Replies)
Discussion started by: mmab
8 Replies

8. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

9. Shell Programming and Scripting

file extensions in a directory structure

Hi, I have a huge directory structure with multiple directories and subdirectories in each of the directory. i am trying to find the various file extensions in the directory structure and put them into a file. is there any way through which i can accomplish this (4 Replies)
Discussion started by: itsritish
4 Replies

10. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies
Login or Register to Ask a Question