2

I'm using gfind running on MacOS, to find text files.

I am trying to see the filenames only and the birthdate of my gfind results, and then sorting them by date, and paging them. Is this achievable?

For the moment I am trying gfind . -name "*.txt" -printf "%f \t\t %Bc\n"

But the results are the following:

todo.txt         Fri Mar  4 17:47:41 2022
99AC1EF5-6BE3-556B-8254-84A8764819E0.txt         Fri Mar  4 17:49:08 2022
chrome_shutdown_ms.txt       Fri Mar  4 17:48:07 2022
index.txt        Fri Mar  4 17:48:05 2022
index.txt        Fri Mar  4 17:48:05 2022
index.txt        Fri Mar  4 17:48:06 2022
index.txt        Fri Mar  4 17:47:46 2022
index.txt        Fri Mar  4 17:48:01 2022
index.txt        Fri Mar  4 17:48:01 2022
index.txt        Fri Mar  4 17:48:05 2022
index.txt        Fri Mar  4 17:48:05 2022
index.txt        Fri Mar  4 17:48:06 2022
index.txt        Fri Mar  4 17:48:06 2022
index.txt        Fri Mar  4 17:47:46 2022
index.txt        Fri Mar  4 17:48:06 2022
LICENSE.txt          Fri Mar  4 17:48:07 2022
english_wikipedia.txt        Fri Mar  4 17:48:07 2022
female_names.txt         Fri Mar  4 17:48:07 2022
male_names.txt       Fri Mar  4 17:48:07 2022

Is there a way to tabulate the output in order to show some consistency as to what it looks like ? I would like to only show the filenames and the birthdate in a more elegant way.

Thanks a lot in advance!

  • 2
  • 2
    Using the suggestion in the (currently) accepted answer of the duplicate question: gfind . -name '*.txt' -printf '%f|%Bc\n' | column -t -s '|' (| is any character not present in any filename). – Kusalananda Oct 14 '22 at 05:42
  • Thanks a bunch @Kusalananda!! This actually worked flawlessly. I could not thank you enough. – mariano-daniel Oct 14 '22 at 05:49
  • @Kusalananda, now that I have you here; do you know where's good documentation on where and why the dollar sign before a single quote expands escape sequences? This is the fist time I hear about this, and I'm googling about it, but all I find is examples of people wanting to escape the dollar sign. Thanks again! – mariano-daniel Oct 14 '22 at 05:53
  • 1
    In the bash manual, look for the section called "QUOTING". The $'...' quoting is described a bit down there. The "ANSI C" quoting $'...' in the zsh shell is more or less the same as in bash but the manual is harder to read. See also various post on this site: https://unix.stackexchange.com/search?q=%22ansi+c%22+quoting+ Possibly a good start: Which shells support ANSI-C quoting? e.g. $'string' – Kusalananda Oct 14 '22 at 06:01
  • Thanks again for your time and explanation @Kusalananda! This is very valuable info for me! I will carefully read those links in order to understand this better. Thanks! – mariano-daniel Oct 15 '22 at 03:08

1 Answers1

2

Here, you can use:

gfind . -name '*.txt' -printf '%-40f %Bc\n'

or

gfind . -name '*.txt' -printf '%40f %Bc\n'

To print the file name left-aligned or right-aligned padded with spaces to a length of 40 bytes (not characters, nor columns unfortunately).

That would align them as long as file names don't contain control, multi-byte, zero-width or double-width characters, are are not longer than 40 bytes.

Note that if you put the date first (here using the mtime (%T), not the Btime (%B) which I doubt is what you want as it doesn't reflect anything useful in the life of the file), and use a more useful and unambiguous timestamp format like the standard YYYY-MM-DDTHH:MM:SS[.subsecond]+ZZZZ, then you don't have to worry about alignment and it makes the sorting easier:

find . -name '*.txt' -printf '%TFT%TT%Tz %f\n'
  • Thanks a lot for taking the time for such a detailed comment! @Stéphane! Your take actually looks more streamlined, since I don't have to pipe the output. I did notice the special chars messing up with the output but I can live with that. One last Q: If I use the mtimeand then make any modifications for the file, how can I still see the file 'creation date' so to speak? Thanks again! – mariano-daniel Oct 15 '22 at 03:17