PDA

View Full Version : Most bizzare 1 line script you have written.



santosh_gr
December 27th, 2007, 01:41 AM
e.g.

cat /etc/samba/smb.conf | egrep -v "^$|^\#|^\;"

This will print out only the configuration of /etc/samba/smb.conf without any blank lines, comments begining with either # or ;

explanation

-v - is for exclude.

"^$|^\#|^\;" stands for ^$ OR ^\# OR ^\;

i.e.
^$ stands for begining of line char ^ and end of line char $. Removes blank spaces.
^\# stands for beginging of line char ^ with \# escape char with # symbol. Removes comments beginging with # sysbol.
^\# stands for beginging of line char ^ with \; escape char with ; symbol. Removes comments begining with ; symbol.

Hope this helps. You can use this with other scripts as well just to read only the config files.

-grubby
December 27th, 2007, 03:37 AM
echo "hello world"?

osx424242
December 27th, 2007, 04:42 AM
I almost asked someone to

for f in `ls -1 /somedir/`; do echo "-- $f --"; cat /somedir/$f; done > ~/out.txt
then send me the output file. Instead of, you know, just tarring up everything in the directory :). I got as far as testing it and writing up instructions before figuring that out.

olejorgen
January 15th, 2008, 03:25 PM
function append() {
lastarg="${!#}"
echo "${@:1:$(($#-1))}" >> "$lastarg"
}

Took me a while to figure out that bash syntax ^^

Namtabmai
January 15th, 2008, 03:31 PM
e.g.

cat /etc/samba/smb.conf | egrep -v "^$|^\#|^\;"


If theres one thing I've learnt from my time using Linux, it's no matter what command you create, someone will always come up with a shorter way of doing the same thing.

testparm -s

(But of course that only work on Samba, not other programs).

red_Marvin
January 15th, 2008, 06:04 PM
gksudo '# Make etqw run faster' && /usr/local/games/etqw/etqw & sleep 10 && pidof etqw.x86 | xargs sudo renice -15 -p

This is a way to run etqw with a nice value of -15 without running it as root. I ended up not using it though since I couldn't notice any performance gain.

beercz
January 15th, 2008, 06:14 PM
To get my IP address (from my wireless network card):


ifconfig eth1 | grep "inet addr" | cut -d":" -f2 | cut -d" " -f1

Praadur
January 15th, 2008, 06:19 PM
I use this line for my /usr/sbin/debsbydate script, it's not the most imaginative thing I've done and it could certainly be handled in a more graceful way... but I never bothered tinkering with it as this works and I like it.


ls -lrt /var/lib/dpkg/info/*.list | sed -e 's/.*[/].*[/]//' | sed -e 's/.list//'

Basically, this lists the names of packages I've installed, throughout the history of this Ubuntu installation, sorted by date so it shows the most recent last. This is incredibly useful to me at times, especially if I've installed something, decided I didn't want it, and then apt-get didn't automatically remove every dependency said item installed that's no longer required.