0

Can you make an alias command that basically formats the out put of ls into two columns, so that the output shows all the subdirectories in column 1 and all the files in column 2.

Example:

me:~$ ls
dir1               file1.txt
dir2               file2.xml
dir3               file3.pdf
dir4               file4.png
dir5               file5.wav
dir6               file6.mp3
...                file7.doc
                   ...

You get the idea :) (Maybe even put the executables in column 3?)

Is this possible?

OS version: Ubuntu 18.04

  • Is there a particular reason why you removed all those things @Rui F Ribeiro ? Was it too personal? – Ciarán J. Hagen Dec 6 '18 at 11:20
  • It might be in your interest keeping your posts succinct and on topic, for getting more attention and up voting. There is also a tradition of editing posts here for consistency and redundancy. See our FAQ and keep around. btw, welcome. – Rui F Ribeiro Dec 6 '18 at 11:46
  • I will keep that in mind for future posts :D Thx – Ciarán J. Hagen Dec 6 '18 at 13:08
0

stat around (you didn't comment on your OS version)? try

stat -c$'%F\n%n' * | awk '/^directory/ {getline LEFT[++DC]; next} {getline RIGHT[++FC]} END {for (i=1; i<=(DC>FC?DC:FC); i++) print LEFT[i], RIGHT[i]}' OFS="\t"
dir1    awkscript
dir2    fil1
dir3    file
dir4    file~
        file1
        file1~
        file2
  • This is what I'm looking for, only it prints column 2 relative to column 1. This makes the second column non-parallell. Is there a way to fix this? – Ciarán J. Hagen Dec 6 '18 at 13:08
  • btw OS version: Ubuntu 18.04 Bionic Beaver – Ciarán J. Hagen Dec 6 '18 at 13:14
  • pipe it through column -nt. – RudiC Dec 6 '18 at 13:20
  • There is one small problem still, in that it prints files with a whitespace in their filename in two columns... Is there a way to remedy this? – Ciarán J. Hagen Dec 7 '18 at 14:33
  • You may want to change to using formatted printf with sufficient field widths in the awk script, also eliminating the need for the column command. – RudiC Dec 7 '18 at 14:37

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.