From wikistone
Jump to: navigation, search
Line 71: Line 71:
 
==arithmetic==
 
==arithmetic==
 
'''$ ((expression))'''
 
'''$ ((expression))'''
 +
Ops:
 +
* + : add
 +
* - : sub
 +
* <nowiki />* : multiplication
 +
* / : division
 +
* % : mod
 +
* <nowiki>**</nowiki> : exp
 +
 +
Examples:
 +
<pre>
 +
echo $(($((5**2)) * 3))
 +
echo $(((5**2) * 3))
 +
echo Five divided by two equals $((5/2))
 +
echo with $((5%2)) left over.
 +
</pre>

Revision as of 10:19, 7 December 2013

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.