parsed.org

Tips by tag: commands

Add a Newline to the End of a File by cygnus on Dec 31, 2005 04:09 PM

Use sed to add a newline to the end of a file (this will perform an in-place replacement and create a backup file, MYFILE.bak):

$ sed -i.bak '$G' MYFILE

Some programs, such as Emacs, will omit the trailing newline from a file unless configured to add one. Emacs can be configured to add a newline automatically.

backupcommandsconfigurationeditorsemacsin-placeline-endingsnewlinesedshell
Adding a Database and a User by xinu on Dec 18, 2005 01:43 PM

To create a Postgres user sam and a database samdb that is owned by the sam user:

$ su - postgres
$ createuser -P -A -D sam
$ createdb -O sam samdb

(Change the -A, and -D options to affect the new user's abilities.)

Edit the user's password with:

template1=# alter user username_here with password 'password_here';
accountcommandscreatedbcreateuserpermissionspostgresqluser
Adding Services by xinu on Apr 21, 2005 08:57 AM

To add a service to boot automatically on startup, do the following:

# chkconfig --level 345 <service_name> on
bootchkconfigcommandsconfigurationservicestartup
Adding Users with Passwords by xinu on Sep 10, 2005 12:13 AM

BSD is a little paranoid about where your passwords come from, so they'll insist on getting it from a stream. Here's an example:

(edit the file '/tmp/pass' and deposit the password there)            
% su root -c sh
Password:
# pw useradd -n test -c "Test User" -m -h 3 3< /tmp/pass
# grep test /etc/master.passwd
test:$1$T2tu0BET$UGPrNB1FavzjlzhTwUWRN.:1002:1002::0:0:Test User:/home/test:/bin/sh
# exit
% su test
Password: [typed "foobar" here...]
$ exit
bsdcommandsfreebsdneatparanoidpasswordspwsecurity
Add Line Numbers by xinu on Dec 31, 2005 04:07 PM

Add line numbers to your source code with expand and some quick perl:

expand /etc/motd | perl -pe 's/^/\t=$.=\t/'
commandsexpandlanguagesperlprogramming
Alternative to 'which' by cygnus on Jan 19, 2005 10:35 PM

Instead of running:

$ ls -lh `which zsh`

use this:

$ ls -l =zsh
commandswhichzsh
Auto-CD by cygnus on Jan 19, 2005 10:26 PM

To have zsh automatically cd to a directory without requiring you to type cd, set this option:

setopt auto_cd

So, if you have a directory foo in the current directory (and no command foo exists in your path), typing simply foo will be equivalent to cd foo.

auto_cdcommandszsh
Background Process by xinu on Dec 31, 2005 04:10 PM

If you need a process to survive your logging out of the system (or being knocked off of it), you can either screen it or wrap it with nohup. If you nohup, you'll lose control of it entirely, but the output will be written to nohup.out. With screen you can re-attach and take control later:

# nohup program -opts args &

-or-

# screen (press 'ctrl+a d' to detach after you've run the proc)
commandsloginlogoutnohupprocessscreenshell

Use these screenrc commands to bind specific key sequences to commands outside of the escape sequence (normally C-a). You can bind key combos to commands this way so you don't always have to prefix commands with your escape key sequence:

# Bind Control-PageDown to 'next', Control-PageUp to 'prev'
# to navigate between windows
bindkey ^[[5;5~ prev
bindkey ^[[6;5~ next

# Bind arrow keys Control-Down to 'next', Control-Up to 'prev'
# to navigate between windows
bindkey ^[[1;5A prev
bindkey ^[[1;5B next

(The keycodes for these keys can be obtained by running cat > /dev/null and pressing the desired key combination.)

bindingbindkeycommandsconfigurationescapekeystrokesscreenscreenrc
Bitchx Timestamps by cygnus on Jan 12, 2005 10:38 AM

%@ is the specifier for timestamps in output formatting:

/fset send_public %@%P<%n$2%P>%n $3-
/fset send_action %@%K* %W$1 %n$3-
bitchxcommandsconfigurationirctimestamps
Change Field Separator in Data by cygnus on Jan 12, 2005 10:27 AM

You can use awk to change the field separator in a data stream:

$ cat foo
a,b,c,d,e,f
a,b,c,d,e,f
$ awk 'BEGIN { FS = ","; OFS = ".."; } { $1 = $1; print }' foo
a..b..c..d..e..f
a..b..c..d..e..f

(You just have to touch one of the fields to get it to process the line.)

awkcommandsfieldsparsingshell
Changing Process Priority by xinu on Mar 10, 2005 01:52 PM

Ever been on a machine that was ailing and just wouldn't respond? As soon as you're root, lower the priority of the offending process ID(s) (in this example, 1103) by using the 'renice' command:

# renice -19 1103
commandsconfigurationcontroldebuggingmonitoringpriorityprocessrecoveryrenicerescuesecurityshell
Colorize python source in a terminal by cygnus on Jan 12, 2005 10:10 AM

Use the pycolor tool included with ipython. It will format the source using ASCII codes so it looks pretty in your terminal:

$ pycolor foo.py
asciicommandsipythonlanguagesprogrammingpycolorpythonterminal
Commands for dealing with branching by cygnus on Jan 12, 2005 12:33 PM

These commands are used to deal with tagging and branching in SVN:

$ cd /path/to/project && svn copy trunk branches/mybranch-N && svn commit -m 'Created new branch'
$ cd /path/to/project/branches/mybranch-N

Make changes and commit:

$ cd /path/to/project/trunk
$ svn merge -r R:head svn://path/to/repo/branches/mybranch-N

(In the merge command, 'R' is the revision in which the branch was created. Note that if the trunk is merged into the branch, then merging the branch back into the trunk again will cause conflicts if selective merging is not used. Use the svn merge -r start:stop syntax for selective merging.)

branchingcommandscommitmergesubversionsvntagging
Compiling Tips by xinu on Sep 10, 2005 12:12 AM

One of the most maddening things I've had to do is compile on Solaris without the warm/fuzzy GNU'ness. Remember these things:

1. add gcc
2. add bison
3. add /usr/ccs/bin & /usr/local/bin to path
commandsgnupackagessolaris
Context Diff by xinu on Apr 29, 2005 02:26 PM

If you want to have a context diff instead of the default that subversion offers, you can give it the binary and options to use on the commandline:

$ svn diff --diff-cmd /usr/bin/diff -x '-crN'
commandscontextdiffsubversionsvn
Convert DOS Files by xinu on Jan 20, 2005 10:55 AM

There are a few different ways to convert a DOS file to Unix format, but the most available is probably this:

$ col -bx < dosfile > unixfile
colcommandsconvertdosfilterline-endingsnewlineshellunix

You can use the convert program (included with imagemagick) to convert a LaTeX file to an image:

$ convert -density 144 -geometry 100% source.dvi dest.jpeg
commandsconvertdviimageimagemagicklatextextypesetting
Convert Man to HTML by xinu on Jan 12, 2005 11:00 AM

Convert a man page to HTML for easy viewing online:

$ gunzip < /usr/local/man/man8/lsof.8.gz | nroff -man | man2html -title "lsof" > otmp/lsof.html
commandsconvertfiltergunziphtmlman2htmlmanpagenroffonlineshell
Copying a filesystem by xinu on Jan 12, 2005 10:59 AM

Here is a way to copy an entire filesystem without descending down its subsumed mount points. This example uses the root filesystem:

$ find / -xdev | cpio -pm /desired/location
commandscopycpiofilesystemfindrootshell
Correcting Command by xinu on Feb 03, 2005 03:30 PM

If you've run a command that you discover needs a path, you can do something like this on the following line:

$ psql -U postgres mydb_here
bash: psql: command not found

$ /usr/local/pgsql/bin/!!
/usr/local/pgsql/bin/psql -U postgres mydb_here

Welcome to psql 7.3.5, the PostgreSQL interactive terminal.
mydb_here=#
bashcommandsneat
Creating a Software RAID Device by cygnus on Feb 15, 2005 12:03 AM

After you've created two or more linux raid autodetect partitions, you can create a RAID device that uses them by running the mdadm command:

# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/hda2 /dev/hdb1
# mke2fs -j /dev/md0
commandsdebianfilesystemmdadmmke2fspartitionsraid
Creating ICO Files by cygnus on Oct 20, 2005 01:44 PM

You can easily create an .ico file (e.g. a favicon.ico file for your website) with the ImageMagick convert program:

$ convert myicon.png favicon.ico
commandsconvertformaticoimageimagemagickwindows
Debugging Bind 9.x by xinu on Jan 15, 2005 02:54 PM

If you need to see what queries are coming through your nameserver, toggle the querylog flag by typing:

$ rndc querylog
bindbind9commandsdnsnameserverquerylogrndcshell
Debug NAT by xinu on Jun 02, 2005 03:48 PM

If you want to view your PAT for debugging:

pixfirewall# show xlate debug
ciscocommandsdebuggingfirewallnatpatpix
Decrypt RSA Key by xinu on Sep 10, 2005 12:15 AM

Tired of typing your SSL password on boot of your webserver? You can decrypt it if you're certain it's safe:

# openssl rsa -in server.key -out server.key.unsecure
apachebootcommandsencryptionkeyopensslsecurityshellsslwebserver
Diff & Patch by xinu on Jan 12, 2005 12:30 PM

Make a recursive copy of your source tree before any changes (pristine version). E.g., copy project/ to project-pristine/.

After the changes, run this command:

$ diff -crN old new > output.diff
- or -
$ diff -crN project-pristine project > name_of_change.diff

On the target system in /path/to/project/../:

$ patch -p0 --dry-run < ./name_of_change.diff

Remove --dry-run to make it take effect.

commandsdiffpatchprogrammingshell
Display files by size by http://felicity.me.uk/ on Apr 28, 2008 02:08 PM

For example, to display the 20 largest files owned by joe:

find / -printf "%k\t%p\n" -user joe | sort -n | tail -20
commandsfilesfindpermissionsprintfsorttailusers
Display NULL by xinu on Jan 20, 2005 08:10 PM

If instead of a blank space you'd prefer something that tells you a particular column in a row is NULL, you can set it:

\pset null '(null)'
commandsconfigurationpostgresqlpsql
Ditch All Output Of Query by xinu on Jan 12, 2005 10:25 AM

If you want to run a query or a function and ditch the output, you can do something like this:

xinu=# select my_void_function() \g /dev/null
commandsconfigurationpostgresqlpsql

To create a .ico file that can be used for the favicon.ico on webpages, you can use a nice little program called png2ico. There is no package for this in Debian or Ubuntu so you will need to compile it yourself. Compilation is very straightforward. You do need a libpng package. Most of the time it will be installed but if you see an error, just searching for that file will yield the package you need to get for your distribution.

The session below uses /usr/local/src for the compilation and installed to /usr/local/bin. It can be compiled anywhere and installed anywhere, but having it in your $PATH makes things easier:

$ cd /usr/local/src
$ wget http://www.winterdrache.de/freeware/png2ico/data/png2ico-src-2002-12-08.tar.gz
$ tar xvzf png2ico-src-2002-12-08.tar.gz
$ cd png2ico
$ make
$ sudo cp png2ico /usr/local/bin/
$ sudo cp doc/png2ico.1 /usr/local/man/man1/

Once compiled, upload your png images. They should be square; sizes 16x16 and 32x32 are suggested. To create the icon you would then call the following:

$ png2ico favicon.ico your_favicon16x16.png your_favicon32x32.png

Afterwards you will then have a favicon.ico file. You then place this in the webroot of your website add the following to <head></head> section of your webpages:

<link rel="shortcut icon" href="/favicon.ico" />

It's good form to include it, but most common browsers automatically look for an icon at that location.

commandsconvertfaviconiconimagepng2icoshellweb
Echo Hidden by xinu on Jan 15, 2005 02:47 PM

If you want to see how a query like \du is being built:

\set ECHO_HIDDEN
analysiscommandsconfigurationpostgresqlpsqlsql
External SSH Access by xinu on Dec 13, 2005 10:23 AM

You need to get someone into an internal machine that doesn't have a public IP? Use an SSH tunnel. For this example, machine_a is your internal machine and machine_b is external:

$ ssh -R 9000:localhost:22 you@machine_b

Once you've logged in, you should be able to run this on machine_b:

$ ssh -p 9000 you@localhost
commandsnetworkshellsshtunnel
Extract RPM by xinu on Aug 17, 2005 11:22 AM

If you want to extract the contents of an RPM to the current directory without installing it, run the following:

rpm2cpio foo.rpm | cpio -idv
commandscpioextractinstallationrpmrpm2cpio
FIFOs Are Great by xinu on Jan 12, 2005 10:52 AM

If you want to tail the errors on another terminal, just push them to a fifo:

$ mkfifo pgerror
$ psql -U user dbname < ./dbfile 2> pgerror

On your other terminal:

$ tail -f pgerror

Voila! STDOUT on the main terminal, and STDERR on the secondary.

commandserrorsmkfifopipepsqlredirectshelltailterminal
Find and Zip by xinu on Jan 12, 2005 10:59 AM

To zip up the contents of a directory (selectively), use find and zip:

$ find . -type f -name "*.jpg" | zip -@ myimages.zip
commandsdirectoryfindshellzip
Find Out Which Package Contains a File by cygnus on Sep 19, 2005 08:18 AM

The apt-file program allows you to search the contents of all debian packages (installed and not installed) for files that you may need. For example, if you're compiling a program and need a header file but don't know which package provides the file, you can use apt-file to find out which package you should install to fix the problem:

# apt-get install apt-file
# apt-file update
# apt-file search foo.h

Be sure to run apt-file update periodically to update the file listing cache just as you also run apt-get update. The last command above will list any packages whose files match the specified search string, as well as the files that matched:

$ apt-file search bin/lsof
lsof: usr/bin/lsof
lsof: usr/sbin/lsof
aptapt-fileapt-getcommandsdebianlsofneatutilities
Finger for Kernel Versions by xinu on Sep 10, 2005 12:07 AM

Finger the kernel.org finger server to get current kernel versions:

$ finger @finger.kernel.org
[zeus-pub.kernel.org]
Trying 204.152.191.5...
The latest stable version of the Linux kernel is:           2.6.13.1
The latest snapshot for the stable Linux kernel tree is:    2.6.13-git9
The latest 2.4 version of the Linux kernel is:              2.4.31
The latest prepatch for the 2.4 Linux kernel tree is:       2.4.32-pre3
The latest 2.2 version of the Linux kernel is:              2.2.26
The latest prepatch for the 2.2 Linux kernel tree is:       2.2.27-rc2
The latest 2.0 version of the Linux kernel is:              2.0.40
The latest -ac patch to the stable Linux kernels is:        2.6.11-ac7
The latest -mm patch to the stable Linux kernels is:        2.6.13-mm2
commandsfingerkernelnetwork
Fixing an SVN Log Entry by cygnus on Jan 12, 2005 09:48 AM

If you've botched an SVN log entry (typo, etc.), you can fix it as follows:

$ echo "Here is the new, correct log message" > newlog.txt
$ svnadmin setlog myrepos newlog.txt -r 388
brokencommandslogsubversionsvn
Flush Queue by xinu on Mar 16, 2005 12:02 PM

To force it to run through the queue (again), you can run:

# ${PATH_TO_POSTFIX}/postfix flush
commandsconfigurationmailmtapostfixqueueserver
Function Help by xinu on Aug 30, 2005 03:37 PM

Type perldoc -f <function_name> for syntax help. Also, perldoc -q <regexp> will search question headings in the perlfaq[1-9] man pages.

commandsdocslanguagesmanpagesperlperldocprogramming
Generate a Self-Signed SSL Certificate by cygnus on Apr 11, 2005 07:54 AM

Use these commands to generate a self-signed SSL certificate (e.g. for Apache):

# openssl genrsa 1024 > server.key
# openssl req -new -key server.key -x509 -days 90 -out server.crt
apachecertificatescommandskeysopensslsecurityssl
Generating Strong Passwords by cygnus on Apr 05, 2005 10:35 AM

Use the apg utility to generate strong mnemonic passwords:

$ apg -st

Please enter some random data (only first 8 are significant)
(eg. your old password):>
Coydgoceuk6 (Coyd-goc-euk-SIX)
Caculpyep7 (Cac-ulp-yep-SEVEN)
otevDet6 (ot-ev-Det-SIX)
Jiwacwarj6 (Ji-wac-warj-SIX)
gurkOnRyet1 (gurk-On-Ryet-ONE)
EbTarIv0 (Eb-Tar-Iv-ZERO)
apgcommandsgeneratemnemonicneatpasswordsecurityutilities
Grep: Show only filenames by cygnus on Jun 03, 2005 11:12 AM

You can have grep show only the filenames that matched (instead of showing all lines in those files that matched) by using the -l switch:

$ grep -l SELECT *.sql
file1.sql
file2.sql

grep will only list unique filenames (i.e. a file with two matches will only be listed once).

commandsgrepshellunique
Hidden Characters by xinu on Aug 27, 2007 08:18 PM

If you need to know where a line ends, where unprintable characters lurk, and the difference between white space and tabs, you can always remember to take the cat to the vet:

$ <commands> | cat -vet
catcharacterscommandscrlfshell
Ignoring Patterns by cygnus on Dec 31, 2005 04:11 PM

Given a directory DIR and a glob of files (e.g. *.php):

$ svn propset svn:ignore \*.php DIR

You can also remove a property:

$ svn propdel svn:ignore DIR

The svn propset format only allows you to set one pattern at a time. To add multiple patterns, run:

$ svn propedit svn:ignore DIR

which opens a file in an editor where you can add ignore patterns, one per line.

commandsignorepropdelpropeditpropertypropsetsubversionsvn
Import New Project by cygnus on Jan 13, 2005 08:29 AM

To create a new project with its own repository, do this. The svnadmin command assumes the path exists already:

$ svnadmin create /path/to/repository
$ svn import project_name file:///path/to/repository -m 'initial checkin'

Then remove the original copy and check it out:

$ mv project_name project_name.old
$ svn checkout file:///path/to/repository/trunk project_name

Note: You can change the file:// to svn:// or whatever protocol you're using.

commandsimportprojectsubversionsvnsvnadmin
In-place Sed Replace by xinu on Jan 12, 2005 11:54 AM

This command will replace occurrences of foo with bar in the file X in-place and create a backup of X in X.old:

$ sed -i.old "s/foo/bar/g" filename
backupcommandsin-placesedshell
Installing a Specific Package Version by cygnus on Dec 20, 2005 02:04 PM

To use apt-get to install a specific (perhaps older) version of a package, follow the package name with an equals sign and the exact version number. For example:

# apt-get install bash=3.0-17
apt-getcommandsdebianneatpackagetroubleshootingversion
Ipchains Loop by xinu on Sep 28, 2005 10:57 AM

If you need to fool a machine into believing that a host:port pair is local, you can use ipchains to redirect traffic. For example, the desired destination is www.example.com:80 and you want it to go to localhost:8080:

# echo '1' > /proc/sys/net/ipv4/ip_forward
# ipchains -A input -j REDIRECT 8080 -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 80

Note: No one really uses ipchains anymore, but it can be found on older systems.

commandsfirewallip_forwardipchainsloopredirectshell
Libraries by xinu on Mar 22, 2005 08:54 AM

FreeBSD's ldconfig binary doesn't work the same as the one in Linux derivatives. If you happen to type ldconfig -v, for instance, you're going to lose all your configuration information. To fix the problem:

# ldconfig -m /usr/local/lib/compat/pkg                                                          
# ldconfig -m /usr/libexec                                                                       
# ldconfig -m /usr/X11R6/lib                                                                     
# ldconfig -m /usr/local/lib                                                                     
# ldconfig -m /usr/lib
bsdcommandsfreebsdldconfiglibraries
Linux Shared Memory by cygnus on Jan 12, 2005 10:39 AM

Update /etc/sysctl.conf and add (or alter):

kernel.shmmax = <max bytes>

and run sysctl -p to update the system settings.

commandsconfigurationshared-memorysysctlsysctl.confsystem
Listing Open Files in Solaris 10 by xinu on Aug 15, 2007 11:43 AM

Since lsof is tragically broken in Solaris 10, you have to try other methods of finding out which ports a given PID has opened:

# pfiles 2602 &> output

That will redirect stdout and stderr to a file (output) that will outline any files (and ports; remember, everything is a file) that the process has open.

commandslsofpfilesshellsolaris
Locale Fix by cygnus on Jan 12, 2005 11:04 AM

If you get strange locale errors when running perl and GTK apps, run these commands and be sure to generate all en_US locales:

$ apt-get install localeconf
$ dpkg-reconfigure locales
apt-getcommandsdebiandpkggtklocalelocaleconfperl
Locating Files by cygnus on Mar 07, 2005 02:34 PM

Use slocate to build a database of files on your machine and use locate to find them:

# slocate -u # Rebuilds file database by scanning all filesystems
# locate foobar # finds all files with 'foobar' somewhere in the path
commandsdiagnosticfindslocateutilities
Moving Files by xinu on Nov 09, 2005 07:11 PM

If you need to move files, logs, or any kind of program output off a compromised system without disrupting evidentiary data on the disk, use netcat.

On your trusted system:

$ nc -v -l -p 2222 > victim.dump

On the victim's system:

$ <program> | nc <trusted_system> 2222

Where program is the discovery application you're running (e.g. netstat -an).

cleanupcommandsforensicsncnetcatparanoidsecuritytroubleshooting
MySQL DB & User Creation by xinu on Jan 12, 2005 10:50 AM

To create a new database:

$ mysqladmin create <database_name>

To grant permissions to a user, run this:

$ mysql -u root -p
Password: (enter password)
mysql> GRANT ALL ON db_name.* TO username@localhost IDENTIFIED BY "userpasswd";

To flush the privilege tables, run this:

$ mysqladmin flush-privileges

or:

mysql> flush privileges;

To revoke the privileges from a particular user/host pair:

mysql> revoke all privileges, grant option from username;
commandsgotchamysqlmysqladminpermissionsrevokesql
MySQL-style output border by cygnus on Jan 12, 2005 10:25 AM

In your ~/.psqlrc, add this to emulate MySQL-style borders in query results:

\pset border 2
commandsconfigurationmysqloutputpostgresqlpsqlpsqlrc
MySQL Windows CLI by xinu on Jul 27, 2007 03:28 PM

To log into MySQL using the CLI in windows:

(in the mysql\bin directory)
c:\mysql\bin> mysql --user=<user> --pass=<pass> --port=3306
commandlinecommandsmicrosoftmysqlshellwindows
Network Forensics by cygnus on Jan 21, 2005 08:31 AM

You can use the lsof (LiSt Open Files) utility to view information about which processes own file handles on a system. Since sockets map to file descriptors, lsof will show you which processes own socket connections. If you see that your machine is connected to another on TCP port 6234 (source or dest) and you want to find out which process(es) are responsible for the connection, run:

# lsof -ni tcp:6234

Note that when run as an unprivileged user, lsof will only show you file descriptors that you have permission to see. You must run lsof as root to see everything in the kernel.

commandsconnectionsdebuggingdescriptorsfilesystemlsofmonitoringnetworkpermissionsprocesssocketsutilities
Pipe Read by xinu on Jan 25, 2005 02:01 PM

If you want the time, and only the time:

$ date | (read u v w x y z; echo $x)
14:05:52
commandsdateextrasparsingshell
PostgreSQL Client by xinu on Jan 19, 2005 07:35 AM

If you just need the client and not the binary, you can modify the behavior of the port installation like so:

# cd /usr/ports/postgresql7
# make install clean WITHOUT_SERVER=yes

To see the other tasty build options:

# make build
bsdcommandsfreebsdmakepostgresql
Purge Uninstalled Packages by cygnus on Jan 12, 2005 11:04 AM

Use this command to purge old configs and files from your system that are in uninstalled packages:

$ dpkg --get-selections | awk '/deinstall/ {print $1}' | xargs dpkg --purge
awkcommandsconfigurationdebiandpkgpackagespurgexargs
Quick history search by felipec on Jul 10, 2007 04:24 PM

Add the following to your ~/.inputrc:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

And of course, in order to use your ~/.inputrc you need to set your INPUTRC environment variable in ~/.bash_profile:

export INPUTRC=$HOME/.inputrc

The next time you login you will be able to run "gvim <pageup>" and the last entry that started with "gvim " will appear, <pageup> again will bring the next one up, and so on.

Note that escape codes for PageUp and PageDown vary depending on your terminal type; check out this tip for a technique on how to find out what your terminal expects.

bashcommandshistoryinputrcshell
Ranged Curl by xinu on Jan 15, 2005 02:29 PM

If you have a URL that you need to crawl and you know the range of numbers in the image, you can do something like this:

$ curl -O http://www.example.com/img/samples[00-99].jpg

That should (at least attempt to) fetch the images samples00.jpg through samples99.jpg. Enjoy!

If you're using more than one range, you'll want to build your filename or a path with the --create-dirs option. For example:

$ curl http://www.example.com/imgs[00-99]/samples[00-27].jpg --create-dirs -o "#1/#2.jpg"

Alternatively, you can just be ghetto and name the files like dirname_filename.jpg:

$ curl http://www.example.com/images[00-99]/samples[00-27].jpg -o "#1_#2.jpg"
commandscurlextrasimageshellurl
Recursive WGET by xinu on Jan 12, 2005 10:57 AM

Download an entire directory tree:

$ wget -r ftp://username:password@site/path/to/suck
commandsdirectorydownloadftpshelltreewget
Redhat/Fedora Services by xinu on Jan 18, 2005 01:02 PM

If you have a services script in /etc/rc.d, you can add the service to the various run levels to create the appropriate start/kill symlinks:

# chkconfig --level 345 imap on
# service xinetd restart
bootchkconfigcommandsconfigurationfedoraredhatservicesstartupsymlinks
Refresh Apache Logs by xinu on Jan 13, 2005 08:45 AM

Clever kill/cat/sed line to refresh the logs for Apache stolen from some documentation somewhere:

# kill -USR1 $(cat $(httpd -V | sed -n '/DEFAULT_PIDLOG/s/.*"\(.*\)"/\1/p'))
apachecommandskillloggingsed

If your BGP neighbour is a Cisco unit (and possibly others), it is possible to reprocess all learned routes and new announcements without clearing and retransmitting the full contents of the BGP table. This is known as a "soft reconfiguration," and is supported as of IOS 12.0. This avoids fast route cache invalidation, network service disruption, and other results associated with wiping the BGP table that would normally be undesirable, although it is more memory-intensive:

Router# clear ip bgp <neighbor IP, AS number, or *> in

To trigger a release of updates toward a neighbor in a similar fashion:

Router# clear ip bgp <neighbor IP, AS number, or *> out
bgpciscocommandsconfigurationiospeerrefilterrouterouter
Remove Orphaned Packages by cygnus on Jan 12, 2005 11:04 AM

If you have packages on your system upon which no others depend, you easily can find out what they are by running the deborphan program. This command will uninstall them:

$ deborphan | xargs apt-get remove

(The --yes switch can be used with apt-get to continue with the removal instead of asking for confirmation.)

apt-getcleanupcommandsdebiandeborphanutilities
Resetting the Root Password by xinu on Sep 10, 2005 12:14 AM

Reset the root password:

1. Insert the Solaris install CD.
2. Issue STOP-A (Ctrl-Break).
3. Type: boot cdrom -s
4. fsck /dev/rdsk/c0t0d0s0
5. mnt /dev/dsk/c0t0d0s0 /a
6. cd /a/etc
7. TERM="vt100"; export TERM
8. vi shadow
9. on root line, delete everything in the second ":" delimited field.
10. exit out of file (ESC :wq! -or ESC ZZ)
bootcommandsconfigurationhackpasswordresetrootsolarisstartup
Resizing Images by xinu on Nov 03, 2005 08:00 AM

If you find yourself on a machine without the semi-ubiquitous ImageMagick packages, you might at least have pnmscale. Starting with a PNG file, you can do the following to resize it to 450 pixels wide:

$ pngtopnm < ./firefox-upgrade.png | pnmscale -x 450 | cjpeg -smoo 100 -qual 100 > firefox-upgrade.jpg
cjpegcommandsconvertfilterimageimagemagickpngpngtopnmpnmscaleresizescaleshell
Restricting SCP Bandwidth Usage by cygnus on Oct 17, 2005 04:28 PM

You can use the -l <kilobits_per_sec> option with scp (NOT ssh or sftp) to restrict the bandwidth used to transfer files:

$ scp -l 200 user@host:~/files .
bandwidthcommandsnetworkrate-limitingscpsftpshellssh
Reverse Lines by xinu on Jan 15, 2005 05:36 PM

Running this ed command will reverse the lines in the current buffer. This would be useful for logfiles and the like:

:g/^/m0
buffercommandsededitorsvim
Save and View Pipe Stream by xinu on Mar 10, 2005 01:37 PM

You can use the tee program to save the contents of a pipe to a file while also viewing it on standard out:

# tail -0f /var/log/httpd/error_log | tee ~/newest_errors.txt

Note: tail -0 instructs tail to begin at the very end of the file (the default is to show the last ten lines), and -f means tail will periodically check the file for additional data and print the data to standard out.

commandsdebuggingmonitoringpipeshellstdouttailteeutilities
SCP Symlinks by xinu on Dec 19, 2005 12:05 PM

If you're running scp -r, beware of symlinks; they are followed rather than preserved. This might be favorable behavior if you're referencing files outside what you're copying, but if you're copying symlinks which reference other parts of what you're copying, the referenced files will be duplicated on the destination host.

Take, for example, the following files on host A:

~/myfiles/
  foo/
    a.txt
  bar/ -> foo/

When you run this command on host B:

joe@B:~$ scp -r joe@A:~/myfiles .

The result on host B will be:

~/myfiles/
  foo/
    a.txt
  bar/
    a.txt
commandsgotcharecursivescpshellsymlinks
Sendmail Aliases by xinu on Jun 09, 2005 02:32 PM

If you have a system that might be changing versions multiple times you might orphan some of the lateral utilities (like newaliases). If you want to be certain that you're rehashing the correct aliases file (the one that sendmail.cf is referencing), run sendmail with the -bi option like this:

# /path/to/sendmail -bi
aliasescommandsmailmtanewaliasessendmailsendmail.cfserver
Setting the Prompt in 'psql' by cygnus on Jan 14, 2005 12:34 PM

Set the PROMPT1 variable using psql prompt escape sequences:

\set PROMPT1 '[%n@%M:%/]=%# '
  • %n - User
  • %M - Host ([local] or the domain or IP address of the server)
  • %/ - Database
  • %# - # if superuser, $ if regular user.
commandsconfigurationescapepostgresqlpsqlvariables
Shared Lib Dependencies by cygnus on Jan 12, 2005 10:26 AM

Given an executable /path/to/EXEC:

$ ldd /path/to/EXEC
commandsdependenciesdiagnosticexecutablelddlibrariesutilities
Show Databases by xinu on Oct 29, 2005 09:20 AM

A quick way to see all of the databases on the system and (optionally) the number of tables in each:

$ mysqlshow

Use the -v flag to include number of tables.

commandsdatabasesmysqlmysqlshow
Showing Duplicated Lines in a File by cygnus on Feb 15, 2005 04:09 PM

You can use this command to show duplicate lines in a file:

$ uniq -d MYFILE
commandsduplicatesfiltershellsortuniq
Solaris Verson by xinu on Feb 08, 2008 10:58 AM

To determine what version of Solaris you're running, type showrev.

commandssolarissunosversion
Specifying Runtime Linkage Paths by cygnus on Dec 31, 2005 03:51 PM

You can specify the search path(s) used by ld at runtime to find shared objects by building your program with the -rpath option:

$ gcc -Xlinker -rpath -Xlinker /path/to/my/libraries filename.c

This is the equivalent of:

$ ld -rpath /path/to/my/libraries filename.o
ccommandscompilationgcclanguagesldlinkingprogramming
SSH Config by xinu on Dec 05, 2007 10:48 AM

If you find yourself having to log into various systems with long strange names and usernames that aren't your own, check into ~/.ssh/config. Adding a Host block for each system you need to log into will give you a short name to use as well as let you set the user (and various other things - check out man ssh_config):

Host cs
  HostName cs.really.long.name.example.com
  User mrxinu

At this point you can type ssh cs and log right in.

commandsconfigurationsshssh_config
Standalone Procmail by xinu on Sep 10, 2005 12:10 AM

You have a mailbox you need to sort. You can't have it come back through your MTA, of course. Use this script to push it through the procmail filter of your choice:

#!/bin/sh

ORGMAIL=/var/spool/mail/$LOGNAME

if cd $HOME &&
  test -s $ORGMAIL &&
  lockfile -r0 -l3600 .newmail.lock 2>/dev/null
then
  trap "rm -f .newmail.lock" 1 2 3 15
  umask 077
  lockfile -l3600 -ml
  cat $ORGMAIL >>.newmail &&
  cat /dev/null >$ORGMAIL
  lockfile -mu
  formail -s procmail <.newmail &&
  rm -f .newmail
  rm -f .newmail.lock
fi
exit 0
commandsmailboxmtaprocmailscriptsshellsort
Stop On Errors by xinu on Jan 12, 2005 11:07 AM

Set this variable in your ~/.psqlrc to stop on error when psql is used to run non-interactive scripts (e.g. cat file | psql ...):

\set ON_ERROR_STOP 1

Or use it from the command line:

$ psql ... -v ON_ERROR_STOP=1 ...
commandsconfigurationdebugginginteractivepipepostgresqlpsqlpsqlrc
Symbols by xinu on Jan 20, 2005 08:50 PM

If you want to list the symbols of your object code, you can use the nm command:

$ nm object_file.o
ccommandslanguagesnmprogramming
Syntax Highlighting by xinu on Dec 31, 2005 04:11 PM

If you would like to have syntax highlighting on a file that would otherwise not have any highlighting at all, you can symlink the file to the appropriate extension and open it:

$ ln -s example.lxp example.html
$ vi example.html # opened with pretty highlighting

*Note: This should be used sparingly and you should clean up your symlinks.

commandseditorshighlightingshellsymlinksyntaxvi
System Monitoring by xinu on Jan 20, 2005 08:58 PM

A nice way to take the pulse of a BSD machine is to run systat -vm. It updates often and includes quite a bit of useful information.

bsdcommandsfreebsdmonitoringsystat
Tagging by cygnus on Jan 13, 2005 08:27 AM

Tagging is useful for taking snapshots of releases. For example, in /path/to/project:

$ svn copy trunk tags/release-1.0
$ svn commit -m 'Created release 1.0 tag.'
branchescommandscommitcopysnapshotssubversionsvntagging
Tar + SSH by xinu on Feb 10, 2005 05:39 PM

To transfer files via tar/ssh, do the following:

$ tar cvjf - * | ssh user@remote "(cd /desired/path; tar xjf -)"
commandspipeshellsshtartunnel
Testing Authentication by xinu on Aug 19, 2006 03:32 PM

A way to test whether your domain login credentials are working is via net use on the commandline like so:

c:\> net use \\<computername>\IPC$ /user:<domain>/<username> *

The * forces it to ask for your password. Otherwise, you can replace * with your password to do it all at once. Also, net use supports smartcard authentication, etc.

Thanks to Scott Morrison (a.k.a. "Plaid") for the tip!

authenticationcommandsnetsmartcardwindows
Testing Webserver with Netcat & Echo by xinu on Jan 12, 2005 10:58 AM

Netcat is handy little utility for scripting all manners of network functionality. Here we're making sure a web server is responding as we'd expect:

$ (echo "GET / HTTP/1.1"; echo "Host: www.xinu.org"; echo) | nc www.xinu.org 80
commandsdebuggingmonitoringnetcatnetworkshellutilities
Tracking Down Symlinks by xinu on Jun 24, 2005 01:41 PM

Make sure you always specify a path free of symlinks. This can be pretty tough, though. An alternative approach is to use namei to track down symlinks:

# namei /usr/X11/bin/xterm
f: /usr/X11/bin/xterm
d /
d usr
l X11 -> X11R6
  d X11R6
d bin
- xterm
commandsdirectorynameipathshellsymlinkstree
Upload Directory Structure by xinu on Jul 12, 2006 01:48 PM

If you need to upload an entire directory structure, check out wput on sourceforge.net. It works the same way as wget only in the other direction (i.e., supporting various protocols).

http://wput.sourceforge.net/

Thanks to Aronalle for this tip!

commandsdownloadnetworkshellsourceforgeuploadwgetwput
Useful Exim commands by http://felicity.me.uk/ on Apr 28, 2008 02:00 PM

display the route from your server to any email address:

exim -bt email@domain.com

send an email using exim:

exim -v email@domain.com

show the number of emails in the queue:

exim -bpc

display the mail queue:

exim -bp

flush queue:

exim -qff &

view a particular mail in the queue:

exim -Mvh msgid (for headers)
exim -Mvb msgid (for body)
commandseximmailmta
Variable Indirection by xinu on Jan 31, 2006 10:06 AM

Sometimes you need to iterate over variable names and access their values. In shell script, you would do something like this to get the values of FOO and BAR:

$ FOO=apple
$ BAR=orange
$ VARS="FOO BAR"
$ for v in $VARS ; do echo ${!v} ; done

The above works in bash. Use this in Zsh:

$ for v in $VARS ; do echo ${(P)v} ; done

(The 'P' flag on ${v} causes a further variable lookup before ${v} is evaluated.)

Thanks to Cliff for the tip!

bashcommandsenvironmentevaluationiterationloopshellzsh
Watching Connections by xinu on Jun 02, 2005 09:15 AM

If you want to use tcpdump to watch initiating connections (that is, the syn flag only is set indicating we're looking at the first third of the three-way handshake) on ports 80 and 443 you could do something like this:

# tcpdump '(tcp[13] & 0x3f = 2) and (dst port 80 or dst port 443)'
commandsconnectionsmonitoringnetworksecurityshelltcpdump
Xargs House-Cleaning by xinu on Jan 13, 2005 08:29 AM

If you have a bunch of files in your home directory and you want to push them into ~/sort, create the directory and then do the following:

$ find . -type f -maxdepth 1 ! -name ".?*" | xargs -I '{}' mv '{}' sort

Note: GNU xargs uses -i. BSD versions use -I.

bsdcommandsdirectoryfindgnushellsortxargs
Xargs & SSH by xinu on Apr 19, 2006 05:48 AM

Let's say you want to check the uptime on a list of servers. We're assuming that you've got a key on each machine otherwise you'll be entering your password often:

$ xargs -i ssh {} uptime < ./server.list
  5:46am  up 155 days, 17:49,  2 users,  load average: 0.12, 0.03, 0.01
  5:46am  up 147 days, 17:14,  2 users,  load average: 0.02, 0.05, 0.01
  5:46am  up 209 days, 17:26,  0 users,  load average: 0.00, 0.00, 0.00
  5:46am  up 89 days,  6:30,  0 users,  load average: 0.00, 0.00, 0.00
  5:46am  up 82 days,  6:40,  0 users,  load average: 0.07, 0.06, 0.01
  5:46am  up 104 days,  9:51,  0 users,  load average: 0.03, 0.03, 0.00
  5:50am  up 68 days,  9:17,  0 users,  load average: 0.00, 0.00, 0.00
  5:48am  up 68 days,  9:15,  0 users,  load average: 0.00, 0.00, 0.00
commandskeyloopremoteserversshellsshuptimexargs
RSS