Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
user:yeti:opkg-list-user-installed-packages [2018/01/16 08:41] – [2018-01-16] shorter 'du' vs 'du -s' example yetiuser:yeti:opkg-list-user-installed-packages [2018/02/03 01:06] – [2018-01-16] yeti
Line 63: Line 63:
 :?: Why ''du -s''? :?: Why ''du -s''?
  
-:!: Have a look:+:!: Have a look: //(the example was run on Debian)//
 <code> <code>
-$ du logs | awk '{ print ; s+=$0 } END { print s"\t---TOTAL---"}'+$ du logs
 8       logs/refs/heads 8       logs/refs/heads
 8       logs/refs/remotes/origin 8       logs/refs/remotes/origin
Line 71: Line 71:
 24      logs/refs 24      logs/refs
 32      logs 32      logs
-84      ---TOTAL--- 
 </code> </code>
-The directories have are entered and all their files are shown in ''du'''s output and then the directory appears again with a sum of all contents plus its own size. Letting ''du -s'' only show the recursive sum for directories fixes this:+The script only needs the summary of directories:
 <code> <code>
-$ du -s logs | awk '{ print ; s+=$0 } END { print s"\t---TOTAL---"}'+$ du -s logs
 32      logs 32      logs
-32      ---TOTAL--- 
 </code> </code>
 +If called with files and directories, files are shown like without ''-s'' and directories are totalled: 
 +<code> 
 +$ ls -ld description logs 
 +-rw-r--r-- 1 yeti yeti   73 Mai 15  2017 description 
 +drwxr-xr-x 3 yeti yeti 4096 Mai 15  2017 logs 
 +$ du -s description logs 
 +4       description 
 +32      logs 
 +</code> 
 +As long as this script shall show no intermediate results, letting ''du'' sum the directories' sizes fits.
  • Last modified: 2019/09/07 19:18
  • by yeti