Introduction to Linux Commands

Source: Internet
Author: User
Tags aliases builtin

Linux learning a heavy task, for beginners, see more like the stars of the command, let people shy, then say the Linux command some introductory learning, I hope I can give the people to see Help.
I think the learning of Linux commands is divided into the following three aspects, command format, classification and execution process, and finally, it is important to learn how to learn to use a just understand the command.
One: The format of the command:
Format: Command options (long option short option) parameters (e.g. filename path user, etc.)
For example:
(1, multiple options, or multiple parameters separated by a white space character
[Email protected] ~]# ls-a-l/home
Total 4
Drwxr-xr-x. 3 root root 8 16:16.
Dr-xr-xr-x. Root root 235 Nov 8 16:16.
DRWX------. Wang Wang 4096 Nov 8 16:30 Wang
[Email protected] ~]#

[email protected] ~]# Touch a.txt b.txt
[[email protected] ~]# ls
Anaconda-ks.cfg b.txt Documents initial-setup-ks.cfg Pictures Templates
A.txt Desktop Downloads Music public Videos
[Email protected] ~]#

(2, a command is very long, can not be finished, you may add anti-slash (\), divided into multiple lines to write
[Email protected] ~]# shutdown-h \
> 18:30 \
> ' system would be!!! '
Shutdown scheduled for Fri 2017-11-10 18:30:00 CST, use ' shutdown-c ' to cancel.
[Email protected] ~]#

Note: A single command directly followed by a backslash, if it is a command with options and parameters, keep each line at the end of a space, followed by a backslash
(3, multiple commands are executed together, can be separated by semicolons (;)

[Email protected] ~]# cat/etc/issue;ls;pwd
Users is \u
Tty is \l
Time is \ t
Date is \d
Hostname is \ n
\s
Kernel \ r on an \m
Anaconda-ks.cfg b.txt Documents initial-setup-ks.cfg Pictures Templates
A.txt Desktop Downloads Music public Videos
/root
[Email protected] ~]#

(4, Cancel or end command CTRL + C (forced exit) or Ctrl+d (normal exit)
[[email protected] ~]# sleep 1000
^c
[Email protected] ~]#

II: Classification of the Order:

(1 internal command: Built in the shell, resident memory, can be used at any time, execution speed very fast
(2 external command: All in the form of a file, is a separate executable file, stored on the disk

How do you know if it is an internal command or an external command?
Usage: #type followed by command to view the given instruction as "external instruction", "command alias" or "Internal instruction"
-A heel command displays information for a given instruction, including command aliases, in the path specified by the environment variable "path"

For example: What is the command to view Cat and CD, ls?
[[Email protected] ~]# type cat
Cat Is/usr/bin/cat//have path display, represented as external command
[[Email protected] ~]# type cd
CD is a shell builtin//display shell builtin, indicating internal command
[Email protected] ~]#
[[Email protected] ~]# type ls
LS is aliased to ' ls--color=auto '//display alias, represented as command alias
[Email protected] ~]#

Note: Some commands are internal commands, and external commands have
For example:
[Email protected] ~]# type-a Echo
Echo is a shell builtin
Echo Is/usr/bin/echo
[Email protected] ~]#

It also explains why some internal commands are missing or can be executed.

About enabling and disabling internal commands
Usage: Enable lists the internal commands that have been opened
followed by command enable command
-N followed by command disable command
-N View Disabled commands

Example:
To view the internal commands that are enabled:
[Email protected] ~]# enable-a
Enable.
Enable:
Enable [
Enable Alias
....................
Enable unset
Enable wait
[Email protected] ~]#

To disable internal commands:
>[[email protected] ~]# enable-n pwd
[Email protected] ~]#

To view the commands that are disabled:
>[[email protected] ~]# Help
GNU Bash, version 4.2.46 (2)-release (X86_64-REDHAT-LINUX-GNU)
These shell commands is defined internally. Type ' help ' to see the This list.
Type ' help-name ' to-find out more about the function ' name '.
Use ' Info Bash ' to find out more about the shell in general.
Use the ' man-k ' or ' info ' to the Find out more about the commands not in the this list.
A Star (*) next to a name means, the command is disabled.
Job_spec [&] history [-c] [-D offset] [n] or history-anr>
((expression)) if COMMANDS; Then COMMANDS; [Elif commands;>
. filename [arguments] jobs [-LNPRS] [jobspec ...] or jobs-x comma>
: Kill [-S Sigspec |-n signum |-sigspec] Pid>
[Arg ...] Let Arg [arg ...]
[[expression]] local [option] name[=value] ...
Builtin [Shell-builtin [arg ...]] pushd [-n] [+n |-n | dir]
caller [expr] *pwd [-LP]
...
hash [-LR] [-P pathname] [-DT] [name ...] while COMMANDS; Do COMMANDS; Done
Help [-DMS] [pattern ...] {COMMANDS;}
[Email protected] ~]#

The command is preceded by an asterisk, which indicates that it is disabled, and can be checked using the Enable command
[Email protected] ~]# enable-n
Enable-n pwd
[Email protected] ~]#

About alias command aliases use:
Usage: #alias command a= "BBB CCC" to define ' BBB CCC ' command alias for command a
#unalias command A To cancel alias command a
Above is only temporary, shutdown failure
#alias View all aliases that are already available
For example:
[[email protected] ~]# alias
Alias cp= ' Cp-i '
................................
Alias rm= ' Rm-i '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '
[Email protected] ~]#

