What Does " */./* "mean?
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.
I type this: Code:
mplayer -shuffle ~/music/oldmusic/directorycontainingsubdirectories/*/./*.mp3 I don't understand what the Code:
*/./* I know it's something simple- the * is like a wildcard that means "everything", right? What is the "." for? What exactly is */./* saying? [Cool thing is, I made an alias, so I can just type one word, and BOOM! Mplayer starts playing the files mentioned above. Man, I LOVE Linux!] |
Quote:
Code:
So I think that the './' is redundant. Try it without the './' in the path and see what happens. |
Yes * is a glob to get all in a directory (not including hidden files).
. on its own is the current directory, just as .. is the directory above in the context of */./*.mp3 I do not see a need for the ., so I believe you could have just written */*.mp3 |
Code:
less ./././././././././././././././example.txt Code:
less example.txt |
You guys nailed it!
I tried it without the /./ and it worked just the same. Code:
~/music/oldmusic/directorycontainingsubdirectories/*/* Code:
*/./* And so, in like manner, if I were to do Code:
mplayer -shuffle ~/music/*/*/*/* Would it play everything at every "level"? i.e. would it play both: Code:
~/music/somecrappysong.mp3 Code:
~/music/oldmusic/blahblahblah/crustyoldie.mp3 Thanks, everyone! |
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 /
|
Quote:
|
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" Code:
find ~/music -iname "*.mp3" | xargs mplayer -shuffle |
Quote:
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:
Code:
find ~/music -iname "*.mp3" -print0 | xargs -0 mplayer -shuffle Code:
find ~/music -iname "*.mp3" -exec mplayer -shuffle {} + |
Quote:
One question, for my edification: What does the "{} +" mean? |
"{}" means "stick the matching filename here".
There are two ways to end -exec in find: 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 |
Quote:
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? I mean, could I do this: Code:
find `/<location> -iname "*.JPEG" -exec mv /<newlocation> *.jpg \ Code:
find `/<location> -iname "*.JPEG" | mv /<newlocation> *.jpg \ 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..... Edit The 2nd: Ah-HA! Maybe: Code:
find `/<location> -iname "*.JPEG" | mv {} /<newlocation> *.jpg \ |
Quote:
Code:
find /<location> -iname "*.JPEG" -exec mv {} /<newlocation> \; Code:
find /<location> -iname "*.JPEG" -exec mv -t /<newlocation> {} + Code:
rename .JPEG .jpg /<newlocation>/*.JPEG |
Excellent! Thank you so much, rknichos! This is great info.
And thanks to all who have responded. I've learned far more than just the meaning of " */./* " !!! |
All times are GMT -5. The time now is 11:08 PM. |