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

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

User avatar
MrAccident
Posts: 279
Joined: Mon Aug 03, 2020 4:29 am
Has thanked: 41 times
Been thanked: 8 times

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

Post 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?

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

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

Post 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.

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

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

Post 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
User avatar
MrAccident
Posts: 279
Joined: Mon Aug 03, 2020 4:29 am
Has thanked: 41 times
Been thanked: 8 times

Post 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.

Last edited by MrAccident on Mon May 10, 2021 11:04 pm, edited 2 times in total.
williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

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

Post by williams2 »

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

du -ah | sort -rhk1

User avatar
MochiMoppel
Posts: 1231
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

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

Post 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.

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

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

Post 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.

User avatar
MrAccident
Posts: 279
Joined: Mon Aug 03, 2020 4:29 am
Has thanked: 41 times
Been thanked: 8 times

Post 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.

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

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

Post 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

Post Reply

Return to “Users”