Archive for the 'Shell' Category

Fixing directory permissions with find

Wednesday, September 28th, 2005

Screwing directories and files with setgid bit: chmod -R 2775 photos

Fixing file permissions with find: find . -type f -exec chmod 664 {} ‘;’

Printing a single quote in a shell script

Wednesday, August 17th, 2005

Diego’s “shell nasty quoting tricks”: print ” ‘ ” ‘ ” ‘ ” ‘

or in more details: perl -e ‘print ” a’ ” ‘ ” ‘b ” ‘

Backticks deprecated

Wednesday, August 17th, 2005

Yes they are – “ are better replaced with $(). The problem is that not all the shells know about it ;-)

Capturing local traffic for further analysis (long term)

Monday, August 15th, 2005

Add this line to cron.daily/cron.hourly/…

tcpdump -np -i eth0 -s 0 -w /<path>/date +"%Y%m%d-%H%M%S.tcpdump" “<filter>”

Shell (almost) regexp variable substitution

Tuesday, July 12th, 2005

${variable#pattern}

If the pattern matches the beginning of the variable’s value, delete the shortest part that matches and return the rest. ${variable##pattern}

If the pattern matches the beginning of the variable’s value, delete the longest part that matches and return the rest. ${variable%pattern}

If the pattern matches the end of the variable’s value, delete the shortest part that matches and return the rest. ${variable%%pattern}

If the pattern matches the end of the variable’s value, delete the longest part that matches and return the rest.

Perl one-liner: Adding all new files to SVN

Wednesday, June 22nd, 2005

svn add svn status | perl -ne '/\?\s*(.*)/ && print "$1 "'

Changing permissions hack

Wednesday, October 13th, 2004

chmod -R go=u,go-w /directory

Copying user’s permissions to group and others, clearing write permission (all this to merely preserve x for directories without setting it to all other files).

PPP over SSH

Friday, October 8th, 2004

WHY?????? WHY NOT? ;-) Run this on client:

pppd noauth debug nodetach  10.0.0.1:10.0.0.2 pty 'ssh user@server "pppd noauth debug nodetach notty "'

It works, even if the server asks for password, as it uses a direct terminal I/O, not stdin. Note that for noauth option pppd needs to be run as root (otherwise, some authentication options have to be set).

BTW Chris found this link. I think our one-liner is much nicer ;-)