If I have two files, tmp.txt
and tmp.pdf
, one large and one small, when I type ls -al tmp.*
everything is nicely right justified and I get this output
-rw-r--r-- 1 simon simon 615316 Oct 17 20:55 tmp.pdf
-rw-r--r-- 1 simon simon 0 Oct 17 20:55 tmp.txt
For a reason that doesn't matter, I want to be able to write the output of two separate ls -al
commands to a file, then cat
the file and obtain the same output. But of course, if I do this:
ls -al tmp.txt > foo
ls -al tmp.pdf >> foo
and then cat foo
, I get this
-rw-r--r-- 1 simon simon 0 Oct 17 20:55 tmp.txt
-rw-r--r-- 1 simon simon 615316 Oct 17 20:55 tmp.pdf
Is there a way of mimicking the justified output that ls -al
produces? Obviously, I can use wc -c tmp.pdf
etc to figure out which output is largest, but how would I translate that information into code that would put the requisite number of spaces before the 0 in the first line? Thanks very much for any suggestions.