LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-18-2004, 07:31 AM   #1
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Rep: Reputation: 15
utility - folder


HI --

Let's say that all of my music files are in folders/subfolders.
like this:
/mnt/music/artist/album/tune.ogg

Now let's say I would like all of the music files to be in one big directory:
/mnt/music/tune.ogg

Is there a utility that will extract folder contents up to 4 levels deep?

Thanks
 
Old 08-18-2004, 08:10 AM   #2
HLVS
Member
 
Registered: Oct 2003
Location: Prague, Czech Republic
Distribution: Gentoo, FreeBSD
Posts: 37

Rep: Reputation: 15
Hi,

I don't know whether there is special app for it, I would simply use find with -exec argument, something like this:

find /usr/music -iname "*.ogg" -exec mv '{}' /usr/music ';'

Check man find for information.
 
Old 08-18-2004, 09:03 AM   #3
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Anybody who knows the correct syntax for a cp "from"-path for this? It should be possible to use cp, I'm just not sure how .
 
Old 08-18-2004, 09:37 AM   #4
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Original Poster
Rep: Reputation: 15
Of course...

FInd all files of a type, copy them to the location of my choice.
it's pretty easy (gui search, ctrl-a, copyto...)

this part is easy:
find /mnt/music -iname *.mp3 -exec cp /mnt/music

but what's the '{}" you have after -exec...and the ';' after the location?

couldya break it down?
find /usr/music -iname "*.ogg" -exec mv '{}' /usr/music ';'

I want them in the same /mnt/music directory -- just out of all their folders.


Thanks

machiner

Last edited by machiner; 08-18-2004 at 09:44 AM.
 
Old 08-18-2004, 09:57 AM   #5
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Original Poster
Rep: Reputation: 15
ACTIONS
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of ‘;’ is encountered. The string ‘{}’
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a ‘\’) or quoted to
protect them from expansion by the shell. The command is exe-
cuted in the starting directory.

so then I would type:
find /usr/music -iname "*.mp3" -exec cp '*.mp3' /usr/music

I get a missing argument to -exec
 
Old 08-18-2004, 10:01 AM   #6
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Original Poster
Rep: Reputation: 15
exec: usage: exec [-cl] [-a name] file [redirection ...]

whaaaaaaaa??
 
Old 08-19-2004, 02:48 AM   #7
HLVS
Member
 
Registered: Oct 2003
Location: Prague, Czech Republic
Distribution: Gentoo, FreeBSD
Posts: 37

Rep: Reputation: 15
Hi,

okay, let's go step by step:

1) I'm sorry for confusing you with /usr/music and /mnt/music.. you have, of course, to use /mnt/music. I use /usr/music because I have my music in this directory...

2) cp works in way " cp source destination"

3) that '{}' means actual file name which have file utility currently found. It's bit tricky if you have never used it so little example how it works (with my directory structure):

bash-2.05b# pwd
/usr/music/Gang Starr/The Ownerz
bash-2.05b# find . -iname "*.mp3" -exec echo '{}' is current filename ';'
(...)
./04 - Sabotage.mp3 is current filename
./05 - Rite Where U Stand featuring Jadakiss.mp3 is current filename
./06 - Skillz.mp3 is current filename
(...)

which means: Find in current directory files ending with mp3 and when you have found, echo their name (which is represented by that '{}'; it's variable containing filename) and 'is current filename' string. That ';' just indicates that -exec command has no other arguments. Very important to realize is fact that '{}' represents just one filename at time.

As indicated in second paragraph cp (mv as well) needs to get source as first argument.

So your command would look like this:

find /mnt/music -iname "*.ogg" -exec cp '{}' /mnt/music ';'

I hope it's clear, if not, just ask :-)
 
Old 08-19-2004, 07:16 AM   #8
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Original Poster
Rep: Reputation: 15
THanks for your help...naah, I noticed the /usr instead of mount...that wasn't it. THe first command you gave was missing syntax and I was just too noob to see it.

following -exec is now the cp command.

I will try this, without echo -- I don't need to see the command in action -- just results.

Thank you, HLVS.

My understanding of the string:

find /mnt/music -iname "*.ogg" ...find all the files with extension .ogg in the music directory (in all of their folders)...
-exec cp '{}' /mnt/music ';' ...copy all of them (each found one '{}') to the music (root) directory
';', no switches for -exec


i would like to point people to this website - what a noob goldmine. And I'll wager - for experienced folk as well.
http://www.linuxcommand.org/lts0070.php

My box is whiz-banging as I type -- it worked like a charm!!!!!!!!!!!!!!!!!

Woohoo!!!!

Thank you again.

machiner -- I friggen love linux.
 
Old 08-20-2004, 07:26 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
I knew it, and now I had time to find it:
Code:
cp -r *.ogg .
That's all -- at least as long there are no mp3-files in the target directory "." in which case you might want another option, which prevents overwriting of existing files:
Code:
cp -ru *.ogg .
Shorter, huh?


Also:
Code:
man cp

Last edited by JZL240I-U; 08-20-2004 at 07:30 AM.
 
Old 08-20-2004, 08:15 AM   #10
HLVS
Member
 
Registered: Oct 2003
Location: Prague, Czech Republic
Distribution: Gentoo, FreeBSD
Posts: 37

Rep: Reputation: 15
machiner: heh, now i got to look to dictionary for "friggen" word :-)

JZL240I-U: I'm bit unsure about this, since "cp -r *.ogg" should, AFAIK, look for all files/dir in current dir. Not for all files in all nested dirs. I'm currently at work where I don't have access to coreutils-using machine, but I'm pretty sure it doesn't work on FBSD.
 
Old 08-20-2004, 08:25 AM   #11
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Nope. -r means recursive (in subdirectories). So it says: copy recursively the *.oggs to "." (the working directory). Works without collision if you have no ogg files here. Use -ru i.e. with the update option, which copies only newer files to "." (since existing files are equally old but not newer they are not copied -- at least thats the theory ).
 
Old 08-20-2004, 09:27 AM   #12
machiner
Member
 
Registered: Jun 2004
Location: New England
Distribution: Debian, straight. No chaser.
Posts: 112

Original Poster
Rep: Reputation: 15
woohoo!

Thanks for your help/responses.

It's tough asking anything on this forum. I successfully found (recursively -- down in directories) all those files, and now they are in one big directory.

The whole purpose to this (besides learning more about linux and commands) is to convert my .mp3 files.

SOme of the rips I did from my cd's apparently were crummy -- there are skips and/pops in some of my songs....no good. I am reasonably sure that converting them will NOT solve the problem - an absence of data is an absence of data -- but I like to mess around with my computer.

Thanks again.

machiner

HLVS - friggen is simply a colloquial expression roughly meaning the same as another colorful (fu#*ing) expression. It's generally safer to use and conveys the same contextual meaning.

eg: this friggen bites
however, friggen is no replacement for the ever-popular "go f*%$ yourself"


Last edited by machiner; 08-20-2004 at 09:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Folder Max Size and Limiting SSH access to home folder. Mefistofeles Linux - General 4 11-26-2005 02:09 PM
permissions difference between /home/..../folder and /root/folder darkleaf Linux - General 3 07-21-2005 05:23 PM
Directory/folder mirroring utility? paulsh2k4 Linux - Software 2 09-14-2004 02:44 PM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 02:26 AM
gnome home folder and trash folder ambelos Linux - Software 2 02-24-2004 06:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration