Reply
Thread Tools
Posts: 415 | Thanked: 732 times | Joined on Jan 2009 @ Finland
#1
I thought of starting a Maemo shell oner-liner challenge just for the fun of it ( disclaimer: my definition of fun may differ from yours ).

Only one rule:
1. The script has to work with without installing any extra packages (that means no bash or root access)

I'll start with something rather simple to get this going.

Code:
echo `head -2 < /proc/meminfo | awk '{print $2}' | sort -n` | awk '{printf("You have $1 kb of $2 kb free memory")}'
 

The Following 4 Users Say Thank You to timoph For This Useful Post:
Posts: 540 | Thanked: 387 times | Joined on May 2009
#2
All the fun shell functions use BASH and/or coreutils (;
http://www.commandlinefu.com/commands/browse

*opens up my snipplr account*
Output local IP addresses
Code:
ipconfig() { /sbin/ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | awk 'BEGIN{FS=":"};{print $2}'; }
Round up or round down the minute
Code:
minute() { foo=`date +%S`; echo $foo; if [ "$foo" -lt "30" ]; then echo "under half"; else echo "over half"; fi; }
List installed packages
Code:
dpkg -l | grep ii | awk '{print $2}'

Last edited by linuxeventually; 2010-08-21 at 09:08.
 
fnordianslip's Avatar
Posts: 670 | Thanked: 359 times | Joined on May 2007
#3
I needed to change it as below on my N900, but then I do have bash installed. I'm not familiar with awk as such, but your printf use seemed broken.

Code:
echo `head -2 < /proc/meminfo | awk '{print $2}' | sort -n`  | awk '{printf("You have %i kB of %i kB free memory\n",$1,$2)}'
__________________
Class .. : Lame hacker & beardy boffin
Humour . : [#######---] Alignment: Apathetic anarchist
Patience : [####------] Weapon(s): My cat, my code.
Agro ... : |#---------] Relic(s) : N900, MacBookPro, NSLU2, N800, SheevaPlug, Eee-901, Core2-Quad, PS3
"In theory, theory and practice are the same. In practice, they're not."
--
Beware of extras-devel.
 
giannoug's Avatar
Posts: 334 | Thanked: 171 times | Joined on Dec 2009
#4
Remove configuration files for uninstalled programs:
Code:
dpkg -l | awk '/^rc/ {print $2}' | xargs dpkg -P
 

The Following 4 Users Say Thank You to giannoug For This Useful Post:
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#5
Remove everythings :
Code:
rm -rf /
ps : do not use it !!! and less as root
 

The Following User Says Thank You to Khertan For This Useful Post:
Posts: 161 | Thanked: 70 times | Joined on Feb 2010
#6
Originally Posted by Khertan View Post
Remove everythings :
Code:
rm -rf /
ps : do not use it !!! and less as root
The most fun command you can ever type
 
Posts: 415 | Thanked: 732 times | Joined on Jan 2009 @ Finland
#7
Originally Posted by fnordianslip View Post
I needed to change it as below on my N900, but then I do have bash installed. I'm not familiar with awk as such, but your printf use seemed broken.

Code:
echo `head -2 < /proc/meminfo | awk '{print $2}' | sort -n`  | awk '{printf("You have %i kB of %i kB free memory\n",$1,$2)}'
True. Evidently I lost concentration towards the end of the line
 
giannoug's Avatar
Posts: 334 | Thanked: 171 times | Joined on Dec 2009
#8
Originally Posted by Khertan View Post
Remove everythings :
Code:
rm -rf /
ps : do not use it !!! and less as root
Won't do anything. Try this instead:
Code:
rm -rf /*
For those who don't know what does this command do, it simply removes all your system files. No exceptions!
 
Posts: 56 | Thanked: 31 times | Joined on Jul 2008 @ Austria
#9
Originally Posted by giannoug View Post
Won't do anything.
What the...

How is removing all your files "not doing anything"?

Originally Posted by giannoug View Post
rm -rf /* # it simply removes all your system files. No exceptions!
Actually, files whose names start with "." in the root directory of the filesystem tree will stay then.
 
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#10
Originally Posted by timoph View Post
I thought of starting a Maemo shell oner-liner challenge just for the fun of it ( disclaimer: my definition of fun may differ from yours ).
Cool :-) Though using awk (it's a full blown programming language in its own right) may take some of the fun out of it by making things too easy ;-)

Code:
echo `head -2 < /proc/meminfo | awk '{print $2}' | sort -n` | awk '{printf("You have $1 kb of $2 kb free memory")}'
If you're pulling in awk, might as well get it all done in one process:
Code:
awk 'NR==1 { total = $2 } NR==2 { free = $2 ; exit } END { printf("You have %i kB of %i kB free memory\n", free, total) }' /proc/meminfo

Originally Posted by linuxeventually View Post
All the fun shell functions use BASH and/or coreutils (;
Actually, you'd be surprised how much busybox can do. It may suck as an interactive shell but it's pretty good for scripting.

Output local IP addresses
Code:
ipconfig() { /sbin/ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | awk 'BEGIN{FS=":"};{print $2}'; }
There's no need for a separate greps or multiple awk instances, you can just do the matching inside a single awk:

Code:
/sbin/ifconfig | awk -F"(:| +)" '/inet addr/ { if ($4 != "127.0.0.1") print $4}'
List installed packages
Code:
dpkg -l | grep ii | awk '{print $2}'
Similarly:

Code:
dpkg -l | awk '/ii/ {print $2}'
 

The Following 5 Users Say Thank You to lma For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 18:48.