ls -ahlX ~|awk '{printf "%-20s %-40s\n",$9,$5 }'>~/Desktop/Option1.txt
Sorted alphabetically by entry extension.(Using ls -X
)
Includes any hidden files and folders.(Using ls -a
)
Shows all of the file sizes in human readable format(Using ls -lh
)
awk '{print $9,$5 }
just prints the name and size of files and directories
and finally stores in Option.txt.
%-20s %-40s\n
is for formatting the columns
But this will not print full directory name, as pointed out in the comments by @ Glenn Jackman ,if there are spaces in directory name.
So,
Another option would be (source)
ls -ahlX ~|gawk -F':[0-9]* ' '/:/{print $2}'>~/Desktop/Option1.txt
This one prints file names even if there are spaces.
But it is always a bad idea to parse ls.
~/Desktop/Option1.txt
– Sylvain Pineau Apr 03 '14 at 14:49$9
won't contain the full filename if there are spaces. – glenn jackman Apr 03 '14 at 14:52ls
is always a bad idea – Stormvirux Apr 03 '14 at 15:06