Linux common Commands-command line editing, history, command line shortcut keys, Pstree,alias, command substitution, wildcard characters

Source: Internet
Author: User
Tags aliases clear screen documentation

command-line editing:
Cursor Jump:
CTRL + A: Skip to the beginning of the command
Ctrl+e: Jump to the end of the command line
Ctrl+u: Delete the cursor to the beginning of the command line
CTRL+K: Delete the cursor to the end of the command line
Ctrl+l: Clear Screen
Ctrl+d: Delete the contents after the cursor


Command history:
View command history: Historical
-C: Empty command history
-D OFFSET [n]: Delete command at specified position
-W: Save the Command history to the history file

Environment variables
Path: Command Search Path
Histsize: Command history buffer size


The use of command history tips:
!n: Executes the nth command in the command history;

[Email protected] ~]$!1
Whatis Mans
Man (1)-format and display the on-line manual pages
Man (1p)-Display system documentation
Man (7)-Macros to format mans pages
Man.config [Man] (5)-Configuration data for Mans
Man [Manpath] (1)-format and display the on-line manual pages
Man-pages (7)-Conventions for writing Linux mans pages
[Email protected] ~]$ history
1 Whatis Mans


!-n: Executes the reciprocal nth command in the command history;

Whatis Mans
History
[Email protected] ~]$!-2
Whatis Mans
Man (1)-format and display the on-line manual pages
Man (1p)-Display system documentation
Man (7)-Macros to format mans pages
Man.config [Man] (5)-Configuration data for Mans
Man [Manpath] (1)-format and display the on-line manual pages
Man-pages (7)-Conventions for writing Linux mans pages


!: Executes the previous command;

[[email protected] ~]$!!
Whatis Mans
Man (1)-format and display the on-line manual pages
Man (1p)-Display system documentation
Man (7)-Macros to format mans pages
Man.config [Man] (5)-Configuration data for Mans
Man [Manpath] (1)-format and display the on-line manual pages
Man-pages (7)-Conventions for writing Linux mans pages


!string: The most recent command in the command history that starts with a specified string

[Email protected] ~]$!man
Mans
[Email protected] ~]$
[Email protected] ~]$


!$: References the last parameter of the previous command;

[Email protected] ~]$ ls/tmp/
ABC inittabl.2 KEYRING-C6BPQR ORBIT-GDM pulse-y030ipht7unr test
Hi keyring-11uhbi keyring-hxk4gf orbit-rhel rc Virtual-rhel. T2nxt0
Inittab KEYRING-4AFGVD KEYRING-TTIDCT passwd rc.2
Inittab.1 keyring-6hak4z keyring-v1ncmd PULSE-KYYFFO5RNHPL rc.3
[email protected] ~]$ ll!$
ll/tmp/
Total 84
Drwxr-xr-x. 2 root root 4096 Nov 20:26 ABC
Drwxr-xr-x. 2 root root 4096 Nov 20:28 hi
-rw-r--r--. 1 root root 884 Nov 02:59 Inittab
Drwxr-xr-x. 2 root root 4096 Nov 21:01 inittab.1
Drwxr-xr-x. 2 root root 4096 Nov 21:01 inittabl.2
DRWX------. 2 Rhel rhel 4096 Nov 17:54 Keyring-11uhbi
DRWX------. 2 Rhel rhel 4096 June KEYRING-4AFGVD


Esc. Same as!$


ALT +. (remote terminal not supported)



Command completion:
PATH:
Path Completion:


Pstree: Show Process Tree

NAME
Pstree-display a tree of processes

[Email protected] ~]$ Pstree
Init─┬─networkmanager─┬─dhclient
│└─{networkmanager}
├─abrtd
├─acpid
├─atd
├─AUDITD───{AUDITD}
├─bonobo-activati───{bonobo-activat}
├─clock-applet
├─CONSOLE-KIT-DAE───63*[{CONSOLE-KIT-DA}]
├─crond
├─cupsd
├─2*[dbus-daemon───{dbus-daemon}]
├─2*[dbus-launch]
├─devkit-power-da
├─gconfd-2


