UNIX
To determine the size of a directory: du -hs directory/
The du command looks at all the subdirectories to calculate the directory size.
tar (e.g., for arxiv submission): tar -cvvf ../grb.tar ../arxiv/
gzip a file: gzip -c H1.tar > H1.tar.gz
unzip to a different directory: gzip -cd file.tar.gz --uncompress > ./file.tar
This is handy if you directory permissions require that you copy the .gz file to one directory, but you need the contents in a different directory!
unzip and untar: gunzip file.gz tar -xvf file.tar
change owner to ethrane: chown ethrane
change permissions: chmod u+x file
In this example we add permission to user (owner) ("u") the ability to execute ("x").
To take away that permission, you'd type chmod u-x file.
You can modify permissions for three groups: user--aka the owner--("u"), group ("g"), and other--aka everyone else--("o").
To see what permissions are turned on/off, type ls -hl file.
scp over the web: scp -r ethrane@dante.u.washington.edu:directory/file/ .
symbolic linking: ln -s file-or-directory link
the -s flag stands for "symbolic"
setting unix variables
set variable = value (in tsch or something)
varb=value (in bash)
to see the value of a variable: echo $variable
to see what shell you're using: echo $SHELL
the different types of shells: bash, tsch, csh...
to pick a shell place at the beginning of script: #! /usr/bin/bash
To change the default shell: chsh or ypchsh
to make comments in a shell script: # followed by space, then comments
to find a file by name: find directory -name "filename_fragment*" -print
to find a directory by name: find . -type d -name "engrun" 2> /dev/null
to find a file by content: grep "this string" *
-l flag supresses line number
-i flag ignores case
-exec lpr {} ";" to do something to the file (like print it.)
in order to find strings buried in a binary file: strings framefile.gwf
(You can pipe this to grep to look for a specific string.)
to find/locate stuff on suketto: find /home/atmpd/skrep/06b_new/atmpd/src -print | grep fillnt.F
to find something on spartha: find -name stochastic.m
to reboot: su root then: reboot
to force a terminal screen: ctrl alt F1
to leave the terminal screen: ctrl alt F7
to kill a job like you mean it: kill -KILL 15786
to suspend a foreground job: ctrl-z
to suspend a job from a different terminal: kill -stop PID
to restart it: kill -cont PID
to place a job under nohup once it is running: disown -h 98937
to resume said job: type fg in the command line.
to move a job from foreground to background: ctrl-z (to suspend), then bg
to force a stubborn job into the background when it prefers the foreground:
echo "" > dummy.input
apdetsim.sh < dummy.input
recursive ls: ls -R
recursive grep: grep -r
ls but ignore certain files: ls -I "*.txt" -I "*.csv"
copy but ignore certain files: find H1/model/V4/ ! -name '*REF*' | xargs -i cp {} H1/model/test/
another xargs command: find ./ -name "*.m" | xargs -i grep "lsc.electronics_gain" {}
override safe delete: alias rm rm
or: unalias rm
reinstate safe delete: alias rm rm -i
ssh keygen: ssh-keygen -t dsa
This creates a file called id_dsa.pub in your .ssh/ directory.
Then append the id_dsa.pub file to the authorized_keys2 file in the .ssh directory of the computer/account you want to ssh to:
e.g. more id_dsa.pub >> ~atmpd/.ssh/authorized_keys2
(another SK example:) scp ~ktc/id_dsa.pub skrep@kmcvs:kev.pub
more kev.pub >> .ssh/authorized_keys2 (from kmcvs)
to convert a .ps to a .pdf: ps2pdf file.ps
use convert to reduce the size of a file: convert -density 200x200 -quality 60 -compress jpeg input.pdf output.pdf
to add an executable to your path:
open .csrch file in home directory
find the line where it says "# set path = "
add an additional path onto the end of the line, but before the right parenthetical.
to run a job in the background: follow the command with an ampersand.
Then you can even log off and the job will keep running.
to write error output to a log file: upmu1_low >& error.log
Set your environmental variables: with a .cshrc file
Create your own auto-completions: by sourcing .tcshrc
Are two files different? diff file1 file2
Lists all the differences between file1 and file 2. If nothing happens, the files are the same.
diff -q suppresses the list of differences and says only if the files are different (when you want a simple answer.)
to list local files while sftp-ing: lls
to list only files that don't end in ".F": ls -I "*.F"
to list only directories: find . -type d
to change local directories: lcd
to look at the first five lines of a file: head -n5 filename
to look at the last five lines of a file: tails -n5 filename
to delete all the white space from a file: cat file | tr -d "[:space:]"
to remove all the new lines from a file: cat file | tr -d "\n"
to remove ^M's from excel exports: tr '\r' '\n' < eric.prn > eric.txt
to remove every instance of "insect" and "bug" from a file: cat file | tr -ds "insect" "bug"
to sort with scientific notation: sort -g file
to delete consecutive duplicate lines from a file: uniq file
to delete non-consecutive duplicate lines from a file: sort -bn nevthru.dat | uniq | more > nevthru.del
find and replace strings with sed
to forward mail sent to your suketto account: create a .forward file and put your email address in it
to determine the number of lines in a file: set file_size = `wc -l $source_dir$source_file | awk '{print $1}'
to determine the length of a filename: echo $file | awk '{print length}'
wc (word count) returns *newlines* *words* *bytes*
awk '{print $1} isolates and prints the first number, which is the one we want.
another example of awk: grep "-78 6" cone.dat | awk '{print "hits="$3", alpha="$4}'
this command prints the third word (hits) and forth word (alpha) on any line that contains "-78 6"
To force a script to use the $SHELL variable: source script.sh
(otherwise it can default to bash shell)
To get color code terminal windows: include "setenv TERM xterm" in your .cshrc file. (cshell)
export LS_OPTIONS='--color=auto'
eval `dircolors`
alias ls='ls $LS_OPTIONS' (bash)
double less-than is used to direct input to another command.
Here, for example, we direct everything in between the two exclamation marks into the cat command:
cat <<! >! $RFLIST
...
!
the name of the computer you are using is returned by the command: hostname
to force a manual core dump: gcore pid
creates core.pid
To view a .gif/.jpeg/etc. image file: xv file.gif
or convert it to an eps: convert test.gif test.eps
Then you can open it with gsview.
To fix errors associated with "X connection": try removing entries from .ssh/known_hosts so they can refresh when you ssh -X
To rename a terminal window (from bash): echo -n -e "\033]0;name\007"
To print remotely: cat file.ps | ssh physics.umn.edu "cat - |lpr -P216"
Make sure to render your file as a ps/pdf before printing it in this fashion.
To print on one side (or two):
lpr -o sides=two-sided-long-edge filename
lpr -o sides=two-sided-short-edge filename
lpr -o sides=one-sided filename
To control the orientation:
lpr -o portrait filename
lpr -o landscape filename
Check the status of print jobs: lpstat 216
unfreeze a terminal window: ctrl-q
list library dynamic dependencies: ldd executable
$LD_LIBRARY_PATH is a colon-separated list of paths to shared-object libraries.
how was a library compiled: file /apps/Linux/gds/lib/libawg.so
/apps/Linux/gds/lib/libawg.so: ELF 32-bit LSB shared object, Intel 80386,
version 1 (SYSV), not stripped
Is my executable 32-bit or 64 bit? file executable
compiling 32-bit code on a 64-bit machine: gcc -m32
compile library:
$(FRVER)/src/libFrame.a : untar.log
rm -f $(FRVER)/src/*.o
cd $(FRVER)/src; gcc -O -Wall -fexceptions -fPIC -c FrameL.c FrIO.c zlib/*.c -Izlib
rm -f $(FRVER)/src/libFrame.a
ar r $(FRVER)/src/libFrame.a $(FRVER)/src/*.o
ranlib $(FRVER)/src/libFrame.a
repeat a command every second: watch -n 1 'echo "929033456 - `tconvert now`" | bc'
list all environmental variables: printenv
handy tool for checking library dependencies of an app: gdd executable
pipe input to /dev/null if you do not want it written to screen or to disk.
How much memory is matlab using? ulimit -a
Then run top to see what percentage of the memory matlab is using.
Limit memory usage: ulimit -v 4096000
How do I search previous commands to determine, e.g., how I called some code yesterday?
history | grep "executable_name" | more
How to find non-printable characters in a file? (useful when porting a google doc to latex!)
grep '[^[:print:]]' main.tex
Back to Resources
ethrane@u.washington.edu