LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices

Reply
 
Search this Thread
Old 09-08-2012, 05:15 AM   #1
krakatoa1
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Rep: Reputation: Disabled
Smile need help with find command and rar/unrar command line


Greetings,
What began as a simple desire has turned into a couple days of staring at various forums, help websites, man pages, and blogs. I have really, really tried to serve myself and not have to actually start a new thread so if by some chance this has been answered somewhere else my sincere apologies, but I just can't devote any more time to trying to solve this myself and I really need someone to just tell me the answer.
What I'm trying to do with find: I am trying to find *.mp3 files in subdirs named CD* (where the * is a number) and pass the results to the mv command which will then mv said mp3s to the parent directory. I have been able to construct an argument for the first half of this which is: find . -type d -name 'CD?' -print (I'm just printing to test the output). The issues that I need to guard against are that I already have mp3s in an artist directory and I don't want those just moved into the mp3 directory; I only want the mp3s that are in dirs named CD* to be moved. I have tried find . -type d -name 'CD?' -and -type f -name '*.mp3' -print but nothing happens. I even looked at http://www.gnu.org/software/findutil...ttern-Matching and tried to do:
find . -name './CD*mp3' -print
but the command line returns nothing - no errors, no suggestions, just as if I hit the enter key without typing a damn thing.

My find does not seem to have the -iwholename or -wholename switch fwiw. This is stemming from an issue that I was not able to solve with rar/unrar. I do not know how to script and while I believe I found a couple scripts that seemed to address my issue, I couldn't understand how to compile the script (my most command line familiarity unfortunately is with DOS, so, what's the *nix equivalent of a .bat file?), so I will ask this question as an addendum...

I had .rar files in my /mp3/ArtistName-AlbumName/CD*/ dirs, and I wanted to just unrar the contents to the parent dir, thus negating the need for the above operation with mv (although at this point I would like to know how to do it for pure and simple edification...). I was able to come up with this:
cd mp3
find . -name "*.rar" -exec rar x {} "../" \;

which I thought would do what I wanted but no dice. Believe me I tried moving those dots and slashes, i.e. "../" in all sorts of permutations to no avail. The best I could do that would get me halfway there and actually put me in a postition to use this other find expression was:
find . -name "*.rar" -execdir unrar e {} \;
which will unrar into the same dir as the archives.

So if anyone could answer one or both of these questions I would be immensely grateful. Thank you.

Last edited by krakatoa1; 09-08-2012 at 05:32 AM.
 
Old 09-08-2012, 05:55 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
find . -name './CD*mp3' -print
but the command line returns nothing - no errors, no suggestions, just as if I hit the enter key without typing a damn thing.
That command is looking for the filename CD*mp3, where "*" means "any characters". It is looking in the current directory, which is redundant, since that was specified earlier.

If you want filename in the current directory, in a sub-directory "CD-something", and with the filename ending in "mp3", then try this:
Code:
find . -name "CD*/*mp3"
<<EDIT--this is wrong---see below>>

Last edited by pixellany; 09-08-2012 at 06:30 AM.
 
Old 09-08-2012, 06:04 AM   #3
krakatoa1
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for your quick response... I just pasted what you suggested and it again returns nothing, like I didn't type anything at all
 
Old 09-08-2012, 06:29 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
My mistake!! The -name option works only on the filename. Take a look at the -path option.

Here is a test--I created directories beginning in CD, and then put files ending in mp3 into each:
Code:
[mherring@herring_desk ~]$ ls -R CD*
CD1:
abc.mp3  def.mp3

CD2:
xyz.mp3

CD3:
qrs.mp3
[mherring@herring_desk ~]$ find . -path "*CD*mp3"
./CD3/qrs.mp3
./CD2/xyz.mp3
./CD1/def.mp3
./CD1/abc.mp3
[mherring@herring_desk ~]$
 
Old 09-08-2012, 10:17 AM   #5
krakatoa1
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Still NOT working

Thank you for replying again, however your second suggestion gave me the exact same results; that is to say, nothing. Not an error, not incorrect output, just... nothing. FYI, this is BSD Unix and I am in a bash shell. Yes the OS X implementation. Thank you for trying though
 
Old 09-08-2012, 11:01 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
I'm not used to BSD and I cannot test, but undoubtfully a simple and explicit loop might solve your issue without much effort in seeking a complex one-liner. Let's try something like this:
Code:
#!/bin/bash
while read dir
do
  cd "$dir"
  pwd
  :
done < <(find /mp3/*/ -type d -name 'CD[0-9]*' -print)
This simple bash script has the solely purpose to show that you can easily change directory if you provide the absolute path. The pwd command will show you in which directory you are (just for testing). Once you're inside the directory, do whatever you need to accomplish your task.

After having verified it loops over the correct directories, you can try to put your own commands in place of the null command (see the colon inside the loop).

Sincerely, my only doubt about this simple bash script is if BSD supports process substitution, which is the part that contains the find command and feeds the loop:
Code:
<(find /mp3/*/ -type d -name 'CD[0-9]*' -print)
By the way, you can safely try it (as is) since it doesn't contain any potentially dangerous command (like mv, rm, cp, ln, mkdir, touch and so on) nor the find command contains any other action than -print. Hope this helps.
 
Old 09-11-2012, 03:21 PM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
The find in OS X is a different one. But you can easily compile the GNU find on your own on OS X and have the same options this way.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find command line switch value Cpare AIX 2 06-16-2011 03:44 PM
How to find a file using the command line matrix13 Linux - Desktop 4 11-13-2006 11:45 PM
How do I find the command line? callum85 Linux - Newbie 3 09-27-2006 06:02 PM
Can't find command line barbra Linux - Newbie 3 12-28-2004 02:17 PM
how to find a looooooooong command line acid_kewpie Linux - General 6 11-20-2002 01:37 PM


All times are GMT -5. The time now is 11:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration