From wikistone
Contents
regex
- * any char
- ? single char
- [characters] all chars
- [!characters] not all chars
- [[:class:]] specified class
- [:alnum:]
- [:alpha:]
- [:digit:]
- [:lower:]
- [:upper:]
examples:
| pattern | match |
|---|---|
| a*b | a, any # chars, b |
| poo??? | poo then any 3 char |
| [abc] | an a, b, or c |
| poo.[0-9][0-9][0-9] | poo. then any 3 # |
| [[:upper:]]* | any beginning with an upper |
| [![:digit:]]* | any not beginning with a digit |
| *[[:lower:]123] | and ending with lower or 1|2|3 |
| .[!.]* | all starting with . followed by anything |
find
by size
find files at least _kb in size:
$ find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} \;
Example (50 megs):
$ find / -type f -size +50000k -exec ls -lh {} \;
RedHat / CentOS / Fedora
$ find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Debian / Ubuntu
$ find {/path/to/directory} -type f -size +{file-size-in-kb}k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
std in, out, & err
- 0 : in
- 1 : out
- 2 : error
redirection
out
$ [command] > [dump_location]
err
$ [command] 2> [dump_location]
out & err old way newer way
$ [commnad] > [dump_location] 2>&1 $ [commnad] &> [dump_location]
append std to dump_location
$ [command] >> [dump_location] $ [command] &>> [dump_location]
repeat a function
Add this to ~/.bashrc for persistance.
function repeat { while 1 ; do "$@" ; sleep 1 ; done; }
watch a command
watch -n # [command] # -> interval
arithmetic
$ ((expression)) Ops:
- + : add
- - : sub
- * : multiplication
- / : division
- % : mod
- ** : exp
Examples:
echo $(($((5**2)) * 3)) echo $(((5**2) * 3)) echo Five divided by two equals $((5/2)) echo with $((5%2)) left over.
brace expansion
Structure: [preambple]{expansion_set}[postscript]
Examples:
$ echo Front-{A,B,C}-Back
Front-A-Back Front-B-Back Front-C-Back
$ echo Number_{1..5}
Number_1 Number_2 Number_3 Number_4 Number_5
$ echo {01..15}
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
$ echo {001..15}
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
$ echo {Z..A}
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
$ echo a{A{1,2},B{3,4}}b
aA1b aA2b aB3b aB4b
$ mkdir {2007..2009}-{01..12}
$ ls
2007-01 2007-07 2008-01 2008-07 2009-01 2009-07
2007-02 2007-08 2008-02 2008-08 2009-02 2009-08
2007-03 2007-09 2008-03 2008-09 2009-03 2009-09
2007-04 2007-10 2008-04 2008-10 2009-04 2009-10
2007-05 2007-11 2008-05 2008-11 2009-05 2009-11
2007-06 2007-12 2008-06 2008-12 2009-06 2009-12
quotes and escapes
Double Quotes... "exp" :
Special character handling is suppressed except for $, `, and \.
Single Quotes... 'exp' :
Special character handling is always suppressed.
Escapes... /exp :
Uh, escape a special char. Examples:
$ echo "dolla \$2.98" dolla $2.98 $ mv bad\&filename good_filename
And also for Escape Sequences:
| Sequence | What It Do |
|---|---|
| \a | bell (system beep) |
| \b | backspace |
| \n | newline / Unix:linefeed |
| \r | carriage return |
| \t | tab |