From wikistone
(→regex) |
|||
| (10 intermediate revisions by the same user not shown) | |||
| Line 68: | Line 68: | ||
<pre>watch -n # [command] | <pre>watch -n # [command] | ||
# -> interval</pre> | # -> interval</pre> | ||
| + | |||
| + | ==arithmetic== | ||
| + | '''$ ((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> | ||
| + | |||
| + | ==brace expansion== | ||
| + | Structure: [preambple]{expansion_set}[postscript] | ||
| + | |||
| + | Examples: | ||
| + | <pre>$ 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 | ||
| + | </pre> | ||
| + | |||
| + | ==quotes and escapes== | ||
| + | '''Double Quotes'''... <nowiki>"exp"</nowiki> :<br> | ||
| + | Special character handling is suppressed except for $, `, and \. | ||
| + | |||
| + | '''Single Quotes'''... <nowiki>'exp'</nowiki> :<br> | ||
| + | Special character handling is always suppressed. | ||
| + | |||
| + | '''Escapes'''... /exp : <br> | ||
| + | Uh, escape a special char. Examples: | ||
| + | <pre> | ||
| + | $ echo "dolla \$2.98" | ||
| + | dolla $2.98 | ||
| + | $ mv bad\&filename good_filename</pre> | ||
| + | And also for Escape Sequences: | ||
| + | {| class="wikitable" | ||
| + | |- | ||
| + | ! Sequence !! What It Do | ||
| + | |- | ||
| + | | \a || bell (system beep) | ||
| + | |- | ||
| + | | \b || backspace | ||
| + | |- | ||
| + | | \n || newline / Unix:linefeed | ||
| + | |- | ||
| + | | \r || carriage return | ||
| + | |- | ||
| + | | \t || tab | ||
| + | |} | ||
| + | ==shell prompt== | ||
| + | ===bash at login=== | ||
| + | Adjust the following for the appropriate SHELL at login: | ||
| + | * bash: .bash_profile, .bash_login, .profile (for backwards compabitibility) | ||
| + | * sh: .profile | ||
| + | * tcsh and csh: .login | ||
| + | * zsh: .zshrc | ||
| + | <pre> | ||
| + | # ~/.profile | ||
| + | clear | ||
| + | SHELL=/bin/bash exec /bin/bash --login | ||
| + | </pre> | ||
| + | ===shell prompt=== | ||
| + | export PS1="gobldygook" | ||
| + | gobldygook: | ||
| + | * \a : an ASCII bell character (07) | ||
| + | * \d : the date in "Weekday Month Date" format (e.g., "Tue May 26") | ||
| + | * \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required | ||
| + | * \e : an ASCII escape character (033) | ||
| + | * \h : the hostname up to the first '.' | ||
| + | * \H : the hostname | ||
| + | * \j : the number of jobs currently managed by the shell | ||
| + | * \l : the basename of the shell’s terminal device name | ||
| + | * \n : newline | ||
| + | * \r : carriage return | ||
| + | * \s : the name of the shell, the basename of $0 (the portion following the final slash) | ||
| + | * \t : the current time in 24-hour HH:MM:SS format | ||
| + | * \T : the current time in 12-hour HH:MM:SS format | ||
| + | * \@ : the current time in 12-hour am/pm format | ||
| + | * \A : the current time in 24-hour HH:MM format | ||
| + | * \u : the username of the current user | ||
| + | * \v : the version of bash (e.g., 2.00) | ||
| + | * \V : the release of bash, version + patch level (e.g., 2.00.0) | ||
| + | * \w : the current working directory, with $HOME abbreviated with a tilde | ||
| + | * \W : the basename of the current working directory, with $HOME abbreviated with a tilde | ||
| + | * \! : the history number of this command | ||
| + | * \# : the command number of this command | ||
| + | * \$ : if the effective UID is 0, a #, otherwise a $ | ||
| + | * \nnn : the character corresponding to the octal number nnn | ||
| + | * \\ : a backslash | ||
| + | * \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt | ||
| + | * \] : end a sequence of non-printing characters | ||
Latest revision as of 15:26, 24 March 2014
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 |
shell prompt
bash at login
Adjust the following for the appropriate SHELL at login:
- bash: .bash_profile, .bash_login, .profile (for backwards compabitibility)
- sh: .profile
- tcsh and csh: .login
- zsh: .zshrc
# ~/.profile clear SHELL=/bin/bash exec /bin/bash --login
shell prompt
export PS1="gobldygook" gobldygook:
- \a : an ASCII bell character (07)
- \d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
- \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
- \e : an ASCII escape character (033)
- \h : the hostname up to the first '.'
- \H : the hostname
- \j : the number of jobs currently managed by the shell
- \l : the basename of the shell’s terminal device name
- \n : newline
- \r : carriage return
- \s : the name of the shell, the basename of $0 (the portion following the final slash)
- \t : the current time in 24-hour HH:MM:SS format
- \T : the current time in 12-hour HH:MM:SS format
- \@ : the current time in 12-hour am/pm format
- \A : the current time in 24-hour HH:MM format
- \u : the username of the current user
- \v : the version of bash (e.g., 2.00)
- \V : the release of bash, version + patch level (e.g., 2.00.0)
- \w : the current working directory, with $HOME abbreviated with a tilde
- \W : the basename of the current working directory, with $HOME abbreviated with a tilde
- \! : the history number of this command
- \# : the command number of this command
- \$ : if the effective UID is 0, a #, otherwise a $
- \nnn : the character corresponding to the octal number nnn
- \\ : a backslash
- \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
- \] : end a sequence of non-printing characters