What about this?:
Bash:
ls -sh | awk '{printf "%-30s %s\n",$2,$1}'
That should do the trick nicely!
The file-system object names and their sizes are listed in distinct columns.
In
awk
, I've used the
printf
command to allow us to format the output.
The
%-30s
gives us a field of 30 characters to put the names of the files/directories etc in the listing.
And the final
%s
is where the file-size will go.
So
$2
- The name of the file-system object, is substituted into the 30 character wide string field.
And
$1
- The size of the file-system object, is substituted into the other string field.
NOTE: If 30 characters is too wide, or not wide enough - feel free to alter that value!
Also, because the output from
ls
is piped to awk - it loses it's colouring - which helps you to differentiate between files, directories and other file-system objects like symbolic links, if you have it enabled. So if you want to be able to easily tell which objects are files and which are directories, symbolic links, etc. You could optionally use the
ls
commands
-F
switch, which outputs an additional special character at the end of the name of each file-system object listed.
e.g.
Bash:
ls -shF | awk '{printf "%-30s %s\n",$2,$1}'
This lists everything in two columns as before, but the names of each object in the listing may have an additional character at the end, to indicate which type of FS object it is.
Using
-F
:
- Regular files don't have any extra characters at the end of their names. So if there are no characters at the end of the file-name - it's just a normal file.
- Executable files have an
*
after their names.
- Directories have a
/
after their names.
- Symbolic links have a
@
after their names.
- Sockets have an
=
after their names.
- FIFO pipes have a
|
after their names.
There are a couple of symbols for other types of objects, like
%
for whiteouts. But you won't find those on your usual file-system, I think they're specific to OverlayFS, which I think is used by the kernel. I can't remember what the others are - I think they may be things that are used on older UNIX file-systems. I can't remember offhand!
But the symbols listed above are probably the only ones that you're likely to see in your day to day usage!
Hopefully this helps!