|

Bash – Variable indirection – Using variable contents as a(nother) variable name

This was a tricky action. Assume I have a list of variables, obtained by an external source: var1=a var2=b var3=c I cannot use loop and in it the phrase ${var$i} (where i is the integer counter). It just doesn’t work. I used this instead to assign the values to an array: var[$i]=$(eval echo "${var${i}}") That…

I never quite remember it – extracting a specific file from tar archive

I always forget, and this blog is meant to help me remember. Found in Tar’s manual, are these simple directives: Have a file called file.tar, do: tar -xf file.tar full/path/without/trailing/slashes It can be a file or directory. You can have a list of files, such: tar -xf file.tar home/me home/you home/us/important-file Should do the trick.

|

Quick and dirty delete old files, with exclude list and support for filenames with spaces

Here’s a little script I’ve written which deletes older than AGE days files, and has an exclude list, just in case. It’s meant to be run by cron on a daily basis: #!/bin/sh # Source of all evil DIR=/ftp # Age of file in days AGE=10 # Exclude list – Use pipe (|) seperated values….