7 Useful Linux Tricks

scrottie on 2008-10-11T06:09:10

while true;do ssh -N -R *:2222:localhost:22 -l scott slowass.net;sleep 10;done



... I'll leave that running on firewalled machines so I can get back in (ssh -l scott -p 2222 slowass.net) from outside the firewall. Sometimes I'll leave my main laptop at home and take the little P1120 (that runs for 8 hours on a charge!) and kind of work remotely. slowass.net in this example is a non-firewalled host with your public key in its ssh/authorized_keys.



x11vnc -reflect 'listen:5551' -dontdisconnect -forever -passwd 'whatever' # on the remote, non-firewalled host

x11vnc -connect slowass.net:5551 -dontdisconnect -forever # on the firewalled host

... similarly for X/VNC. The first command runs a VNC proxy on a non-firewalled host and the second pushes a VNC connection to that proxy.

for i in *.jpg;do djpeg -pnm < "$i" | pnmscale -pixels 500000 | cjpeg > "small_$i.jpg";done

El cheap thumbnails using the NetPBM utilities.

tar -czv --one-file-system -f - / /usr | ssh user@backuphost 'cat >/home/baks/whatever.tgz'

... tar-gz your data and write the tarball on another host over ssh while it works so you don't fill your harddrive up. If you have a lot of partitions you want to back up, it might be easier to do --exclude rather than --one-file-system, and exclude /proc, /mnt/whatever, etc.

cat /dev/rwd0d | gzip --force --stdout | ssh user@backuphost 'cat >/home/backs/whatever.wd0d.img'

... similar, but back up the raw partition data. That's NetBSD style partitions. You'd probably want /dev/hda1 etc. And if you have to restore from this backup, you'll find it'll need a filesystem check afterwards. If you modified the filesystem much, you may well find that it completely fails to complete a filesystem check.

/bin/busybox sh

Keep a busybox binary handy in case you hose shared libraries. In the old days, /bin and /sbin were built static so that they'd always work, even if shared libraries got hosed. Not so these days. busybox is statically linked and it has a built-in sh and numerous built-in commands. That should hopefully be enough to fix whatever went wrong. If you have a Firefox running when you screw the dynamic linker, you can use it to fetch busybox and then run it from an xterm you have open.

du -k / | sort -r -n -k 1 | more

... find out what's using up all of the drive space.

-scott