History: Command Historical use

[Email protected] ~]$ history
1 Whatis Mans
2 whatis/etc/passwd
3 Mans Whatis
4 Whatis CD
5 Whatis ls
6 Whatis Type
7 Whatis du
8 Whatis Echo
9 Whatis MV
Ten Whatis Man
One man cut
Cut-d:/etc/passwd
Cut-d:-f1/etc/passwd


-C: Clear History

-N: Delete the specified location command

-W: Save command to History file


Command aliases
Alias cmdalias= ' COMMAND [options] [arguments] '
Aliases defined in the shell are valid only for the current shell life cycle, and the valid range of aliases is only the current shell process;

[[email protected] ~]$ alias
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias Vi= ' Vim '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '
[Email protected] ~]$


[[Email protected] ~]$ type alias
Alias is a shell builtin
[email protected] ~]$ Help alias
Alias:alias [-P] [Name[=value] ...]
Define or display aliases.

Without arguments, ' alias ' prints the list of aliases in the reusable
Form ' Alias Name=value ' on standard output.

Otherwise, an alias was defined for each NAME whose the VALUE is given.
A trailing space in VALUE causes the next word to being checked for
Alias substitution when the alias is expanded.

Options:
-P Print all defined aliases in a reusable format

Exit Status:
Alias returns True unless a NAME is supplied for which no alias have been
Defined.
[Email protected] ~]$


Canceling command aliases

Ualias Cmdalias


Use the original command

\cmd

[Email protected] ~]$ \ls/tmp/
ABC inittabl.2 KEYRING-C6BPQR ORBIT-GDM pulse-y030ipht7unr test
Hi keyring-11uhbi keyring-hxk4gf orbit-rhel rc Virtual-rhel. T2nxt0
Inittab KEYRING-4AFGVD KEYRING-TTIDCT passwd rc.2
Inittab.1 keyring-6hak4z keyring-v1ncmd PULSE-KYYFFO5RNHPL rc.3
[Email protected] ~]$


Command substitution: $ (command), anti-quote: ' command '
To replace a subcommand in a command with the process of executing the result
File-2013-02-28-14-53-31.txt



Quotes supported by bash:
": Command substitution

[Email protected] ~]$ echo "dir is ' pwd '"
Dir Is/home/rhel
[Email protected] ~]$ cd/tmp/
[Email protected] tmp]$ echo "dir is ' pwd '"
Dir is/tmp
[Email protected] tmp]$


"": weak reference, can implement variable substitution

[Email protected] tmp]$ echo "The path is $PATH"
The path Is/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/rhel/bin
[Email protected] tmp]$


': Strong reference, do not complete variable substitution

[Email protected] tmp]$ echo ' The path is $PATH '
The path is $PATH
[Email protected] tmp]$



File name wildcard, globbing
*: Any character of any length
?: any single character
[]: matches any single character within the specified range
[ABC], [A-m], [A-z], [A-z], [0-9], [a-za-z], [0-9a-za-z]
[: Space:]: white space character
[:p UNCT:]: Punctuation
[: Lower:]: lowercase letters
[: Upper:]: Uppercase
[: Alpha:]: Uppercase and lowercase letters
[:d igit:]: Number
[: Alnum:]: Numbers and uppercase and lowercase letters

# Man 7 Glob
[^]: matches any single character outside the specified range


[[: Alpha:]]*[[:space:]]*[^[:alpha:]]


Practice:
1, create A123, Cd6, c78m, C1 My, m.z, K, 8yu, 789 and other documents; Note that the above files are separated by commas, and the other symbols are part of the file name;
2. Display all files beginning with a or m;
LS [am]*
3. Display all files containing numbers in the file name;
LS *[0-9]*
LS *[[:d igit:]]*
4. Display all files that end with a number and do not contain a blank in the file name;
LS *[^[:space:]]*[0-9]?????????
5. display files with special symbols of non-letters or numbers in the file name;
LS *[^[:alnum:]]*


Linux common Commands-command line editing, history, command line shortcut keys, Pstree,alias, command substitution, wildcard characters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.