commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
* grep -i leaves only mp3 files (case insentitive)
* sort -R randomizes list (may use GNU 'shuf' instead).
* the sed command will add double quotes around each filename (needed if odd characters are present)
Here's my version. It's a bit lengthy but I prefer it since it's all Bash.
Using urandom to get random data, deleting non-letters with tr and print the first $1 bytes.
If you don't have seq, you can use perl.
Ever need to get some text that is a specific number of characters long? Use this function to easily generate it! Doesn't look pretty, but sure does work for testing purposes!
Seeing that _sort_ its been used, why not just _use_ it. ;)
The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible. Human-memorable passwords are never going to be as secure as completely completely random passwords. [from pwgen man page]
According to the gpg(1) manual:
--gen-random 0|1|2 count
Emit count random bytes of the given quality level 0, 1 or 2. If count is not given or zero, an endless sequence of random bytes will be emitted. If used with --armor the output will be base64 encoded. PLEASE, don't use this command unless you know what you are doing; it may remove precious entropy from the system!
If your entropy pool is critical for various operations on your system, then using this command is not recommended to generate a secure password. With that said, regenerating entropy is as simple as:
du -s /
This is a quick way to generate a strong, base64 encoded, secure password of arbitrary length, using your entropy pool (example above shows a 30-character long password).
Give files a random name (don't ask why :-)
The function will rename files but maintain their extensions.
BUG: If a file doesn't have an extension it will end up with a dot at the end of the name.
The parameter '8' for pwgen controls the length of filenames - eight random characters.
Also looks in subfolders
I used only shuf command.
Here's a bash version using an array.
Choose random file from current folder. Avoids using ls.
Good if you have your music like Artist/(Year) Album/Song
random file from files in directory
The same thing using only Bash built-in's.
For readability I've kept the variables out, but it could me made extremely more compact (and totally unreadable!) by stuffing everything inside the single echo command.
Select a file/folder at random.
I use this command to select a random movie from my movie collection..
fixes a problem with bad bytes in /dev/urandom on Mac OS X
This will show a random cow with cowsay.
A bash version.