Note: 1, in some cases the alias does not want to cancel, but also want to use the original command within the definition, add single quotation marks on the original command
Example: Define #alias ifconfig= "Ifconfig ens33"
If you want to use the ifconfig original command, do not cancel the definition alias, you can do this by adding single quotation marks # ' ifconfig '
2, the above operation restart or logoff will be lost
Do not lose, need to write files, files in home directory
/home/user/.BASHRC is only valid for the current user of the system
/ETC/BASHRC effective for all users of the system

At this point, for the newly modified configuration file, want it to take effect and do not want to restart, you can do the following
Soure file names make the modified files effective immediately
3, alias priority is greater than internal command, internal command priority is greater than external command

Three: The execution process of the command:
The system first determines whether an internal or external command is executed directly----is an internal command; is an external command, the hash cache table lookup----Cache table cannot find the Go Path variable path lookup---is not found, the command does not exist

Use of the command hash cache table:
Usage:
Hash display current system command cache table
-l Display Cache table details
-d command clears the specified command cache
-R clears all hash caches
For example:
[[email protected] ~]# hash
Hitscommand
1/usr/bin/pwd
2/usr/sbin/service
2/usr/bin/cat
1/usr/bin/touch
1/usr/bin/sleep
4/usr/sbin/shutdown
12/usr/bin/ls
[Email protected] ~]# hash-l
Builtin Hash-p/usr/bin/pwd pwd
Builtin hash-p/usr/sbin/service Service
Builtin Hash-p/usr/bin/cat Cat
Builtin Hash-p/usr/bin/touch Touch
Builtin hash-p/usr/bin/sleep Sleep
Builtin Hash-p/usr/sbin/shutdown shutdown
Builtin hash-p/usr/bin/ls ls
[Email protected] ~]#

About environment variable paths:
Echo $PATH See all the environment variables
[Email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[Email protected] ~]#

When the command is not an internal command, the hash table is not found, it will be in the path path from left to right in order to find

Tip: Whichcmd View the environment variable path for a command
-A cmd view command all existing paths

[[email protected] ~]# which-a ls
Alias ls= ' ls--color=auto '
/usr/bin/ls
[Email protected] ~]#

Four: Help for the command:
Help Mans Info
A lot of orders, people can not remember, or learn to check the command to help, learn to teach themselves.
Usage:
Command--help View command Help
Help command to view internal command assistance
Man command to view external command help
Man a command into the detail page, the space to the rear of the screen, B to the first flip screen
D turn half screen to tail, u turn half screen
Q Exit the information page.
/keyword in the current position, to the tail search for the keyword to find n Next, N prev
? Keyword with current position, want to search for the first keyword n Next, n previous
Notice that there is a date number in the middle, indicating that the last page is

Info command to view detailed command help
The Whatis whatis command displays the header line of the manual section. You can then issue the man command to get additional information. The Whatis command is equivalent to using the MAN-F command
If not, execute the command: #makewhatiscentos6的开启
# Mandb Centos7 's Open
For example:
[email protected] ~]# cat--help
Usage:cat [OPTION] ... [FILE] ...
Concatenate FILE (s), or standard input, to standard output.
-A,--show-all equivalent To-vet
-B,--number-nonblank number nonempty output lines, overrides-n
-e equivalent To-ve
-E,--show-ends display $ at end
-N,--number number all output lines
-S,--squeeze-blank suppress repeated empty output lines
-T equivalent TO-VT
-T,--show-tabs display TAB characters as ^i
-U (ignored)
-V,--show-nonprinting use ^ and m-notation, except for LFD and TAB
--help Display this Help and exit
--version output version information and exit
With no file, or if file is-, read standard input.
Examples:
Cat f-g Output F ' s contents, then standard input, then G ' s contents.
Cat Copy standard input to standard output.
GNU coreutils online Help: For complete documentation, Run:info coreutils ' cat invocation '
[Email protected] ~]#

[email protected] ~]# Man Cat | More
Cat (1) User Commands Cat (1)
NAME
cat-concatenate files and print on the standard output
Synopsis
Cat [OPTION] ... [FILE] ...
DESCRIPTION
Concatenate FILE (s), or standard input, to standard output.
-A,--show-all
Equivalent To-vet
-B,--number-nonblank
Number nonempty output lines, overrides-n
-e equivalent To-ve
-E,--show-ends
Display $ at end of each line
-N,--number
Number all output lines
-S,--squeeze-blank
Suppress repeated empty output lines
-T equivalent TO-VT
-T,--show-tabs
Display TAB characters as ^i
-U (ignored)
-V,--show-nonprinting
Use ^ and m-notation, except for LFD and TAB
--help Display this Help and exit
--version
Output version information and exit
With no file, or if file is-, read standard input.
EXAMPLES
Cat F-g
Output F ' s contents, then standard input, then G ' s contents.
Cat Copy standard input to standard output.
GNU coreutils online Help: Lation Bugs to AUTHOR
Written by Torbjorn Granlund and Richard M. Stallman.
COPYRIGHT
Copyright? Free Software Foundation, Inc. License gplv3+: GNU GPL version 3 or
Later This was free software:you was free to change and redistribute it. There is NO war‐
Ranty, to the extent permitted.
See ALSO
TAC (1)
The full documentation-CAT is maintained as a Texinfo manual. If the info and cat
Programs is properly installed at your site, the command
Info coreutils ' Cat invocation '
Should give you access to the complete manual.
GNU coreutils 8.22 November CAT (1)
[Email protected] ~]#

[Email protected] ~]# Whatis cat
Cat (1)-Concatenate files and print on the standard output
Cat (1p)-Concatenate and print files
[Email protected] ~]#

Introduction to Linux Commands

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.