Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/

and the contents are

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

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
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
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 > 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:

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .