Welcome to WebmasterWorld Guest from

Forum Moderators: bakedjake

Message Too Old, No Replies

Bash command for last listing in directory



3:34 pm on Oct 13, 2010 (gmt 0)

5+ Year Member

How, in Bash, would you get the alphabetically last subdirectory in a directory.

This is for an incremental rsync backup system. I want to name the directories by (ISO8601) date rather than using (fixed) numbered backups, but whether I use cp -al or use the --link-dest options, I need to know the directory of the last backup (I think).


8:10 pm on Oct 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

This seems to work for me on the command line:

ls -1|grep pattern|tail -n 1

pattern should be something that matches the subdirectories you want given your naming scheme.

I am a Bash newbie (I have used Linux for a long time, but GUI and other scripting languages) so please test or wait for more expert comments before using for anything as important as backups.


9:14 am on Oct 14, 2010 (gmt 0)

5+ Year Member

Dagnammit, I know all those commands... I just keep forgetting about pipes!

Seems a sensible suggestion to me. Thanks for the reminder.

Featured Threads

Hot Threads This Week

Hot Threads This Month