bash-history-cheat-sheet.pdf

(77 KB) Pobierz
Bash History Cheat Sheet
BashHistoryCheatSheet
Emacs and Vi history editing keyboard shortcuts:
Shortcut Description
Emacs Mode Shortcuts:
CTRL-p Fetch the previous command from the history list.
CTRL-n Fetch the next command from the history list.
CTRL-r Search history backward (incremental search).
CTRL-s Search history forward (incremental search).
Meta-p Search backward using non-incremental search.
Meta-n Search forward using non-incremental search.
Meta-< Move to the rst line in the history.
Meta-> Move to the end of the history list.
Vi Mode Shortcuts:
k Fetch the previous command from the history list.
j Fetch the next command from the history list.
/stringorCTRL-r Search history backward for a command matchingstring.
?stringorCTRL-s Search history forward for a command matchingstring.
n Repeat search in the same direction as previous.
N Repeat search in the opposite direction as previous.
G Move to the N-th history line (for example,15G).
History behavior modication via shell variables:
ShellVariable Description
HISTFILE Controls where the history le gets saved. Set to/dev/nullnot to keep history.
Default: /.bash history.
HISTFILESIZE Controls how many history commands to keep inHISTFILE.
Default: 500.
HISTSIZE Controls how many history commands to keep in the history list of current session.
Default: 500.
HISTIGNORE Controls which commands to ignore and not save to the history list. The variable takes a
list of colon separated patterns. Pattern&matches the previous history command.
History behavior modication viashoptcommand:
shoptoption Description
histappend Setting the variable appends current session history toHISTFILE. Unsetting overwrites
the le each time.
histreedit If set, puts a failed history substitution back on the command line for re-editing.
histverify If set, puts the command to be executed after a substitution on command line as if you had
typed it.
shoptoptions can be set by a shopt-soption and can be unset by a shopt-uoption shell command.
A cheat sheet byPeterisKrumins(peter@catonmat.net), 2008.
http://www.catonmat.net - good coders code, great reuse
ReleasedunderGNUFreeDocumentLicense.
675539167.051.png 675539167.062.png 675539167.067.png 675539167.068.png 675539167.001.png 675539167.002.png 675539167.003.png 675539167.004.png 675539167.005.png 675539167.006.png 675539167.007.png 675539167.008.png 675539167.009.png 675539167.010.png 675539167.011.png 675539167.012.png 675539167.013.png 675539167.014.png 675539167.015.png 675539167.016.png 675539167.017.png 675539167.018.png 675539167.019.png 675539167.020.png 675539167.021.png 675539167.022.png 675539167.023.png 675539167.024.png 675539167.025.png 675539167.026.png 675539167.027.png
History expansion:
Shortcut Description
Event Designators:
! Starts a history substitution.
!! Refers to the last command.
!n Refers to then-th command line.
!-n Refers to the current command line minusn.
!string Refers to the most recent command starting withstring.
!?string? Refers to the most recent command containingstring(the ending ? is optional).
^string1^string2^ Quick substitution. Repeats the last command, replacingstring1withstring2.
!# Refers to the entire command line typed so far.
Word Designators (word designators follow the event designators, separated by a colon):
0 The zeroth (rst) word in a line (usually command name).
n Then-th word in a line.
^ The rst argument (the second word) in a line.
$ The last argument in a line.
% The word matched by the most recent ?string? search.
x-y A range of words fromxtoy(-yis synonymous with0-y).
* All word but the zeroth.
x* Synonymous withx-$.
x- The words fromxto the second to last word.
Modiers (modiers follow word designators, separated by a colon):
h Removes a trailing pathname component, leaving the head.
t Removes all leading pathname components, leaving the tail.
r Removes a trailing sux of the form .xxx, leaving the basename.
e Removes all but the trailing sux.
p Prints the resulting command but does not execute it.
q Quotes the substituted words, escaping further substitutions.
x Quotes the substituted words, breaking them into words at blanks and newlines.
s/old/new/ Substitutesnewforold.
& Repeats the previous substitution.
g Causess/old/new/or&to be applied over the entire event line.
History expansion examples:
$echoabcde (executes`echoabcde`)
abcde
$echo!!:3-$ (executes`echocde`)
cde
$echo!-2:*:q (executes`echo'abcde'`)
abcde
$echo!-3:1:2:4:x(executes`echo'a''b''d'`)
abd
$echo!-4:1-3:s/a/foo/:s/b/bar/:s/c/baz/
(executes`echofoobarbaz`)
foobarbaz
$tar-xzfpackage-x.y.z.tgz
...
$cd!-1:$:r(exec's`cdpackage-x.y.z`)
package-x.y.z$
$ls-a/tmp
file1file2file3...
$^-a^-l^ (exec's`ls-l/tmp`)
-rw-------1useruserfile1
...
A cheat sheet byPeterisKrumins(peter@catonmat.net), 2008.
http://www.catonmat.net - good coders code, great reuse
ReleasedunderGNUFreeDocumentLicense.
675539167.028.png 675539167.029.png 675539167.030.png 675539167.031.png 675539167.032.png 675539167.033.png 675539167.034.png 675539167.035.png 675539167.036.png 675539167.037.png 675539167.038.png 675539167.039.png 675539167.040.png 675539167.041.png 675539167.042.png 675539167.043.png 675539167.044.png 675539167.045.png 675539167.046.png 675539167.047.png 675539167.048.png 675539167.049.png 675539167.050.png 675539167.052.png 675539167.053.png 675539167.054.png 675539167.055.png 675539167.056.png 675539167.057.png 675539167.058.png 675539167.059.png 675539167.060.png 675539167.061.png 675539167.063.png 675539167.064.png 675539167.065.png 675539167.066.png
Zgłoś jeśli naruszono regulamin