Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 21 Oct 2014, 01:19
All times are UTC - 4
 Forum index » House Training » Beginners Help ( Start Here)
Need script to find the file size of ISO
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [19 Posts]   Goto page: 1, 2 Next
Author Message
ally


Joined: 19 May 2012
Posts: 851
Location: lincoln

PostPosted: Sun 28 Apr 2013, 16:21    Post subject:  Need script to find the file size of ISO  

hey guys

I have collected puppy ISOs for a while now, recently a call was made for kernel version info so I opened the ISO and got the data from vmlinuz

I had to do this manually as I couldn't understand the script that somebody posted

I had started recorded file sizes on some but not all so thought that somebody could help by generating a script to output ISO name and file size for all ISOs in a directory but also explain how and why it works

if anybody could take up the baton I would be sincerely grateful

cheers

Smile
Back to top
View user's profile Send private message Visit poster's website 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Sun 28 Apr 2013, 18:32    Post subject:  

Code:
du -sh /dir/where/Isos/*.iso

Something like this?

_________________

Back to top
View user's profile Send private message 
DPUP5520

Joined: 16 Feb 2011
Posts: 801

PostPosted: Mon 29 Apr 2013, 06:24    Post subject:  

Code:
du -ah /dir/where/Isos/*.iso


would be the proper code I believe as the -sh switches would only output a total size of the ISO files and -ah would list them seperately

Edit: Only checks current directory and is not recursive

_________________
PupRescue 2.5
Puppy Crypt 528
Back to top
View user's profile Send private message 
ally


Joined: 19 May 2012
Posts: 851
Location: lincoln

PostPosted: Mon 29 Apr 2013, 06:45    Post subject:  

thanks both

over 1600 files so will output to txt file as only small amount ends in terminal

how to obtain output in bytes?

Smile
Back to top
View user's profile Send private message Visit poster's website 
DPUP5520

Joined: 16 Feb 2011
Posts: 801

PostPosted: Mon 29 Apr 2013, 07:09    Post subject:  

Code:
du -a /dir/where/Isos/*.iso


This will put the output in bytes but why the hell would u want that?

_________________
PupRescue 2.5
Puppy Crypt 528
Back to top
View user's profile Send private message 
ally


Joined: 19 May 2012
Posts: 851
Location: lincoln

PostPosted: Mon 29 Apr 2013, 07:26    Post subject:  

that's how I started!

Smile
Back to top
View user's profile Send private message Visit poster's website 
DPUP5520

Joined: 16 Feb 2011
Posts: 801

PostPosted: Mon 29 Apr 2013, 07:32    Post subject:  

How you started? Are you entering everything manually? If you just want to pipe the output into a text file do something like this

Code:
du -a /dir/where/Isos/*.iso | cat > text_file


This will create a file and pipe the output of du to it

Edit: If you are pulling everything from a single directory I think GustavoYz had the better idea using the s switch as long as you are specifying a file type and using * as it will only list the files and not the entire directory like the a switch does so if you have all the ISO files in a single directory and want a list of how big all of them are you could do
Code:
du -sb /dir/where/Isos/*.iso | cat > textfile

or
Code:
du -sm /dir/where/Isos/*.iso | cat > textfile
(For an easier to read output in Mb)
_________________
PupRescue 2.5
Puppy Crypt 528
Back to top
View user's profile Send private message 
CatDude


Joined: 03 Jan 2007
Posts: 1484
Location: UK

PostPosted: Mon 29 Apr 2013, 14:40    Post subject:  

Hello ally

Here is a little script i knocked together (i'm sure it could be improved)
which will recurse through all subdirectories inside of the directory from which the script is run from.

Code:
#!/bin/sh
#
# Clean up previous temp files
rm /tmp/iso-paths
rm /tmp/sizes-fullpaths
rm /tmp/iso-sizes
rm /tmp/iso-names
rm /tmp/iso-sizes_iso-names

sleep 0.5
#Find all ISO's, and redirect output to a temporary file.
find $PWD -name "*.iso" -type f > /tmp/iso-paths

# Now get the file sizes, redirecting output to another temporary file.
for iso in $(cat /tmp/iso-paths) ; do
du -a $iso  >> /tmp/sizes-fullpaths
done

# Split content into two files. (removing the PATH from the second one)
cat /tmp/sizes-fullpaths | awk '{print $1}' > /tmp/iso-sizes
cat /tmp/sizes-fullpaths | awk '{print $2}' | sed 's/^.*\///' > /tmp/iso-names

# Combine the two files back into one.
paste /tmp/iso-sizes /tmp/iso-names >> /tmp/iso-sizes_iso-names



Copy & Paste it into a text file, and save it (as whatever name you wish)
into one of the following directories:
    /root/my-applications/bin
    /usr/bin
    /usr/local/bin

Make sure it is executable.

I have my ISO images saved in a setup similar to this:

/mnt/sda12/ISOs/
/mnt/sda12/ISOs/Fatdog
/mnt/sda12/ISOs/Legacy
/mnt/sda12/ISOs/LHP
/mnt/sda12/ISOs/Lupu
/mnt/sda12/ISOs/Precise
/mnt/sda12/ISOs/Racy
/mnt/sda12/ISOs/Slacko
/mnt/sda12/ISOs/Wary


So i open a console/terminal in /mnt/sda12/ISOs/
and then run the script from there.
(Simply type the name you gave your script.)

When the script has finished running it will return to the prompt,
and you will find the output in this file: /tmp/iso-sizes_iso-names
which will have content similar to this:
Code:
142676   wheezy-3.5.2.2-SCSI.iso
130908   lupu-525.iso
129780   lupu-520.iso
141444   wary-5.3.92.iso
126036   wary-511-k2.6.32.28.iso
161656   wary-511-k2.6.32.28_MediaPlayers.iso


If you would rather have the full PATHS to the ISO's included,
then have a look at this file: /tmp/sizes-fullpaths
which will have content similar to this:
Code:
142676   /mnt/sda12/ISOs/DpupWheezy3522/wheezy-3.5.2.2-SCSI.iso
130908   /mnt/sda12/ISOs/lupu-525.iso
129780   /mnt/sda12/ISOs/lupu-520.iso
141444   /mnt/sda12/ISOs/Wary/5.4beta2/wary-5.3.92.iso
126036   /mnt/sda12/ISOs/Wary/wary-511-k2.6.32.28.iso
161656   /mnt/sda12/ISOs/Wary/wary-511-k2.6.32.28_MediaPlayers.iso


    NOTE:
    The first time you run the script it will complain about not being able to remove the temp files,
    do not worry about it as they do not yet exist. Wink

    If you want to keep any of the files created,
    copy/move them somewhere else before re-running the script.


Hope this helps
CatDude
.

_________________

Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Mon 29 Apr 2013, 19:29    Post subject:  

Actually, was a typo, is s and not a, as i replied quickly...
I'd just do this (cd wherever you need firstly):
Code:
find . -iname '*.iso' -exec du -sh {} +

Example:
Code:
find . -iname '*.iso' -exec du -sh {} + | sort -h
12M     ./lil/TinyCore-current.iso
34M     ./lil/pUPnGO_V412_060113.iso
46M     ./lil/beini-1.2.3.iso
94M     ./0linux-mini-04112012-x86_64.iso

_________________

Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11117
Location: Arizona USA

PostPosted: Mon 29 Apr 2013, 22:38    Post subject:  

No doubt I'm showing off my ignorance to mention this, but if you open a directory in ROX and change to the "Show extra details" view, the size of all the files in that directory is shown.
Back to top
View user's profile Send private message 
Semme

Joined: 07 Aug 2011
Posts: 3965
Location: World_Hub

PostPosted: Mon 29 Apr 2013, 23:01    Post subject:  

Flash- you're a Very Happy Guinness!

Then again..
Quote:
.. generating a script to output ISO name and file size for all ISOs in a directory but also explain how and why it works.
Back to top
View user's profile Send private message 
ally


Joined: 19 May 2012
Posts: 851
Location: lincoln

PostPosted: Tue 30 Apr 2013, 05:52    Post subject:  

hey all

thanks for the input

@flash - I wanted to get away from doing things manually, I've 1600+ puppies now and it takes ages! also wanted a practical script example to try and play with

unfortunately I suffer with mental health issues amongst other things and information and learning is becoming much harder for me than it used to. although I have tried script tutorials I've struggled and thought a useful practical example would help spur me on

thanks again everybody for the input

Smile
Back to top
View user's profile Send private message Visit poster's website 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Wed 01 May 2013, 12:56    Post subject:  

As script:
Code:
#!/bin/bash
######################################################################
# List all ISO under dir showing sizes in human readable format.
######################################################################
[ $1 ] && DIR_SEARCH="$1"

cd $DIR_SEARCH &&
echo -------------------------------------------------------------- &&
find . -iname '*.iso' -exec du -sh {} + | sort -h
echo -------------------------------------------------------------- &&
exit 0


The script looks for an argument to be used as path of the main search with find
and changes directory to it.

"find" will search in that directory and subdirs for files whose names ends with '.iso':
the * is called "wildcard" and means "something", so it will search for "something.iso".
Is 'iname' and not 'name' because we don't mind much if is on caps or not, we want
case insensitive search (so can match files called SOMETHING.ISO" too).

For each result, find will create a command for launch, which is 'du -sh filename.iso' and will exec it.

All the output above is piped and goes to "sort"; this is only for readibility and is not essential.
The idea is sort all the iso files by size in the final list, from minor to major so can have
a criteria for read and seek in the list later.

Make it a file and run it piped to a new txt if you want to keep the list of isos.
I did it and called "ISOs.sh" and changed permissions like this:
Code:
chmod +x ISOs.sh

then did the test:
Code:
./ISOs.sh /mnt/data/aqemu/ > ISO_list.txt

and the -cropped- results:
Code:
--------------------------------------------------------------
12M     ./TinyCore-current.iso
34M     ./pUPnGO_V412_060113.iso
46M     ./beini-1.2.3.iso
94M     ./0linux-mini-04112012-x86_64.iso
106M    ./4MLinux-4.1-allinone-edition.iso
106M    ./PuppyArcade_9.iso
112M    ./qrky-120.iso
116M    ./slacko-5.3.3-4g-SCSI.iso
120M    ./Feather-0.7.5.iso
...
2,2G    ./TEXLIVE2012/ISO_TEXLIVE_2012/texlive2012-20120701.iso
--------------------------------------------------------------


The script itself is very silly (after all is just some "find" procedure),
but though that I should explain what I wrote there as you required it since main post.

Hope it helps.

_________________

Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 3336
Location: Ontario

PostPosted: Wed 01 May 2013, 15:40    Post subject:  

For reference , there is another command to find file size

For instance to find the file size of the application evince

Code:
stat -c %s /usr/bin/evince


________________________________________
Back to top
View user's profile Send private message 
ally


Joined: 19 May 2012
Posts: 851
Location: lincoln

PostPosted: Thu 02 May 2013, 10:50    Post subject:  

thanks again for all the inputs

much appreciated

Laughing Smile
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [19 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Beginners Help ( Start Here)
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1028s ][ Queries: 11 (0.0062s) ][ GZIP on ]