Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a set of directories that have files in them for use with LiquidSoap for use with IceCast2

Currently, every time I remove a file or add a file, I have to edit the txt file listing the mp3s to play manually

What I would like to do is create a script, or a cron job, t automatically create a simple list of the fill path to the mp3s across the folders that is completely regenerated each time.

I say it needs to be regenerated for sake of deleted files being removed from the file


The files are in directories suck as

/home/user1/files/foo 1/
/home/user1/files/foo 2/
etc...

and the contents are

this file is called this.mp3
another name for a file.mp3
etc...

I would like to have a script or cron that creates a txt file with the contents of each folder that ends up like

/home/user1/files/foo 1/this file is called this.mp3
/home/user1/files/foo 1/another name for a file.mp3
/home/user1/files/foo 1/this is a cool filename.mp3
/home/user1/files/foo 2/moar files.mp3
/home/user1/files/foo 2/okay this is getting old.mp3

But if I removed /home/user1/files/foo 1/this file is called this.mp3 then it would leave the txt file on the next generation, and if I added yet another file.mp3 to one of the folders, it would be added to the txt file

Currently running Ubuntu Server 13.04, and am able to install packages, if needed, although wold like to use simple scripts/crons

share|improve this question
1  
Look into incron too; it responds to changes in directories, so it would be a good fit for this task, instead of a time based cron. –  Paulo Almeida Jul 30 '13 at 1:39

3 Answers 3

up vote 1 down vote accepted

See find:

find "/home/user1/files/foo 1/" "/home/user1/files/foo 2/" > output.txt
share|improve this answer
    
Wow, I feel dumb now...that's like...linux basics.... –  Pixel Perfect Jul 30 '13 at 1:28
    
although is there any way to remove the directory listing from the fist line of the find in each folder? –  Pixel Perfect Jul 30 '13 at 1:30
    
You can use find -mindepth 1. –  Paulo Almeida Jul 30 '13 at 1:36
    
To exclude directory names from the listing, add -type f. This will list only regular files. –  Niccolo M Aug 6 '13 at 16:13

Tip: You can also do LC_ALL=C ls -lR | gzip > listing.ls-lR.gz. Midnight Commander lets you view such files (unofficially known as "ls-lR") as if they were a real filesystem.

share|improve this answer

(Assuming that you're running Linux) The tool you're looking for is inotify (see "man inotify"). It's possible to set it up to run

find "/home/user1/files/foo 1/" "/home/user1/files/foo 2/" > output.txt

whenever a file is added to (or deleted from) the target directories.

For Ubuntu, you'll need to install the inotify-tools package. This installs two binaries: inotifywatch and inotifywait. A good example of scripting what you need is at: http://exyr.org/2011/inotify-run/

I use something similar for my own home-grown Liquidsoap-based jukebox.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.