1

I use rsync to back up my files using --link-dest to sync only differences from the last backup folder.

Is there anyway I can see a directory listing ordered by date and restricting it to --max-depth=1 or -d 1?

For instance, this shows depth of one directory:

$ du -h --max-depth=1
33G     ./05-12-2021-16:00
4.7G    ./05-12-2021-12:30
4.6G    ./05-12-2021-11:30
11G     ./06-12-2021-13:30
4.8G    ./06-12-2021-02:00
19M     ./06-12-2021-08:58
4.7G    ./05-12-2021-21:00
938M    ./05-12-2021-02:11
754M    ./05-12-2021-19:00
32M     ./06-12-2021-02:30
179M    ./05-12-2021-13:30
172M    ./05-12-2021-17:30
4.7G    ./05-12-2021-22:00
752M    ./05-12-2021-20:00
170M    ./05-12-2021-17:00
4.7G    ./06-12-2021-12:01
934M    ./05-12-2021-12:00
38M     ./05-12-2021-14:00
175M    ./06-12-2021-12:31
34M     ./05-12-2021-18:00
388M    ./05-12-2021-16:30
42M     ./06-12-2021-14:01
4.7G    ./05-12-2021-00:54
756M    ./06-12-2021-11:33
173M    ./06-12-2021-00:31
4.5G    ./06-12-2021-15:31
31M     ./06-12-2021-00:00
1007M   ./05-12-2021-23:01
762M    ./05-12-2021-22:30
31M     ./05-12-2021-21:30
765M    ./06-12-2021-15:01
214M    ./05-12-2021-10:44
32M     ./06-12-2021-01:30
33M     ./06-12-2021-13:00
27M     ./05-12-2021-15:00
166M    ./05-12-2021-11:00
32M     ./06-12-2021-01:01
176M    ./05-12-2021-02:30
27M     ./05-12-2021-15:30
30M     ./05-12-2021-18:30
37M     ./05-12-2021-13:00
31M     ./05-12-2021-20:30
753M    ./05-12-2021-23:30
752M    ./05-12-2021-19:30
43M     ./06-12-2021-14:30
38M     ./05-12-2021-14:30
91G     .

Using the answer here, it sorts by size, but recurses fully into each directory:

$ command ls -dt */ | while IFS= read -r dir; do du -sh "$dir"; done
33G     05-12-2021-00:54/
33G     05-12-2021-02:11/
33G     05-12-2021-02:30/
33G     05-12-2021-10:44/
33G     05-12-2021-11:00/
33G     05-12-2021-11:30/
33G     05-12-2021-12:00/
33G     05-12-2021-12:30/
33G     05-12-2021-13:00/
33G     05-12-2021-13:30/
33G     05-12-2021-14:00/
33G     05-12-2021-14:30/
33G     05-12-2021-15:00/
33G     05-12-2021-15:30/
33G     05-12-2021-16:00/
33G     05-12-2021-16:30/
33G     05-12-2021-17:00/
33G     05-12-2021-17:30/
33G     05-12-2021-18:00/
33G     05-12-2021-18:30/
33G     05-12-2021-19:00/
33G     05-12-2021-19:30/
33G     05-12-2021-20:00/
33G     05-12-2021-20:30/
33G     05-12-2021-21:00/
33G     05-12-2021-21:30/
33G     05-12-2021-22:00/
33G     05-12-2021-22:30/
33G     05-12-2021-23:01/
33G     05-12-2021-23:30/
33G     06-12-2021-00:00/
33G     06-12-2021-00:31/
33G     06-12-2021-01:01/
33G     06-12-2021-01:30/
33G     06-12-2021-02:00/
33G     06-12-2021-02:30/
23G     06-12-2021-08:58/
33G     06-12-2021-11:33/
33G     06-12-2021-12:01/
33G     06-12-2021-12:31/
33G     06-12-2021-13:00/
33G     06-12-2021-13:30/
33G     06-12-2021-14:01/
33G     06-12-2021-14:30/
33G     06-12-2021-15:01/
33G     06-12-2021-15:31/
33G     06-12-2021-16:03/

What I need, is the answer to this question, but ordered by time / date.

I've had a look at the answers here, but I can't see anything helpful:
https://superuser.com/questions/147027/how-can-i-sort-the-output-of-ls-by-last-modified-date
Is there any du (disk usage) command flag that summarizes the size for each sub-directory
https://stackoverflow.com/questions/37272935/unix-command-size-of-directory-with-order-by-size
How to recursively find the amount stored in directory?

2 Answers 2

1

One way, if your du supports --time flag:

du --max-depth=1 --time | sort -k 2

The solution to your second example, without showing the recursive size is to add -S flag to du:

ls -dt */ | while IFS= read -r dir; do du -Ssh "$dir"; done

But this command is unnecessarily complicated. You could make it easier:

du -Ssh "$(ls -Qdt /*)"
3
  • Thanks aviro. I awarded the answer to @Stephan as he replied a few minutes earlier and the output is more succinct, but I also upvoted your reply.
    – NoExpert
    Dec 11, 2021 at 15:00
  • @NoExpert sure, thanks. I would just want to say that the other answer doesn't actually sorts the directories by time, but by their names. If the names of the folders also indicate their time, it does the trick. But it didn't actually answer your question which was "sorting by date". Mine does. But as long as his answer fits your needs and you've learned something from it, it's all good. Next time just be more accurate with your questions, and if the folders names are already sorted by the date, you should have clearly stated that.
    – aviro
    Dec 11, 2021 at 19:59
  • Hi aviro, in fact, you're correct and I've now awarded you the answer. The reason I didn't notice this is because, as you correctly say, the folder names coincidentally sort by date (since they are named after the date / time). PS: looks like -d 1 is the same as --max-depth=1.
    – NoExpert
    Dec 11, 2021 at 20:33
1

You can pipe the output of du into sort -k 2 to sort the results based on the second column:

du -h --max-depth=1 | sort -k 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.