Unix Mnl

From Biowiki
Jump to: navigation, search
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 <file1> <file2> ...
	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 <directory>

Link
	ln -s bin bin.linux

File type
	file <filename>
	If output is 'text', file is a text file. 'data' means a binary file.

Text processing
	cut -f2 <file> {get second field}
	sort -u <file> {get unique rows}
	tr -d <string> {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 <user>@<hostname>
	scp <file> <user>@<hostname>:<directory>

Users and Groups
	adduser <user> // create new user
	adduser <user> <group> // assign group to user
	id <user>

Permissions
	chmod a+w <file>
	chown <user>:<group> <file>

Processes
	ps ax[l|j|u]U <user>
		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 <increment> <program>
	renice <priority> [-p <pid>|-g <gid>] {only su can decrement priority}

Searching for executables and documentation:
	which <file>
	locate <file>
	apropos <string>

Mac OS X
	Displaying dot files in Finder:
	  defaults write com.apple.finder [[Apple Show All Files]] 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 <msg-list> {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
  {/|?}<regexp> = 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 <project>
		cvs import -m "comment" <project> vendor_tag release_tag
	Checkout
		cvs checkout|co <module> {Local}
		cvs -d :ext:faun.example.org:$CVSROOT checkout <module> {Remote}
		cvs -z3 -d:ext:ybendana@cvs.sourceforge.net:/cvsroot/dart co -P modulename
	Add file
		cvs add <file>
		cvs commit
	Remove file
		cvs remove -f <file>
		cvs commit

-- Yuri Bendana - 26 Jul 2006