Help shell script to list filename file_path

HI
owner date and time and size of file in a row
shell script to list filename file_path i have tried the below code

present_dir=`pwd`
dir=`dirname $0`
list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` 
size=`du -h`
path=`cd  $dir;pwd;`
printf  "$list" 
printf "$path"
printf " $size"

but im not getting the path for every file and it is not displaying in one row:confused:
my output should be like:

filename filepath owner date and time size

it has to list in this way

one=foo
two=bar
three=baz
printf "%s %s %s\n" "$one" "$two" "$three"

You only get the path once because you're only outputting it once. Your $list has multiple lines in it, but they're not joined to the path output (or the size, for that matter).

One approach could be to just use a for loop, similar to:

for i in *
do
   filesize=$(du -h $i)
   fileinfo=$(ls -l $i | awk '{printf $3,$6,$7,$8}')

   printf "%s %s %s %s\n" $i $filepath $fileinfo $filesize
done

EDIT: Forgot to set $filepath, but you should get the idea...

You can try this also

ls -lrt -h | awk -v a=$PWD 'BEGIN{print "filename\tfilepath\towner\tdate\ttime\tsize"}{print $9,a,$3,$7"-"$6,$8,$5}' OFS=\\t >filelog.dat

if you need full date and time use this

ls ---full-time -h

You may want to try (given stat is available on your system):

stat -c"%n   $PWD    %U      %y      %s" *
1 Like