2
Shell Cheat Sheet linuxadminhelp.blogspot.in Useful Editing Keystrokes for shell KEYSTROKE(s) FUNCTIONS Up Move back one command in the history list Down Move forward one command in the history list Left Move back one character. Right Move forward one character Esc + f Move forward one word Esc + b Move forward one word Ctrl + A Move to the beginning of line Ctrl + E Move to the end of line Ctrl + D Delete current character Backspace Delete previous character Esc + d Delete current word Ctrl + U Delete from beginning of line Esc + k Delete to end of line Ctrl + Y Retrieve last item deleted Esc Insert last word of previous command Ctrl + L Clear the screen, placing the current line at the top of the screen Tab Attempt to complete the current word, interpreting it as a filename, username, variable name, hostname, or command as determined by the context Esc + ? List the possible completions Ctrl + C Sends an interrupt signal to the currently executing command, which generally responds by terminating itself Ctrl + D Sends an end of file to the currently executing command. Use this keystroke to terminate console input Ctrl + Z Suspends the currently executing program exit Exit from shell Shell special characters CHARACTER FUNCTIONS # Marks the command as a comment, which the shell ignores ; Separates commands, letting you enter several commands on a single line & Placed at the end of a command, causes the command to execute as a background process, so that a new shell prompt appears immediately after the command is entered () execute commands in subshell {} execute commands in current shell $var Substitue the declare variable with its value while execution of the command special characters used in filename globbing(filename metacharacters) METACHARACTER FUNCTIONS * Matches a string of zero or more characters ? Matches exactly one character [ abc ...] Matches any of the characters specified [ a - z ] Matches any character in the specified range [! abc ...] Matches any character other than those specified [! a - z ] Matches any character not in the specified range ~ The home directory of the current user ~ userid The home directory of the specified user ~+ The current working directory ~- The previous working directory SHELL ALIASES alias name='command' (like --> alias mv='mv -i') unalias <alias name> special scripts SCRIPT FUNCTIONS /etc/profile Executed when the user logs in ~/.profile Executed when the user logs in

Bash Shell cheat sheat

Embed Size (px)

Citation preview

Page 1: Bash Shell cheat sheat

Shell Cheat Sheet linuxadminhelp.blogspot.in

Useful Editing Keystrokes for shellKEYSTROKE(s) FUNCTIONS

Up Move back one command in the history list

Down Move forward one command in the history list

Left Move back one character.

Right Move forward one character

Esc + f Move forward one word

Esc + b Move forward one word

Ctrl + A Move to the beginning of line

Ctrl + E Move to the end of line

Ctrl + D Delete current character

Backspace Delete previous character

Esc + d Delete current word

Ctrl + U Delete from beginning of line

Esc + k Delete to end of line

Ctrl + Y Retrieve last item deleted

Esc Insert last word of previous command

Ctrl + L Clear the screen, placing the current line at the top of the screen

Tab Attempt to complete the current word, interpreting it as a filename, username, variable name, hostname, or command as determined by the context

Esc + ? List the possible completions

Ctrl + C Sends an interrupt signal to the currently executing command, which generally responds by terminating itself

Ctrl + D Sends an end of file to the currently executing command. Use this keystroke to terminate console input

Ctrl + Z Suspends the currently executing program

exit Exit from shell

Shell special charactersCHARACTER FUNCTIONS

# Marks the command as a comment, which the shell ignores

; Separates commands, letting you enter several commands on a single line

& Placed at the end of a command, causes the command to execute as a background process, so that a new shell prompt appears immediately after the command is entered

() execute commands in subshell

{} execute commands in current shell

$var Substitue the declare variable with its value while execution of the command

special characters used in filename globbing(filename metacharacters) METACHARACTER FUNCTIONS

* Matches a string of zero or more characters

? Matches exactly one character

[ abc ...] Matches any of the characters specified

[ a - z ] Matches any character in the specified range

[! abc ...] Matches any character other than those specified

[! a - z ] Matches any character not in the specified range

~ The home directory of the current user

~ userid The home directory of the specified user

~+ The current working directory

~- The previous working directory

SHELL ALIASES

alias name='command' (like --> alias mv='mv -i') unalias <alias name>

special scriptsSCRIPT FUNCTIONS

/etc/profile Executed when the user logs in

~/.profile Executed when the user logs in

Page 2: Bash Shell cheat sheat

Shell Cheat Sheet linuxadminhelp.blogspot.in~/.bashrc Executed when BASH is launched

~/.bash_logout Executed when the user logs out

Shell evironment variablesVARIABLE FUNCTIONS

USER The user's current username; may differ from the login name if the user executes the su command

DISPLAY The X display to be used; for example, localhost:0

HOME The absolute path of the user's home directory

HOSTNAME Internet name of the host

LOGNAME The user's login name

MAIL The absolute path of the user's mail file

PATH The search path

SHELL The absolute path of the current shell

TERM The terminal type

printenv Print environment values

export <variable> To make the value of a shell variable available to the programs invoked by the shell

Variable= To remove the value associated with shell variable, give the variable an empty value(though it will appear in the output of set cmd)

Unset <variable> To dispense the variable from the shell

CONTROLLING OPERATION OF THE ShellCHARACTER FUNCTIONS

' Characters within a pair of single quotes are interpreted literally; that is, their metacharacter meanings (if any) are ignored. Similarly, the shell does not replace references to shell or environment variables with the value of the referenced variable

“ Characters within a pair of double quotes are interpreted literally; that is, their metacharacter meanings (if any) are ignored. However, the shell does replace references to shell or environment variables with the value of the referenced variable

` ` Text within a pair of back quotes is interpreted as a command, which the shell executes before executing the rest of the command line. The output of the command replaces the original back-quoted text

\ The following character is interpreted literally; that is, its metacharacter meaning (if any) is ignored. The backslash character has a special use as a line continuation character. When a line ends with a backslash, the line and the following line are considered part of a single line

Input/Output Redirection and Piping (stdin,stdout,stderr)REDIRECTOR FUNCTIONS

cmd > file Redirects standard output stream to specified file (same as cmd 1> file)

cmd 2> file Redirects standard error stream to specified file

cmd >> file Redirects standard output stream to specified file, appending output to the file if the file already exists

cmd 2>> file Redirects standard error stream to specified file, appending output to the file if the file already exists

cmd &> file Redirects standard output and error streams to the specified file

cmd > file 2>&1 Another way to redirect both stdout and stderr of cmd to a file

cmd < file Redirects standard input stream to the specified file

cmd << text Reads standard input until a line matching text is found, at which point end of file is posted

cmd > /dev/null Discard stdout of cmd

cmd 2> /dev/null Discard stderr of cmd

cmd &> /dev/null Discard stdout and stderr of cmd

{ cmd1; cmd2; } > file Redirect stdout from multiple commands to a file

cmd << EOL line1 line2 EOL

Redirect a bunch of lines to the stdin. If 'EOL' is quoted, text is treated literally. This is called a here-document

cmd1 | cmd2 Takes the standard input of cmd2 from the standard output of cmd1 (also known as the pipe redirector)

cmd1 |& cmd2 Redirect stdout and stderr of cmd1 to stdin of cmd2 (bash 4.0+ only)

cmd | tee file Redirect stdout of cmd to a file and print it to screen

A cheat sheet by Shiwang Kalkhanda ([email protected]) 2012.http://linuxadminhelp.blogspot.inReleased under GNU Free Document License