Listing files
ls -alhp [Gg]* // all files; long format; shortened file sizes; directories with '/'
ls -d [Gg]* // directories as plain files
Jobs
nohup make batch0 >& make-0.out & { don't hangup and redirect errors to file }
Regexp
. Any character
* 0 or more prev characters
? 0 or 1 prev characters
^ Beginning of line
$ End of line
[abc] Match any one of characters
[abc|def] Match either set
Grep:
grep [options] regexp files
-E = interpret regexp as an extended regular expression (basic regular expressions need a '\' to escape metacharacters)
-n = print line number
-i = ignore case
-c = count matches
-v = print lines not matching regexp
-r = recurse thru subdirectories
Find: recursively descend directory tree starting at given path
find path [options]
-name expr = name of file to find
-iname = same as -name but case insensitive
-type char = file type. "d"=directory.
Tar
tar cvfz file.tar.gz ...
tar xvfz file.tar.gz
For loop
for x in $( ls|grep '[[:digit:]]' ); do echo tar cf $x.tar $x; echo bzip2 --best $x.tar;done > /tmp/zip2.bat
Nfs
root# mount giles:/nfs /mnt/nfs
Edit /etc/fstab to have this line:
giles:/nfs /mnt/nfs nfs rsize=8192,wsize=8291,timeo=14,intr 0 0
Mac:
umount -f /mnt/nfs/
mount_nfs 192.168.0.13:/home/ /mnt/nfs/
Disk space:
df -h .
Directory size:
du -hs
Link
ln -s bin bin.linux
File type
file
If output is 'text', file is a text file. 'data' means a binary file.
Text processing
cut -f2 {get second field}
sort -u {get unique rows}
tr -d {delete string from input}
sed s/foo/fooey/ {replace all instances of foo}
Bash shell
.profile {user environment setup}
alias dir='ls -al'
PS1='[$HOSTNAME:\!] ' {sets the prompt}
export PS1
Korn shell
Cmd number = '!'
Filename completion (emacs mode): ESC - ESC, ESC - =
Secure Shell and Copy
ssh @
scp @:
Users and Groups
adduser // create new user
adduser // assign group to user
id
Permissions
chmod a+w
chown :
Processes
ps ax[l|j|u]U
Selection: a=all processes w/tty; x=all processes w/o tty; U=by user
Output formats: l=long; j=jobs; u=user
nice -n
renice [-p |-g ] {only su can decrement priority}
Searching for executables and documentation:
which
locate
apropos
Mac OS X
Displaying dot files in Finder:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Network Utility: displays networks status
Adding a PICT preview to an EPS file:
epstool --add-pict-preview --mac-rsrc abb.eps abb.eps/rsrc
mailx:
Sending mail:
echo 'This is a test' | mailx -s 'Subject' ybendana@yahoo.com
Commands:
from {display message headers}
Msg-list:
* {all msgs}
$ {last msg}
- {previous msg}
+ {next msg}
= {print current msg}
Sun
stop-a gives prompt; type 'boot' to reboot
vi
0/$ = go to start/end of line
G = go to end of file
:n = move to line number n
C-g = show current line number
C-f/C-b = scroll forward/backward
{/|?} = search forward/backward for regexp {escape "/" with "\"}
n = move forward to next matching expression
i = insert
a = append
Esc = exit out of editing mode
:w = write
:q = quit
x = delete character
dd = delete line
CVS
Create repository:
cvs -d /usr/local/cvsroot init
Environment vars:
export CVSROOT=/usr/local/cvsroot
export CVS_RSH=ssh
Importing files
cd
cvs import -m "comment" vendor_tag release_tag
Checkout
cvs checkout|co {Local}
cvs -d :ext:faun.example.org:$CVSROOT checkout {Remote}
cvs -z3 -d:ext:ybendana@cvs.sourceforge.net:/cvsroot/dart co -P modulename
Add file
cvs add
cvs commit
Remove file
cvs remove -f
cvs commit
-- YuriBendana - 26 Jul 2006 |