combine output from 2 linux commands into one output -


in linux there way present output of 2 different commands refer same object give different data in interlaced format without scripting.

to explain mean when interlaced format consider following.

ls --full-time  

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

du -sh ./* 

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

if run 1 command followed other of sizes each on own line folder name next each size , of dates each accompanied folder name on own line.

by "interlacing" mean first line out output each command presented, preferably on 1 line. second line of output each command presented in same fashion (ect). i.e data displayed date, size , name of each folder appear on same line despite fact not of data provided same command. (i dont mind if folder name displayed twice since provided both commands).

tl;tr: commands below show how use join command above input. individual task of displaying filesize in human readable format along other ls output values can achieved with:

ls --full-time -lh 

note -h.


you can use join command process substitution:

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

if want nice, aligned output can pipe column command:

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

i'm joining on 2nd column of du output , 9th column of ls output filename. try yourself.


example:

let's folder contains files 1.txt, 2.txt, 3.txt. output 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 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -