13

This is standard ls -l output.

user@linux:~$ ls -l
total 0
-rw-rw-r-- 1 user user 0 Nov   1 00:00 file01
-rw-rw-r-- 1 user user 0 Nov   1 00:00 file02
-rw-rw-r-- 1 user user 0 Nov   1 00:00 file03
user@linux:~$ 

Would it be possible to add new line like this?

-rw-rw-r-- 1 user user 0 Nov   1 00:00 file01

-rw-rw-r-- 1 user user 0 Nov   1 00:00 file02

-rw-rw-r-- 1 user user 0 Nov   1 00:00 file03
2
  • 11
    But why? If it is to make it more readable, then consider changing to a different font, and different line spacing. Nov 30 '19 at 19:12
  • 1
    I agree with the above question. Please provide some rationale for your issue. Thank you. Dec 1 '19 at 7:25
20
ls -l | sed G

(that one is a common idiom and on the sed FAQ).

Or (likely faster, probably doesn't matter for the (likely short) output of ls -l):

ls -l | paste -d '\n' - /dev/null

Those insert a blank line after each line of the output of ls -l.

Now, if you want an empty line after each file described by ls -l, which would be different if there are files whose name contains newline characters, you would have to do something like:

for f in *; do ls -ld -- "$f" && echo; done

(which would also skip the total line).

Or you could use ls -ql which would make sure you get one line per file (the newline characters, like all control characters would be rendered as ? (at least in the POSIX locale)).

5

Using awk:

ls -l | awk '{printf "%s\n\n", $0}'
2
  • 2
    ... or perhaps more idiomatically, ls -l | awk 1 ORS='\n\n' Nov 30 '19 at 17:27
  • 1
    Or ls -l | awk '{print $0 "\n"}'
    – U. Windl
    Dec 1 '19 at 0:40
4
NAME
       pr - convert text files for printing

Interleaving with single empty line, w/o adding header:

… | pr -dt

1
  • 2
    Note that pr also treats formfeed characters specially in its input (with the behaviour varying between implementations) Dec 1 '19 at 7:57
2

One more:

ls (options) | while read LINE; do
  echo "$LINE
"
done
6

Your Answer

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