I'm trying to figure out how to pick a random file in bash. So for example, I use 'ls' to generate a list of all the files in the current directory. I then want to be able to pipe (|) it to a "random" command that will return the name of one of the files chosen randomly. I know you can generate a random number with bash. So I assume the way to go about this would be to put the output of ls in an array and then generate a random number based on the length of the array. And then use that random number to return a random filename.
That might be totally wrong (I'm basing that solely on prior knowledge of other languages). I'm just interested in an easy way to go about this.
Bookmarks