[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: script to remove linked directories containing specific files



On Thu, 17 May 2012 23:36:43 -0700, Brian Flaherty wrote:

> Good evening,

Same to you but please, don't post html formatted messages :-)

> I have moved away from iTunes back to organizing my own music. The main
> music directory contains several kinds of files: ogg, mp3, flac, aiff. I
> want to create a subdirectory that only contains links (I assume soft.)
> to the directories containing only ogg and mp3 files. For example, if
> this was my base directory:
> 
> music/ artist1/ album1/ogg-songs
>              / artist1/ album2/flac-songs
> ... etc.
> 
> I'd like something like this:
> 
> link-dest.dir/artist1(link)/ album1/ ogg
> 
> without a link to the album2 directory because it contains flac files.

So you want to remove the "/music/artist1/album1/ogg-songs" folder but 
keep "/music/artist1/album2/flac-songs"?

> I think I know how to walk through and link to each directory, but not
> sure how to then go through and remove links to directories with the
> file type I don't want.
> 
> Any suggestions or thoughts welcome. Thank you.

If I got it right, you have something like this:

sm01@stt008:~/Desktop$ ls -la music/artist1/*/*
music/artist1/album1/ogg-songs:
total 0
drwxr-xr-x 2 sm01 sm01 104 may 18 22:31 .
drwxr-xr-x 3 sm01 sm01  80 may 18 22:29 ..
-rw-r--r-- 1 sm01 sm01   0 may 18 22:31 test2.ogg
-rw-r--r-- 1 sm01 sm01   0 may 18 22:31 test.ogg

music/artist1/album2/flac-songs:
total 0
drwxr-xr-x 2 sm01 sm01 112 may 18 22:32 .
drwxr-xr-x 3 sm01 sm01  80 may 18 22:29 ..
-rw-r--r-- 1 sm01 sm01   0 may 18 22:32 test2.flac
-rw-r--r-- 1 sm01 sm01   0 may 18 22:32 test.flac

To get/filter the ogg songs (or the ogg folder) you can:

sm01@stt008:~/Desktop$ ls -la music/artist1/*/ | grep ogg
drwxr-xr-x 2 sm01 sm01 104 may 18 22:31 ogg-songs

or:

sm01@stt008:~/Desktop$ ls -la music/artist1/*/* | grep .ogg
music/artist1/album1/ogg-songs:
-rw-r--r-- 1 sm01 sm01   0 may 18 22:31 test2.ogg
-rw-r--r-- 1 sm01 sm01   0 may 18 22:31 test.ogg

This is a simple approach. For a script, if you want to delete files/folders, 
use the "file" command instead, it's safer.

Greetings,

-- 
Camaleón


Reply to: