User Tools

Site Tools


unix:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
unix:bash [2010/02/22 08:29]
ben created
unix:bash [2011/03/15 16:56] (current)
ben
Line 1: Line 1:
-===== Add file sizes together from a list returned via Find  ​===== +====== ​Bash Notes ======
-<​code>​ +
-IFS=$'​\n';​set j=0;for i in $(du -s $(find ./ -name \*.MOV)|cut -f 1);do j=$(( $i + j ));echo $j;​done;​IFS=$'​ \t\n'​ +
-</​code>​+
  
-This seems to keep growing after multiple runs, so something is odd.+<​tab>​**[[unix:​bash:​simple_arithmetic|Some simple math with file sizes]]**
  
-Better: +<tab>**[[unix:​bash:​rss|an attempt at an rss reader for a specific purpose]]**
-<code> +
-IFS=$'​\n';​set j=0;for i in $(du -s $(find ./ -name \*.MOV)|cut -f 1);do j=$(( $i + j ));echo $j;​done;​unset i;unset j;​IFS=$'​ \t\n'​ +
-</​code>​+
  
-Need to divide number by 2 on a Mac for human readable size in Megabytes: 
-<​code>​ 
-IFS=$'​\n';​set j=0;for i in $(du -s $(find ./ -name \*.MOV)|cut -f 1);do j=$(( $i + j ));echo $(( j / 2 ));​done;​unset i;unset j;​IFS=$'​ \t\n' 
-</​code>​ 
-Better: 
-<​code>​ 
-IFS=$'​\n';​set j=0;for i in $(du -s $(find ./ -name \*.MOV)|cut -f 1);do echo $i;j=$(( $i + j ));echo $j;​done;​echo $(( $j / 2));unset i;unset j;​IFS=$'​ \t\n' 
-</​code>​ 
- 
-Now need to change so the file names are one var, the size is another var, so the output can be nice and neat: 
-<​code>​ 
-IFS=$'​\n';​set j=0;for f in $(find ./ -name \*.MOV);do i=$(du -s $f|cut -f 1);​k=$j;​j=$(( $i + j ));echo $f is $(( $i / 2)) Mbytes;echo Added to $(( $k / 2 )) Mbytes equals $(( $j / 2 ));​done;​unset f;unset i;unset j;unset k;​IFS=$'​ \t\n' 
-</​code>​ 
- 
-This seems to be the working but quite verbose code (important to note "k / 2" instead of "$k / 2", apparently caused by the set of k=$j, creates a pointer or something?​):​ 
-<​code>​ 
-IFS=$'​\n';​set j=0;set k=0;set i=0;set f=;for f in $(find ./ -name \*.MOV);do i=$(du -s $f|cut -f 1);​k=$j;​j=$(( $i + j ));echo $f is $(( $i / 2)) Mbytes;echo Added to $(( k / 2 )) Mbytes equals $(( $j / 2 )) Mbytes;​done;​echo The total size is $(( $j /2 )) Mbytes;​unset f;unset i;unset j;unset k;​IFS=$'​ \t\n' 
-</​code>​ 
- 
-Now, can we get it sorted? 
unix/bash.1266845356.txt.gz · Last modified: 2010/02/22 08:29 by ben