1

I'm downloading my code from my private repo. When the download is finished using the following command :

wget -O project.tar.gz https://gitlab.com/api/v4/projects/1/repository/archive?private_token=XXXXXXXXXXXXX

I end up with an archive :

project.tar.gz

Which I extract

tar -zxf project.tar.gz

And it gives me the following folder :

project-master-97fe635dc27fb89bd16e3448bf6915420

But I have an older downloaded folder in the same path, so I have :

folder
│
└─── project-master-97fe635dc27fb89bd16e3448bf6915420
|
└─── project-master-28ba625ab48ac14bd25c7119aa9511271

I have the following command to find the folder :

find /path/ -name "project-master-*"

But its output me 2 results :

/path/project-master-97fe635dc27fb89bd16e3448bf6915420
/path/project-master-28ba625ab48ac14bd25c7119aa9511271

I would like to output only the most recent repo version :

/path/project-master-97fe635dc27fb89bd16e3448bf6915420
executable
  • 3,365
  • 6
  • 24
  • 52

1 Answers1

1

Don't use find for this. You should use ls for sorting by modification time and head to pick the newest one:

$ ls -dt /path/project-master-* | head -1

ls -dt lists directories (not their content), and sorts them by modification time.

Solution works for directories without spaces and/or other special characters.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
svante
  • 1,375
  • 8
  • 9
  • 1
    [Why *not* parse `ls`?](http://unix.stackexchange.com/questions/128985/why-not-parse-ls) – Cyrus Oct 23 '19 at 09:02