(Edit ― in this post ― I only kept the solutions):
• Terminal code; with output into a specific text-file; change it to the file and folder you want. To print only in Terminal instead - remove > /mnt/home/FileList.txt
.
Open Terminal in the folder:
• With suffixes: M, K, B:
Code: Select all
du -a -d 1 --block-size=1 | sort -rnk1 | numfmt --to=iec --field=1 | awk '{print substr($0, index($0,$2)), "\t" $1}' | sed 's_./__' > /mnt/home/FileList.txt
• With suffixes: MiB, KIB, B:
Code: Select all
du -a -d 1 --block-size=1 | sort -rnk1 | numfmt --to=iec-i --suffix=B --field=1 | awk '{print substr($0, index($0,$2)), "\t" $1}' | sed 's_./__' > /mnt/home/FileList.txt
With subfolders; either:
• Large to small:
Code: Select all
du -a --block-size=1 | sort -rnk1 | numfmt --to=iec-i --suffix=B --field=1 | awk '{print substr($0, index($0,$2)), "\t" $1}' | sed 's_./__' > /mnt/home/FileList.txt
• Small to large:
Code: Select all
find "$@" -type f -printf "%s %p\n" | sort -nk1 | numfmt --to=iec-i --suffix=B --field=1 | awk '{print substr($0, index($0,$2)) "\t\t" $1}' | sed 's_^./__' > /mnt/home/FileList.txt
-----------------------------
Explanations:
“|” separates the kinds of commands.
""\t" " ― is the separating tab. To have more tabs - add more "\t"s.
Largest to smallest ― change sort -nk1
to sort -rnk1
.
delete "./" ― add | sed 's_./__
Search in sub-folders too ― change du -a -d 1
to du -a
.
You can put the file names in quotes with the following:
Code: Select all
du -a -d 1 --block-size=1 | sort -rnk1 | numfmt --to=iec --field=1 | awk '{print "\"" substr($0,index($0,$2)) "\"" ,$1}' | sed 's_./__' > /mnt/home/FileList.txt
-----------------------------
• Program ― Double Commander; with which it's possible to create a list of files in a folder; among many other things. (Portable; unpack(for instance to /opt/). The file to launch the program - “doublecmd”).
-----------------------------
• Script: in /root/my-applications/bin/ Mouse right-click → New → Script. Open the file as text ― and paste the code:
Code: Select all
#!/bin/sh
du -a -d 1 --block-size=1 | sort -rnk1 | numfmt --to=iec-i --suffix=B --field=1 | awk '{print substr($0, index($0,$2)), "\t" $1}' | sed 's_./__' > /mnt/home/FileList.txt
To call upon the Script ― Terminal:
cd /mnt/home/the folder you want to load
NameOfTheScript > /mnt/home/FileList.txt
-----------------------------
• Another way:
MochiMoppel wrote: ↑Sun May 09, 2021 3:05 am@williams2 I tried to push this a little further to make it behave and (almost) look like DoubleCommander. Not sure if this is what MrAccident needs but this is how I would like the output to look like (except for the "human readable" format which I find less readable than sizes in bytes with thousand delimiters).
Includes hidden files, removes '->' trailers from links and keeps directories always on top
Code: Select all
MAX=$(ls -1 | wc -L) #find width of longest file name IFS=$'\t\n' #make sure that printf "sees" only 2 (tab delimited) strings per line printf "%-${MAX}s\t%5s\n" $( #print filenames left aligned, sizes right aligned ls -lAh | awk 'NR>1 { #include hidden files, format sizes as human readable, ignore 1st total line if (substr($1,1,1)=="d") $5="9999G" #make sure that directories are listed on top if (substr($1,1,1)=="l") sub(" ->.*","") #in case of links remove trailing " -> /path/of/link/target" print substr($0,index($0,$9))"\t"$5}' | #print field 9 to end of line (=filename),then a tab, followed by field 5 (=size) sort -t$'\t' -hrk2 | #sort 2nd field (=size) of awk output sed 's/9999G/<DIR>/' #remove fake directory size )