Showing posts with label useful shell bits. Show all posts
Showing posts with label useful shell bits. Show all posts

Wednesday, 16 January 2008

Wget saves mouse clicks...

Today I was visiting a journal web page that listed supplements to an article they published. There were umpteen items to click away at (why don't they have a "download all" button that gives me a gzipped archive??) and I hate that sort of dumb clicking.

I remembered wget can automate this. A quick man wget provided just the right example to do what I wanted:

wget -r -l1 --no-parent -A.mov http://www.thejournal.com/thepage

...where this particular example helps me to download the page and the links on that page (-r), but only one link deep (-l1) and not going up in the web site directory tree (--no-parent), and, finally, to only get items that are .mov-files (-A or --accept).

Yes, the next thing I found out was that I didn't have a codec for those Quicktime supplements, but that's another story...

Friday, 23 March 2007

Quick overview of system hardware

I was just looking to install more memory (I've come to the point where there's only at most one reason a month to start up the original WinXP install on my laptop, and now I want to play with running it inside qemu), and I wanted to know if there's a free memory bank in the laptop. The lshw program tells you such things - and lots of other stuff. Here's the part I needed:

*-memory
description: System Memory
physical id: a
slot: System board or motherboard
size: 512MB
capacity: 2GB
*-bank:0
description: SODIMM DDR Synchronous [empty]
physical id: 0
slot: DIMM #1
*-bank:1
description: SODIMM DDR Synchronous 333 MHz (3.0 ns)
product: NT512D64SH8B0GM-6K
vendor: 7F7F7F0B00000000
physical id: 1
serial: 41663624
slot: DIMM #2
size: 512MB
width: 64 bits
clock: 333MHz (3.003ns)

What else could I wish for? It even gives me enough details of the installed memory to find compatible parts by just web-searching with the product-string. Nice.

Friday, 9 March 2007

Defining shorthand commands in the shell

For all bash users (if, like me, you didn't know this one, you'll be very happy with it): look up the alias feature, described in 'man builtins'.

...always something new to learn when you just pick a random page from 'The Debian Bible' before going to sleep...

Monday, 26 February 2007

Chmod and symbolic links

Seeing in the output of an ls -l command that my symlinks were world writable, I worried for a while and tried to change the permissions on them using chmod. That was a useless exercise, as is in fact pointed out in man chmod... permission to set symlinks is I guess governed by the directory's permissions.

Sunday, 25 February 2007

Setting environment variables through bash scripts

Let's say you don't want to have certain variables set every time (through .bashrc). Setting them up by running a script doesn't exactly do what you want: it sets up your variables in the environment in the script, and then exits that environment on exiting the script.

Bash features a built-in command "source scriptname.sh" to do the thing: it executes the commands in the script in the current environment. Here's an example (this is what I wanted to do today, setting extra library and header search paths for gcc):

#my scriptfile
LD_LIBRARY_PATH=/my/nonstandard/dir/local/lib

export LD_LIBRARY_PATH
CPLUS_INCLUDE_PATH=/my/nonstandard/dir/local/include
export CPLUS_INCLUDE_PATH
LIBRARY_PATH=/my/nonstandard/dir/local/lib
export LIBRARY_PATH
cd /take/me/to/the/basedir/of/my/code/project

which, as a bonus, brings me straight to the right working directory to get on the job...
I found this solution starting here from a google search. The gcc variables are described in the book "An introduction to GCC" by Brian Gough, which is in fact also available online.