-
In "unix," to monitor system calls, use strace or truss.
- In "C++", to string out in full justified hex with type safety:
my_type val = foo;
cout << hex << setiosflags(ios::right) << setw(2*sizeof(my_type)) << val << endl;
- In "linux," to scan for hosts in local domain:
nmap -sP 192.168.1.1-255
- In "linux," to download an http file without a browser, use wget.
- In "emacs", to do regular expression replacement, i.e.,
of x? --> y?
M-x query-replace-regexp RET
x\([0-9]\) RET
y\1 RET
- In "emacs" to manipulate rectangular regions, mark first corner, move to second,
Ctrl-x r k (kill)
Ctrl-x r y (yank).
- to view ps with the full process inheritance tree, try
ps -faux
- to print strings inside a binary try:
strings < binary >
- to print symbols inside a binary try:
nm < binary >
- to look inside an rpm:
rpm -q -l -p < .rpm file >
- to goto page inside Acrobat Reader 7.0:
shift-ctrl-N
- In "sh," to call another program, blah,
with the same arguments that were passed to the shell script:
#!/bin/sh
blah $*
or
#!/bin/sh
blah "$@"
which also passes arguments with embedded character sequences.
-
In "gcc," to show all of the macros that are defined for a given platform:
gcc -dM -E test.c
- In "gas," to show macro expansion listings
gas foo.s -ahlm
-
to spy on officemates:
/usr/sbin/tcpdump -X -s 0 src ip_address | more
-
to spy on net connections machines or processes: nmap or netstat -anp
- In "emacs," to enable conservative indentation, add this to your .emacs files
add-hook 'c++-mode-hook
(function (lambda ()
(c-set-style "k&r")
(setq c-basic-offset 2)
)))
for more information, look at
"/usr/uns/share/emacs/19.34/lisp/cc-mode.el"
- In emacs, to show last typed commands: C-h l
- In "gcc," stringification:
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning:
" #EXP "\n"); }
while (0)
-
In "emacs," to create a macro :
Ctrl-X "(" keys Ctrl-X
")"
Ctrl-X "(" keys Ctrl-X
")"
- In "emacs," to run the macro :
Ctrl-X e
- In "emacs," to create a .emacs entry corresponding to a key sequence :
see emacs faq, #116
- In "make," to run a command without having it barf on error :
rule:
-mkdir blah
-
In "gmake," fancy automatic variables.
%.s: %.S
$(RGCC) -E $< -o $@
%.lnk: %.o
$(GEO) link 0 16 0 $^ libarch.a -o $@
- In "gmake," a strlen function.
strlen = $(strip $(shell /bin/echo -n $(1) | /usr/bin/wc -c))
MAX_FIGURE = 10
FIGURE_DIGITS := $(call strlen,$(MAX_FIGURE))
- To use CVS over ssh:
setenv CVS_RSH ssh
alias cvs cvs -d :ext:user_name@host:cvsroot_path
- To see what happened in the CVS repository between two and four hours ago:
cvs diff -D "2 hour ago" -D "4 hour ago"
- LD_LIBRARY_PATH can be overridden by /etc/ld.so.conf, followed by
ldconfig to update the .so cache
- When your terminal gets messed up because you tried to print out binary stuff, type "reset"
- ps, so that more does not get screwed up: ps -www -aux | more
- To capture screen in X.
xwd > blah
xpr blah > blah.ps
use xv to convert to ppm or whatever
-
To sync up the times when make sucks.
rdate < time server >
- To highlight a zephyr message, hold down shift.
- OpenPBS commands
qsub -V -I -q short -l nodes=1:dual2.2GHz (interactive, dual 2.2 GHz)
pbsnodes -a (list servers)
qstat -Q (list queues)
qsub -1 node=foo
- To view x resources: editres
- To check for non-updated files with cvs:
bash -c "cvs status 2> /dev/null | grep Status | grep Need"
- To get the time on unix systems:
#include < stdio.h>
#include < stdlib.h>
#include < dlfcn.h>
#include < sys/time.h>
#include < unistd.h>
typedef unsigned long long UInt64;
UInt64 current_microseconds()
{
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv,&tz);
  return (tv.tv_sec*1000000 + tv.tv_usec);
}
On x86-linux machines, there's a macro that accesses the
machine's cycle counter. It's higher resolution but not as portable.
You also have need to know the frequency of the machine.
#include < asm/msr.h >
{
  UInt64 time;
  rdtscll(time);
  printf("%llu cycles\n",time);
}