Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.


Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.


Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.


Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Random Filename Chooser

Submitted by on June 17, 2008 – 9:02 pm 2 Comments

This is a rather peculiar little script with a purpose that may not be immediately apparent. The script will look for files in the specified folder; it will then pick one at random from the list of matches and create a soft link to it. How is this useful, you ask? There are situations where you want to access the same file name but get something different once in a while.

Imagine you access “default.htm”, which is a dynamically updated link to a random page from a given set. Or, perhaps, you have an application use a particular file for input and you want to rotate the input sources at random, selecting from a specific set of choices.



FILENAME=$(ls $INPUT_DIR | grep ".xml$" | while read FILE
        echo "`expr $RANDOM % 1000`:$FILE"
done | sort -n| sed 's/[0-9]*://' | head -1)

if [ -f ${INPUT_DIR}/default.xml ]
       rm ${INPUT_DIR}/default.xml

ln -s ${INPUT_DIR}/${FILENAME} ${INPUT_DIR}/default.xml
Print Friendly, PDF & Email


  • henryshensbcglobalnet says:

    Let’s remember what Mr. George Bush did while he was in office:

    –started the Iraq War
    –started the Afghanistan War
    –bailed out the banks
    –bailed out the insurance companies
    –bailed out the car companies
    –socialized medicine
    –was in power when the economy crashed
    –expanded the federal government
    –doubled our national debt

    Yes, all that is true–and you damn well know it–but you choose not to remember. Instead, you bash Obama and blame everything on Obama because it’s convenient. You know how stupid many Americans are, and so you are trying to brainwash them into believing that Obama started all of the wars and the deficits and the bailout programs and the health care socialization.

    I don’t side with either party, but I think it’s a bit unfair to blame everything on Obama when Bush handed him an absolute mess on every front imaginable. In fact, In fact, Obama shows a lot of class by now reminding eveyone of how incompetent of a president Bush was. Bush was unfit to run a hardware store, and you guys ought to know it. He couldn’t speak English, invaded countries for no reason, promised to be a conservative but turned out to be a socialist, implemented idiotic tax breaks, bailed out banks and car companies…..(I could go on and on, but I’m sure you’re now remembering how idiotic Bush was.)

  • Mr SoLo DoLo says:

    When liberals bashed Bush, people said they were unpatriotic terrorist sympathizers. But if you bash Obama, it’s not seen as unpatriotic you’re just critical of your government. Why the double standard?

Leave a Reply

%d bloggers like this: