Free Republic
Browse · Search
General/Chat
Topics · Post Article

Skip to comments.

The Complete Beginner's Guide to Linux
Linux.com ^ | 13 August 2014 | Jack Wallen

Posted on 08/15/2014 4:37:21 AM PDT by ShadowAce

click here to read article


Navigation: use the links below to view more comments.
first previous 1-2021-23 last
To: martin_fierro
Nice sed!

Here's a fun trick for linuxers....

#!/usr/bin/bash

if [ "$1" == "" -o "$2" == "" ]
    then
      echo "Syntax:"
      echo "$0 extension path"
    exit
fi

ls -lR $2 | grep \\.$1 | awk '{ total += $5 } END { print total }'

What does it do? It accepts one arguments. The first  argument is a file extension. The second is a directory name. If you want it to start from the directory you are in, use ".".

This script will start in the directory specified and will find all files with that extension, add up all the file sizes, then print a total for that file type.

$ columnsum mp3 /home/av/music/bluegrass/
1500935414
$ columnsum mp3 .
488423164

 

21 posted on 08/15/2014 10:36:28 AM PDT by zeugma (Islam: The Antidote for civilization)
[ Post Reply | Private Reply | To 12 | View Replies]

To: zeugma
Pretty cool. Are you a fan of CommandlineFu?
22 posted on 08/15/2014 10:39:22 AM PDT by ShadowAce (Linux -- The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 21 | View Replies]

To: ShadowAce
Pretty cool. Are you a fan of CommandlineFu?

Yeah, it's been a while since I've been to that site, but I recall it having some really cool one liners.

I actually used that very simple script to teach some of the basics of life in the shell to a nephew. It was originally exactly 1 line that was hardcoded to look for and total up mp3 files. We first made it look for any type of file extension, which is actually trickier than you'd think because you have to escape the "." or you'll get false positives. Then we made it take a path for input. Lastly, put some checking to make sure you had two arguments. Was kinda cool. Very simple, but he was easily able to understand it. The idea I was trying to show was how to take something that did one thing and make it more general.

23 posted on 08/15/2014 4:37:02 PM PDT by zeugma (Islam: The Antidote for civilization)
[ Post Reply | Private Reply | To 22 | View Replies]


Navigation: use the links below to view more comments.
first previous 1-2021-23 last

Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.

Free Republic
Browse · Search
General/Chat
Topics · Post Article

FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson