Can ls -l be made to separate fields with tabs rather than spaces to make the output useful in a spreadsheet?

Try:

ls -l | awk -v OFS="\t" '$1=$1'

Or, if your filenames have spaces:

ls -l | awk '{print $1,"\t",$2,"\t",$3,"\t",$4,"\t",$5,"\t",$6,"\t",$7,"\t",$8,"\t",$9,$10,$11,$12,$13,$14,$15;}'

I've made a shell script for the same. It takes care of the cases when the filenames have spaces or any other special characters.

#! /bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for file in $(ls)
do
    stat --printf="%A\t%h\t%U\t%G\t%s\t" $file
    mod_epoch=$(stat --format="%Y" $file)
    mod_month=$(date -d @$mod_epoch +"%b")
    mod_day=$(date -d @$mod_epoch +"%d")
    mod_time=$(date -d @$mod_epoch +"%H:%M")
    printf "%s\t%s\t%s\t%s\n" $mod_month $mod_day $mod_time $file
done
IFS=$SAVEIFS
  • Save it to a file, say ls_tab.sh
  • Make it executable:
chmod +x ls_tab.sh
  • Run it:
./ls_tab.sh

Note: This can be done by parsing the output of ls, however the reason why it should not be done is given here.

Tags:

Ls