3

In linux is there any way to present the output of 2 different commands which refer to the same object but give different data in an interlaced format without scripting.

To explain what I mean When I say interlaced format consider the following.

ls --full-time 

will show the full time stamp and folder name of each child folder in the current directory.

du -sh ./*

will show the total size and name of every child folder in the current directory.

If I was to run one command followed by the other I would get all of the sizes each on their own line with a folder name next to each size and then I would get all of the dates each accompanied by a folder name on their own line.

By "interlacing" I mean the first line out output for each command is presented, preferably on one line. Then the second line of output for each command is presented in the same fashion (ect). I.E all this data would be displayed so that the date, size and name of each folder all appear on the same line despite the fact that not all of this data is provided by the same command. (I dont mind if the folder name is displayed twice since that is provided by both commands).

1
  • check to see if you system has the stat cmd (which stat, it should be there). The man stat to see how to use its printf args. Good luck. Commented Jan 7, 2016 at 16:08

1 Answer 1

3

TL;TR: The commands below just show how to use the join command with the above input. The individual task of displaying the filesize in human readable format along with other ls output values can be achieved with:

ls --full-time -lh

Note the -h.


You can use the join command together with process substitution:

join -1 2 -2 9  <(du -sh *) <(ls --full-time)

If you want a nice, aligned output you can pipe that to the column command:

join -1 2 -2 9  <(du -sh *) <(ls --full-time) | column -t

I'm joining on the 2nd column of du output and the 9th column of the ls output which is the filename. Try it yourself.


Example:

Let's say your folder contains the files 1.txt, 2.txt, 3.txt. The output would look like this:

1.txt  -rw-rw-r--  1  jdoe  jdoe  34000     2016-01-07  17:08:04.017093659  +0100  36K
2.txt  -rw-rw-r--  1  jdoe  jdoe  4000      2016-01-07  17:08:18.353301052  +0100  4,0K
3.txt  -rw-rw-r--  1  jdoe  jdoe  34335000  2016-01-07  17:08:25.293401318  +0100  33M
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.