Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So I figgered[sic] out how to run Mplayer from the terminal, and to specify that it play all files in all folders in a specified directory- now that I know HOW to do it, I want to know WHY it works.
So I figgered[sic] out how to run Mplayer from the terminal, and to specify that it play all files in all folders in a specified directory- now that I know HOW to do it, I want to know WHY it works.
This enables me to shuffle all the files contained in the 66 subdirectories....
I don't understand what the
Code:
*/./*
means.
Unless mplayer has some esoteric path specifications, I would take that to mean...
Code:
~/music/oldmusic/directorycontainingsubdirectories/*/./*.mp3
all subdirectories and all mp3 files in those subdirectories.
which should be the same thing as...
~/music/oldmusic/directorycontainingsubdirectories/*/*.mp3
'./' simply means "this directory"
So I think that the './' is redundant. Try it without the './' in the path and see what happens.
I thought that might be the case....but the funny thing is, I got the
Code:
*/./*
from a reply to someone else's question on another forum, when I Googled for a way to play all subdirectories within a directory without having to make a playlist for Mplayer. It looked wrong to me, but I thought maybe i was just missing something, as I'm no 'puter geek!
And so, in like manner, if I were to do
Code:
mplayer -shuffle ~/music/*/*/*/*
It would play everything in ~/music?
Would it play everything at every "level"?
i.e. would it play both:
Code:
~/music/somecrappysong.mp3
AND
Code:
~/music/oldmusic/blahblahblah/crustyoldie.mp3
???
Thanks, everyone!
Last edited by Sumguy; 10-19-2014 at 08:28 AM.
Reason: I effed-up!
No ... it will only play all the files at the end of the chain, ie all those that exist in the directory after the last /
Ah, kinda what I suspected. Just for reference, would there be any way to specify a path which would allow it to play files contained at different levels?
As grail said, the "/" forces it to only match directories. So if there are any files 2 levels down, they will be skipped and it will ONLY pass into directories, and those directories' subdirectories, and those subdirectories' files.
If you want to match any mp3 files at any level, you're better off using find.
Code:
find ~/music -iname "*.mp3"
I imagine you could then pass the list into mplayer with xargs
As grail said, the "/" forces it to only match directories. So if there are any files 2 levels down, they will be skipped and it will ONLY pass into directories, and those directories' subdirectories, and those subdirectories' files.
If you want to match any mp3 files at any level, you're better off using find.
Code:
find ~/music -iname "*.mp3"
I imagine you could then pass the list into mplayer with xargs
Just running the find command as youy specified, indeed finds all of the mp3's at any level under /music [This forum really needs a thumbs-up emoticon!]
But I suspect that piping it to mplayer requires a little more tweaking- trying it as specified, it had a few problems: It would attempt to play some files, but then say "file not found"[but it did play others]; the shuffle was not working; and when I'd hit enter to jump to the next track, it had no effect. Maybe a certain option has to be specified in mplayer?
This is VERY interesting, and very helpful- I have just learned a lot, that will be of great use to me as it pertains to many other scenarios! [Until now, I had never even heard of xargs!]
EDIT: Hmmm....maybe what we need here is something to just specify that the results of find be exported as a list to mplayer? [I'm clueless as to how to acheive that, but it should be easy for you guys!]
You will run into problems if any of the file or directory names include embedded whitespace characters. Each "word" will be passed as a separate argument, and mplayer won't be able to find a file by that name. A solution for that is to tell find and xargs to use the NUL character as a separator:
You will run into problems if any of the file or directory names include embedded whitespace characters. Each "word" will be passed as a separate argument, and mplayer won't be able to find a file by that name. A solution for that is to tell find and xargs to use the NUL character as a separator:
1) "\;" - when you use this format, it will run the command once per matching file
2) "+" - when you use this format, it will run the command just one time, with all matching files
1) "\;" - when you use this format, it will run the command once per matching file
2) "+" - when you use this format, it will run the command just one time, with all matching files
Thank you!!!
I'm intending to learn some basic scripting over the winter, as time permits, but so far, just what I've learned in this thread will help me do/simplify some other tasks.
Would the above apply to the "mv" command as well?
(Sorry if I'm being a pain and an info glutton, but this is the best and fastest way for me to learn this stuff, as it is specific to what I need to do, and thus I will actually use it- and once I actually do it a few times, I'll remember it- unlike watching hours of youtube tutorials and then forgetting 99% of it after 15 minutes! )
EDIT: No, I know something is wrong there, regardless- as I somehow need to specify in the first part of mv where the file is coming from, not just the new location.....
Close, but besides that stray back quote (that I assume is a typo) there are two problems. First, you don't want that final "*.jpg" on the mv command. It's getting its source arguments pasted in by find in place of the "{}" marker, and mv can't do name transformations like the rename command does. Second, you're missing the final semicolon. So, this would work:
but if there is a large number of files it's inefficient because it invokes mv separately for each file. Trying to use "+" to move multiple files in one invocation runs into the problem that find insists on "{}" coming last in the argument list. The mv command has a "-t" (--target-directory) option to get around that as well:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.