Reputation: 6461
I have a bunch of directories that I are named with the following time stamp format:
2013-12-04_18_12_40
2013-12-04_19_12_22
2013-12-04_19_46_45
2013-12-04_20_31_04
2013-12-04_21_04_54
2013-12-05_11_15_24
i.e. YYYY-MM-DD-HH-MM-SS
I want a bash script to CD into the latest directory. So in this case it would be
2013-12-05_11_15_24
i.e. the latest directory will always be the biggest number.
How do I determine the latest directory in a nice way that can be used in a script?
Thanks
Upvotes: 2
Views: 38
Reputation: 785721
Though generally it is not recommended to parse ls
's output but in this case you can probably do:
cd "$(ls -rd [0-9]* | head -1)"
Upvotes: 1