Page 2 of 2

Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Mon May 10, 2021 7:47 pm
by MrAccident
williams2 wrote: Mon May 10, 2021 7:05 pm

If this is a script named largest
then largest would list all file in the current working dir and subdirs,
and largest /mnt/videos/ /root/downloads/ would list all files in /mnt/videos/ and in /root/downloads/ and subdirs.
It will not list dirs or symlinks.

I don't understand. Where do I use these codes?


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Mon May 10, 2021 8:38 pm
by williams2

If you make a script,
for example in a roxfiler window showing /root/my-applications/bin/ you could right-click and click New, Script and name the script largest
Then you could right-click the script named largest and copy/paste the code, like this:

Code: Select all

#!/bin/sh
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_^./__' 

then you could run the script like this:

Code: Select all

cd /mnt/home/videos/
largest > /mnt/home/FileList.txt

Or you could run the script with the dirs you want, like this:

Code: Select all

largest /mnt/home/videos/  /mnt/home/mp3s/ > /mnt/home/FileList.txt

or you can put > /mnt/home/FileList.txt in the script.

It could ignore files smaller than a certain size, if you want.


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Mon May 10, 2021 8:53 pm
by williams2

Personally, I prefer size - filename, like:

Code: Select all

151K /bin/netstat
154K /bin/cpio
167K /bin/less
215K /bin/grep
339K /bin/udevadm
414K /bin/tar
938K /bin/busybox
1.1M /bin/bash

Posted: Mon May 10, 2021 10:53 pm
by MrAccident

@williams2:

Then you could right-click the script named largest and copy/paste the code, like this:

I don't understand how I can do that. I can only copy the file, in the right-click context-menu.


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Mon May 10, 2021 10:55 pm
by williams2

i didn't realize that sort can sort human readable numbers ( sort -h instead of sort -n )

du -ah | sort -rhk1


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Tue May 11, 2021 5:50 am
by MochiMoppel
MrAccident wrote: Mon May 10, 2021 4:28 am

@MochiMoppel - Chef's Kiss.
Still a little question ― why "b" for file-sizes in bytes isn't shown?

You mean "B", like "K" and "M"?
This would be inconsistent.


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Tue May 11, 2021 6:11 am
by williams2

I don't understand how I can do that. I can only copy the file, in the right-click context-menu.

You can right click a file and select Open As Text so you can edit the file.
Or hold the shift key down and left click the file.

While the file is open in a text editor like Geany,
you can copy and paste in the text editor's window, and then save the changes.


Posted: Wed May 12, 2021 3:24 am
by MrAccident

@MochiMoppel:

You mean "B", like "K" and "M"?
This would be inconsistent.

I don't understand what this means. With the code from williams2 ― the suffixes after the sizes are: MiB, KiB, B.

@williams2:
Worked.
Will add the solutions to the first post.

Thank you all.


Re: How to get a list of files in a folder + sizes , as text? (Solved)

Posted: Wed May 12, 2021 3:49 am
by williams2

If you want K M G rather than KiB MiB GiB
then change numfmt --to=iec-i --suffix=B to numfmt --to=iec