For notes on Solaris/SunOS, this way.
this page is a random collection of things related to shell, C compiling, and etc:
HTML Colors
http://www.computerhope.com/htmcolor.htm
ssh-agent
after running, copy the output and run them:
SSH_AUTH_SOCK=/tmp/ssh-ABIxF27536/agent.27536; export SSH_AUTH_SOCK; SSH_AGENT_PID=27537; export SSH_AGENT_PID; echo Agent pid 27537;then use ssh-add
ssh-add -l will list keys on the agent
get cpu information
in file /proc/cpuinfo
screen
screen is a powerful tool for text-mode operation. The most useful feature is that you even your terminal dies, your program can still be running in screen.
there's little information on the official page. But the man page and info page look good.
this link is good to start with: http://www.kuro5hin.org/story/2004/3/9/16838/14935
To change escape character, edit .screenrc, e.g.
escape ^Vv
patch for GNU screen: added vertical split http://fungi.yuggoth.org/vsp4s/
In bash, set screen title to current running program, with this in .bashrc
export PS1="[\u@\h \w]"'\033k\033\\\$ '
Then in .screenrc
shelltitle "$ |bash"
In tcsh, add this in .cshrc
if ($TERM == 'screen') then
alias postcmd 'echo -n "\ek${USER}@${HOST}:${cwd} - `history -h 1`\e\\"'
endif
Another example to start multiple ssh in .screenrc
escape ^Vv
vbell on
autodetach on
startup_message off
defscrollback 2048
hardstatus alwayslastline "%{= kK}%50>%n%f %< %{=kG}%-= %M %d %c:%s"
sessionname box
screen ssh ccjbox5
stuff "cd /ccj/w/data05z/run8pp-ndst/run8-agg\015\015"
screen ssh ccjbox6
stuff "cd /ccj/w/data06z/run8pp-ndst/run8-agg\015\015"
screen ssh ccjbox7
stuff "cd /ccj/w/data07z/run8pp-ndst/run8-agg\015\015"
screen ssh ccjbox8
stuff "cd /ccj/w/data08z/run8pp-ndst/run8-agg\015\015"
if it's in a file other than .screenrc, can be run with "screen -c [filename]"
make, Makefile, automake, autoconf, etc.
My notes are here.
Shell
/usr/bin/sh -n will check the syntaxuse set -x to print out something, set +x will change it back.
be careful about spaces around = and anywhere else in the script
Libraries
Check if libs are linked correctlyldd [your program]Calling the libs dynamically is to use dlopen(), dlsym(), dlclose() and etc. Find some examples here.
redirection
an example
[yangrz@rcas2070 ~]$ root -b <<EOF
? .ls
? .q
? *******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 4.01/02 9 February 2006 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled for linux with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.152, Sep 13 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
TROOT* Rint The ROOT of EVERYTHING
[yangrz@rcas2070 ~]$
Find printers
look at /etc/printcap, then use "lpr -Pprintername filename"AFS & quota
the AFS cell for rhic is called "rhic".- klog kerbos login
- unlog destroy tokens
- tokens list tokens
- fs lq: see quota for afs
- quota -v: see quota
- fs listacl filename: access
Find
this part is copied from BABAR work book To find a file, use the command:> find start_directory -name filename -printThis will initiate a search through the directory start_directory and all its subdirectories, for the file filename. Wildcards may be used in the filename, but in this case, the filename must be quoted. Examples:
> find . -name myfile.txt -print > find .. -name "*.txt" -printYou may wish to put an alias in your .cshrc file to handle the simplest use of this command:
> alias findfile "find . -name \!^ -print"
Find file size greater than 1G
find -name '*' -size +1000k
Find file modified in last 30 min
find . -mmin -30
Run multiple commands
find *tar -exec sh -c "tar xvf {}; rm {}" \;
More examples http://www.linux.ie/newusers/beginners-linux-guide/find.php
Disk Usage
sort the disk usage without the annoying error message:du -s * 2>/dev/null | sort -n-h for du will display size in K, M, G, ...
create dirs named by numbers
mkdir `seq -s " " 1 20`
go back
cd -
dealing with processes
fg, bg, jobs, stop, kill, top, etc. kill something by number instead of PID e.g. kill %5. The number can be seen using jobs.look at files
cat, more, head, tail, diff and etc.cat -n print file with line numbers.
tail -20 filename prints last 20 lines.
grep is very powerful command, it is usually used with pipes. It can also be used to find string in a file like: grep "some string" filename.
Note that grep looks for regexp while fgrep looks for literal string.
sometimes sdiff is preferred than diff, e.g. use sdiff liek this sdiff -w40 file1 file2
mount USB
cd /mnt/ su mkdir usbflash mount /dev/sda1 /mnt/usbflash ls usbflash umount /dev/sda1 /mnt/usbflash
UIUC specific information
ph server: ns.uiuc.edunntp server: news.ks.uiuc.edu
top
show 1 screen and exittop -b -n1
Free X server under Windows
Xming : http://www.straightrunning.com/XmingNotes/
Screen capture
import from ImageMagick package
to get the id of an X window, use xwininfo
TightVNC
include both server and viewer, works well under Windows XP and Unbuntu Linux
definition of load average in UNIX/Linux
http://www.teamquest.com/resources/gunther/display/5/
const and C++
http://duramecho.com/ComputerInformation/WhyHowCppConst.html
webcron
cron from their website:
http://www.webcron.org/index.php?&lang=en
The UNIX-haters' Handbook
web.mit.edu/~simsong/www/ugh.pdfrun at boot
The easy way, put it in /etc/rc.local
or write a script that conforms to the rules as in the policy of the specific distribution.
Then update the rc.d scripts. For example, in Debian/Ubuntu:
update-rc.d php-fpm defaults
Integer types with exact bits
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html
csh and rsh
from rsh's man page:
If you are using csh(1) and put a rsh(1) in the background without redirecting its input away from the
terminal, it will block even if no reads are posted by the remote command. If no input is desired you
should redirect the input of rsh to /dev/null using the -n option.
You cannot run an interactive command (like rogue(6) or vi(1)); use rlogin(1).
Stop signals stop the local rsh process only; this is arguably wrong, but currently hard to fix for rea-
sons too complicated to explain here.
less
to preserve the ANSI colors, use -R option
ANSI codes: http://www.dee.ufcg.edu.br/~rrbrandt/tools/ansi.html
redirect stderr separately in csh
yeah we all hate csh, let sh do it for you
sh -c 'command 1>out.txt 2>err.txt &'
the csh way is an abomination
( command >stdout_file ) >&stderr_file
exact width integers
http://en.wikipedia.org/wiki/Stdint.h
portability notes
http://cr.yp.to/docs/unixport.html
ImageMagick
print image size, etc:
identify <file>
convert -size 1869x672 xc:black all.png composite -gravity northwest 2A.png all.png all.png composite -gravity north 2B.png all.png all.png composite -gravity northeast 2C.png all.png all.png composite -gravity southwest 3A.png all.png all.png composite -gravity south 3B.png all.png all.png composite -gravity southeast 3C.png all.png all.png
Debian packages
http://www.debian.org/doc/FAQ/ch-pkgtools.en.html
sub-string in C
http://stackoverflow.com/questions/874015/updated-is-this-a-good-substr-for-c
VirtualBox
booting Scientific Linux 4.7 hangs at "Ok, booting the kernel" with SMP kernel, non-SMP kernel boots fine.
So far, it's still not fixed:
http://www.virtualbox.de/ticket/770
const reference in programming
http://www.parashift.com/c++-faq-lite/const-correctness.html
HAKMEM
http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html
postgres upgrade Ubuntu jaunty -> karmic
postgresql-8.3 is removed as said in the warning during upgrade, to resolve this, one needs to install postgresql-8.3, run it and upgrade the cluster
Ubuntu : Karmic PostgreSQL Upgrade 8.3 -> 8.4 Stop cluster for 8.4, if it$,1ry(Bs running
sudo pg_ctlcluster 8.4 main stop
Drop the cluster for 8.4
sudo pg_dropcluster 8.4 main
Need to install 8.3 here and start it with "pg_ctlcluster"
With 8.3 running, run pg_upgradecluster
sudo pg_upgradecluster -v 8.4 8.3 main
If all goes well, cluster for 8.3 can be dropped
sudo pg_dropcluster 8.3 main
https://bugs.launchpad.net/ubuntu/+source/postgresql-8.3/+bug/403381