Welcome to WebmasterWorld Guest from 50.19.0.90

Forum Moderators: bakedjake

Message Too Old, No Replies

Bash command for last listing in directory

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

Full Member

5+ Year Member

joined:Jan 4, 2007
posts:221
votes: 0


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)

Senior Member from LK 

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

joined:Nov 16, 2005
posts:2414
votes: 16


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)

Full Member

5+ Year Member

joined:Jan 4, 2007
posts:221
votes: 0


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

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members