The following is a table of handy shell commands using standard *NIX utilities (such as find, grep, xargs, et cetera). This table is not sorted semantically. Use your browser's search method (CTRL+F) to find specific commands. Tags have been included to ease this. Some commands may have unforeseen effects when not used in the way I imagined it; and since you have no way to verify what I imagined is what you think I imagined, think before using any of the below.
No warranty is given. Blame yourself for not thinking before executing some command you found on a random site and found everything to go wrong. This page is primarily a resource for myself to prevent re-invinting wheels, and published publically here to hopefully prevent the same for others.
TagsCommandEffect
Samba, mount, NFS
su -c "smbmount <samba address> <mountpoint> -o uid=<user ID of mountpoint folder>,gid=<group ID>"
Mounts a given network location to a given folder (mountpoint). Sets owner and group fields of the mountpoint to the given settings.
SVN (subversion), recursive, find, delete
find . | grep -i svn$ | xargs rm -rf
Finds and deletes all directories (and files) ending with "svn". Can be used to recursively purge the current directory from all .svn-directories. Warning: files or directories in the repository ending on svn will be deleted as well!
code, c++, coding, counting, lines
find . -type f -name *.h -o -name *.cpp | xargs cat | wc -l
Recursively counts and sums up the number of lines in all .h and .cpp files found in the current directory.
SSH, tunnel, port
ssh -f <username>@<host> -L <local port>:<network pc>:<remote port> -N
Connects to a host and through that host, forwards all communication from "localhost:local port" to "remote port" on a machine only accessable from the host (a private network server, for example). The -f and -N flags cause ssh to fork in the background and remain active; the port tunnel remains active for as long this process runs.
SSH, SVN (subversion), remote, tunnel, network, checkout, https
ssh -f <username>@<host> -L 1707:<SVN host>:443 -N
svn co https://localhost:1707/<repository>
Creates a port tunnel which links the local port 1707 to the secure HTTP port of a server on some local network. The second commands shows how to check out a repository through such a tunnel. See also the general port forwarding command above.
SSH, SVN (subversion), remote, tunnel, network, checkout
ssh -f <username>@<host> -L 1707:<SVN host>:3690 -N
svn co svn://localhost:1707/<repository>
Creates a port tunnel which links the local port 1707 to the default SVN port of a server on some local network. The second commands shows how to check out a repository through such a tunnel. See also the general port forwarding command above.
SVN (subversion), server, change, url
svn switch --relocate svn://localhost:1708/figures svn://duiven.mine.nu/figures
Changes which server svn should connect to in the current repository. The current server name can be obtained with "svn info".
PS, PDF, postscript, conversion, convert, ps2pdf
ls *.ps | xargs -n 1 ps2pdf
Converts all .ps files in the local directory to .pdf using ps2pdf
LaTeX, Makefile, tex, pdf, rerun, tex
%.pdf : %.tex
        pdflatex -interaction="nonstopmode" $^ &> /dev/null
        if grep -q \\citation ${^:%.tex=%.aux}; then \
                bibtex ${^:%.tex=%}; \
        fi
        if pdflatex -interaction="nonstopmode" $^ > warnings.log; then \
                while grep -q Rerun\ to\ get\ cross-references\ right warnings.log; do \
                        pdflatex -interaction="nonstopmode" $^ > warnings.log; \
                done; \
                (grep -i warning warnings.log || true );\
                xpdf ${^:%.tex=%.pdf};\
        else \
                (grep -i warning warnings.log || true );\
                (grep -i error warnings.log || true );\
        fi
        rm -f warnings.log
Makefile entry which enables it to create pdf documents out of tex sources. Performs an initial run of pdflatex, followed by a run of bibtex, which is then followed by as many additional pdflatex runs as required. If all went well, it opens the resulting pdf using xpdf for final review. Warnings are printed to stdout. If errors occured, those are also given to stdout. Note that warnings.log is used as a temporary file by this makefile script.
Qemu, qcow, disk creation, virtualisation
qemu-img create -f qcow <name> <size>
Creates a HDD image with a given maximum size. To be used in virtualisation.
Qemu, KVM, virtualisation, installing
echo "Installing $2 to virtual hdd $1. Using $3 MB of memory.";
echo "qemu-kvm -M pc -no-acpi -hda $1 -cdrom $2 -boot d -m $3 -win2k-hack -smp 2";
        
qemu-kvm -M pc -no-acpi -hda $1 -cdrom $2 -boot d -m $3 -win2k-hack
 
$1 is a HDD image, $2 is a boot image, and $3 denotes the amount of memory to be used. -win2k-hack is used to speed up windows 2000 virtualisation.
Qemu, KVM, virtualisation, running
echo "Running $1 on $2 MB of memory.";
qemu-kvm -M pc -no-acpi -hda $1 -m $2 -soundhw es1370 -localtime -boot c -usb -win2k-hack 
 
$1 is a HDD image, $2 is the amount of memory. -smp would control the number of processors assigned to virtualisation.
sed, pattern repitition
echo "test.bmp" | sed 's/\(.*\)\.bmp/\1\.bmp\ \1\.jpg/g'
 
This outputs: "temp.bmp temp.jpg&qout;.
The \(\) matches what is in between the brackets, and stores the result in memory. The memory can then be read out with \1, or higher numbers when using multiple brackets.
Last update: 30th of June, 2008