Recent Notes
Displaying keyword search results 1 - 10
Created by voodoo on January 03, 2012 08:41:21
Last update: February 16, 2012 15:50:06
This is the command to print all regular files in the src folder but excluding all files within the .svn folders:
$ find src -name .svn -prune -o -type f -print
where -o is the or operator.
Define a shortcut:
ff ()
{
find $1 -name .svn -prune -o -...
Created by voodoo on February 16, 2012 13:35:38
Last update: February 16, 2012 13:35:57
The C shell allows you to define aliases with arguments: \!^ passes the first argument, \!* passes all arguments. Examples from http://unixhelp.ed.ac.uk :
alias print 'lpr \!^ -Pps5'
alias print 'lp...
In ksh or bash you cannot define alias with arguments. Use function instead.
Created by Dr. Xi on June 20, 2011 15:18:06
Last update: June 20, 2011 15:18:06
Perl does not have built-in functions to get the base name or dir name from a file path. But on the Unix platforms we can rely on the executables basename and dirname .
#!/usr/bin/perl
$f = '/A path with/space "/file...
The quotes, escapes, and chomp are necessary:
# This fails when there's a space in $f
$base =...
Created by woolf on May 15, 2011 15:11:42
Last update: May 15, 2011 15:11:57
On windows, display IPv4 routing table:
route -4 print
On Linux:
$ route
Kernel IP routing table
Destination ...
This works for both Linux and Windows (" -r ": display routing table, " -n ": display address and port numbers in numerical form):
netstat -rn
Created by jinx on April 20, 2011 08:40:38
Last update: April 20, 2011 08:48:09
The PHP function time returns the current time in seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). This is the same function as the Perl time() .
<?php
print time() . "\n";
?>
Calling mktime without any arguments does the same:
<?php
echo mktime(), "\n";
?>
Created by Dr. Xi on March 28, 2011 11:11:33
Last update: March 28, 2011 11:13:21
grep is a versatile command with many variations (grep, egrep, fgrep, then various implementations). It uses a regula expression (regex) pattern to filter input. But then there are basic and extended flavors of regex - leading to even more confusion. And, beware that there are lots of bad examples of regex in the wild... There are two critical questions to ask when you use grep: which grep implementation are you using? what is the flavor of the regex? Here are some examples for gnu grep v2.7:
# Find all numbers (no decimal point), basic regex... Use the -o flag to show only the matching part instead of the whole matching line: grep -o -E '\b[0-9]{2}\b' The good thing about the gnu grep is that it...
Created by Dr. Xi on February 28, 2011 12:29:19
Last update: February 28, 2011 12:30:40
The Unix shell passes these parameters to the shell script:
Variable Meaning
$* A single string representing all command line arguments separated by $IFS (internal field separator, usually a space)
$@ A sequence of strings representing the command line arguments.
$1,$2...$n $1 is the first argument, $2 is the second argument, and so on...
$0 The name of the script itself.
$# The number of arguments.
Example shell script ( sharg.sh ):
#!/bin/sh
echo $# arguments passed to $0: $@
...
Output for ./sharg.sh "a b c d" :
1 arguments passed to ./sharg.sh: a b c d
here ...
Output for ./sharg.sh a "b c" d :
3 arguments passed to ./sharg.sh: a b c d
here ...
Created by Dr. Xi on February 17, 2011 13:23:16
Last update: February 17, 2011 13:23:16
To find the PID of the tomcat instance that is currently running:
ps -ef | grep java | grep tomcat | awk '{print $2}...
Created by Dr. Xi on December 04, 2009 04:33:05
Last update: December 04, 2009 04:33:05
Variable Meaning $_ The default or implicit variable. @_ Within a subroutine the array @_ contains the parameters passed to that subroutine. $a, $b Special package variables when using sort() $<digit> Contains the subpattern from the corresponding set of capturing parentheses from the last pattern match, not counting patterns matched in nested blocks that have been exited already. $. Current line number for the last filehandle accessed. $/ The input record separator, newline by default. $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after...
Created by Dr. Xi on December 16, 2008 21:17:15
Last update: December 16, 2008 21:19:04
The -h switch prints file or directory sizes in human readable format:
# disk usage for current directory
$ du -ks...