Unixscripts:General
backup-copy
backup-copy - my backup script - using this, I can keep a backup at a cost of only about 2Mb/day. Uses the hard-linking power of rsync(1)
Usage: backup-copy [OPTION...] [--] [repository] Backup interesting files as set in the config file. Simple usage: backup-copy # does a backup - put this in cron!! backup-copy -l # shows what backups are available backup-copy --delta :now -v # shows what's changed since last backup backup-copy -f /etc/passwd # show distinct versions of that file Details. Backups will go to: <repository>/backup-copy/$HOST/YYYY/MM/DD-hh_mm with <repository> in the form of either 'hostname:directory' or 'directory' (default is /var). 'directory' must already have a subdirectory 'backup-copy/$HOST' otherwise the --init option can be given to create it. If using a remote system as <repository>, you need to have the ssh key pushed to the remote for login without password. Environment parameters can be set in the config file as follows: MUST_BE_ROOT="yes" # to restrict to root (or "" or unset) DEFAULT_DESTINATION= # repository to use (overridden by a repository on the command line) TEST_FILE= # invariant inoded file to test consistency EXCLUDES= # list of rsync patterns to exclude INCLUDES= # list of rsync patterns to include EXPIRE= # remove backups older than this number of days KEEP_MONTHLY= # only keep one backup per month of anything older than this Options: -b, --brief On all diff operations, report only whether the files differ, not the details of the differences. -c, --config=config-file override the config file (the default is the first in the list: /home/bhepple/.config/backup-copy.achar /home/bhepple/.backup-copy.achar /home/bhepple/.config/backup-copy /home/bhepple/.backup-copy /etc/backup-copy) Default is '/etc/backup-copy'. -C, --check-links=dates don't backup - just check the backup tree ensuring that hard links are correct (this can be slow, particularly on a remote repository). The argument 'dates' is in the format '[first|last|prev|YYYY/MM/DD-HH_MM[,last|prev|YYYY/MM/DD-HH_MM]'. The dates may be wildcarded (with * and ?) but if two dates are specified, the first may not be wildcarded. The dates 'first', 'last' and 'prev' are expanded to the first, last and previous backup dates respectively. If only one date is given, then all files in the backup repository are compared to the files under that date directory. If two args are given then the comparison is between the first date directory and the second one(s) - but intermediate dates are not interpolated. eg to check the latest backup against the previous one, use 'prev,last'. Note that when duplicates are found then the new link is created using the first date directory as the base. --debug even more verbosity --delta=dates don't backup - just diff two backups. The dates are given as '[date1][,date2]' with a date in the format 'first|last|prev|now|YYYY/MM/DD-HH_MM' eg '2011/01/18-21_13,2011/01/26-21_13'. A blank date means the last (latest) backup. The dates 'first', 'last' and 'prev' are expanded to the first, last and previous backup dates respectively. A date of 'now' compares against the live system (this can be quite slow on a remote backup as the files must be downloaded before the diff is done. Fast on a local backup.) Thus to compare the live system with the latest backup use ',now'. You can get the list of available backups with the --list option. The number of files that differ is returned in the exit code. -D, --diff do a diff after the backup -f, --file-vers=file don't backup - just list the distinct versions of 'file' available in the repository with their sizes. Note that this isn't terribly useful if run on a directory or symbolic link. -H, --host=host override the host name. Default is 'achar'. -i, --init initialise repository if necessary -l, --list don't backup - just list the backups in the repository -n, --dryrun dry run - just print what would be done --progress show progress -q, --quiet be quiet -w, --warn warn about suspicious filenames -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
ff
ff - recursively find files (wrapper for find(1))
Usage: ff [OPTION...] [--] [pattern] Presently this is just a shorthand for: find . -follow -type f -name '*pattern*' -print 2>/dev/null |sort Options: -C, --cd=directory search from this directory rather than cwd. -d, --dir search for a directory rather than a file. Default is 'f'. -v, --verbose be verbose -x, --exclude=directory exclude directory. -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
fs
fs - recursively search for patterns in files (wrapper for find(1) and grep(1))
Usage: fs [OPTION...] [--] pattern [directory [...]] Uses find(1) and grep(1) to recursively search files for regular expressions. Ignores .svn .git nbproject .libs .deps CVS* directories and *~ TAGS #*# and cscope* files. Always applies -I (ignore binary files) and --colour. 'fs -n' is suitable as emacs' grep function. Options: -c, --c-files only looks at *.[ch] *.cpp *.cxx files -C, --context=lines print 'context' lines of context. Must be of type 'i'. Must be in the range '1:100'. --exclude-dir=directory exclude directory --extension=ext extensions to search eg .el -E, --extended-regexp use extended regular expression (as grep) -F, --fixed-strings use fixed strings (as grep) -H, --h-files only looks at *.h files -i, --ignore-case ignore case (as grep) -j, --java-files only looks at *.java files -l, --files-with-matches filename only (as grep) -L, --files-without-matches filename only: without match (as grep) -m, --m4-files only looks at *.m4 files -M, --make-files only looks at *akefile* *.mk files -n, --line-number prefix each hit with the line number (as grep) -p, --python-files only looks at *.py files -r, --ruby-files only looks at *.rb files -s, --spec-files only looks at *.spec files --shell-files only looks at *.sh files -v, --verbose be verbose -x, --xml-files only looks at *.xml files -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
fit
fit - fits a bunch of files/directories into CD or DVD sized subdirectories ready for burning
Usage: fit [OPTION...] [--] Options: -c, --cd fit to 700Mb CD (default). -d, --dvd fit to 4.3Gb DVD. -m, --mb=limit fit to 'limit' Mb. Must be of type 'i'. -n, --confirm no dry run - just do it! -p, --prefix=prefix use prefix for dir names. Default is 'fit_'. -s, --smallest-first fir smallest first -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
m
m - pretty display of man pages (needs 'v' and a postscript or pdf viewer) eg m less
to get a pretty man page for less(1)
Usage: m [OPTION...] [--] [ section ] name A wrapper for 'man'. Depends on the script 'v' available from the same place. Displays a pretty man page if X is available (otherwise just does 'man'). 'section' narrows the search for a man page to that section. 'name' is the name of the manual page. On Solaris, adds the '-s' option for section name. eg. Do 'm man' for more information about 'man' Options: -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit
mass-mv
mass-mv - renames and or moves files according to a regex; can also clean up filenames removing whitespace and/or weird characters
Usage: mass-mv [OPTION...] [--] [ filename(s) ] Renames files en masse. Options: -a, --convert-all replace all runs of non-'[:alnum:].-' with '_' -c, --chop=string chop out a string (not a regex) -l, --lower lower case filenames -n, --dry-run just print what it would do -R, --recursive descend subdirectories -s, --sed=string pass old filename through a sed command (eg 's/asdasd/dfgdfg/') -S, --spaces remove spaces -u, --upper upper case filenames -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
myscreendump
myscreendump - Take a screendump with a choice of Window, screen, rectangle, root. Require, netpbm & ImageMagick.
Usage: myscreendump [OPTION...] [--] Take a screendump with a choice of Window, screen, rectangle, root Options: -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit
newest
newest - recursively list files in directories in date order. If called as oldest, reverse the sort direction. If called as biggest or smallest list by file size.
Usage: newest [OPTION...] [--] [directory ...] Find the newest file in the directory(s) (or PWD). Options: -l, --long print more info about each file -r, --reverse find the oldest rather than the newest -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit
r
r - run a command with sudo or popup a root xterm
Usage: r [OPTION...] [--] [command] Run 'command' as root via the 'root' program if available else sudo. If command is not given then start up a root shell. You might want to customise the XTERM setting in this script if you want something different from "myterm --" Note that you need to take care of the /etc/sudoers file by adding the NOPASSWD:: flag to your line. Ideally be a member of wheel group and: %wheel ALL=(ALL) NOPASSWD: ALL Options: -v, --verbose be verbose -X, --use-x prefer X instead of console -h, --help print this help message -V, --version print version and exit
refactor
refactor - uses find(1) and sed(1) to search and replace
Usage: refactor [OPTION...] [--] pattern [ subst ] Do pattern and substitution on all files in sub-directories. If 'subst' is not given then a 'camel case to underscore' replacement will be done eg CamelCase -> camel_case. Does not touch .svn, 'cscope*', 'TAGS' or '*~' files. It's often a good idea to use -n,--dryrun and copy, paste and modify the command before running it manually. Options: -c, --allc-files only looks at *.[ch], *.cxx, *.hpp & *.cpp files -C, --c-files only looks at *.c, *.cxx & *.cpp files --exclude=directory exclude 'directory' --extension=ext extensions to search ie *.$ext -H, --h-files only looks at *.h files -j, --java-files only looks at *.java files -m, --m4-files only looks at *.m4 files -M, --make-files only looks at *akefile* Minfo*.cfg files -n, --dryrun dryrun -p, --python-files only looks at *.py files -P, --partial match on any occurance of 'pattern' ie don't add \\<..\\> -s, --spec-files only looks at *.spec files --shell-files only looks at *.sh files -v, --verbose be verbose -h, --help print this help message -V, --version print version and exit
v
v - view or execute any type of file going rather beyond the scope of lessopen - in the simple case of a text file this is just shorthand for less(1)
Usage: v [OPTION...] [--] file(s) View a file using an application appropriate to its type depending on whether you're running from a console or under X. Prefer console apps over X. Does not rely on lesspipe.sh Passes all files to the viewer if it makes sense to do so. Also, only the first file is inspected to decide how to view/edit/exec. Options: -a, --all view all media files under PWD (recursively) -e, --edit edit or exec instead of view (default if run as 'x') -n, --dryrun just print what would be done -v, --verbose be verbose -x, --use-x prefer X instead of console -h, --help print this help message -V, --version print version and exit
vnc
vnc - run vncserver or x11vnc remotely and vncviewer locally over ssh(1) (assumes you have passwordless ssh(1) access).
Usage: vnc [OPTION...] [--] [user@]hostname[:display#|::port] Connects to the first existing vncserver or x11vnc on the remote if any. If none, runs vncserver on the remote and vncviewer on the local, using the geometry and dpi of the local to make fonts look right. Options: -d, --dont-keep don't keep the remote session going. -D, --desktop create a remote desktop link to the :0 desktop with x11vnc -g, --geometry=WxH geometry WxH (or 'full' to use the same as the current screen). Default is 'full'. -k, --keep keep the remote session going so that it's ready for future use. Default is 'ask'. --kill=display kill remote display -l, --list list vncports on remote -n, --dname=desktop-name desktop name to pass in VNCDESKTOP to ~/.vnc/xstartup eg :0 -N, --new don't look for an existing vnc session on the remote - create a new one. -p, --sshport=port port to use for ssh -v, --verbose be verbose --via use --via $HOST localhost:$VNCPORT -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
xcheck
xcheck - runs a command (usually under X) and, if there's an error, shows stdout and stderr in a popup window eg xcheck – remote-x11vnc -x xdm
.
Requires zenity.
Usage: xcheck [OPTION...] [--] <x-command> Run a X command capturing stdout and stderr. If it gives an error, popup a viewer with the messages. If it survives for 5 seconds, exit this script and delete any temporary files. Also removes any crufty xwin-utils backup file /home/bhepple/.local/share/xwin/$WINDOW_ID. Options: -f, --force always display output -v, --verbose be verbose -w, --watch=time time to watch the app. 0==forever. Default is '5'. Must be of type 'i'. Must be in the range '0:1000'. -h, --help print this help message -V, --version print version and exit Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.