Common Linux commands (8)-bash application skills

Source: Internet
Author: User
Tags touch command

View existing shell of the system

 
[Root @ localhost ~]#CAT/etc/shells/Bin/Sh/Bin/Bash/Sbin/Nologin/Bin/Tcsh/Bin/CSH [root@ Localhost ~]# 

 

Common shortcut keys in Bash:

CTRL + l clear screen, crtl + u delete all content before the command line cursor

1. Command completion

Command to allow the user to enter several letters starting from the file, press<Tab>Key to fill in the file name

This is useful when installing the software package, because the command of the software package in Linux is very long, and it is easy to make mistakes by letter.

2. Command history

Command history allows you to browse previously entered commands and call them again.HistoryCommand to display the list of used commands, press the direction keyBytesAndBytesYou can find commands previously executed

[Root @ localhost ABC]#History1005 Ping-s 1024 192.168.1.1 1006 Ping-C 4-s 1024 192.168.1.1 1007 Ping-s 60000000 192.168.1.1 1008Clear1009Ifconfig1010Clear1011History1012Clear1013 CAT/etc/Shells1014CD bac1015 CD/ABC1016Ls1017History [root@ Localhost ABC]# 

Use! + The serial number before the command can call the corresponding command

[Root @ localhost ABC]#! 1016Lsadir afile afile.zip issue. Soft test test.zipadir.tar afile.bz2 issue. Hard Prem test.tar.gz [root@ Localhost ABC]# 

 

3. Command alias

Example: when using alias copy = CP, you can use copy instead of CP.

Alias DRM = "RM-RF" command combination, which must be enclosed in double quotation marks

View alias information: alias

Delete alias: unalias copy

 View the system alias [root @ Localhost ~]#  Alias Alias CP = 'cp- I 'Alias L. = 'LS-D. * -- color = Auto 'Alias LL = 'LS-l -- color = Auto 'Alias ls = 'Ls -- color = Auto 'Alias mv = 'Mv- I 'alias RM = 'Rm- I 'Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show- Tilde '[root @ Localhost ~] #   Define the alias DRM = " Rm-RF  "  [Root @ Localhost ~] #  Alias DRM = "RM-RF"  Use an alias to delete the test directory [root @ Localhost ~] #  DRM Test  Delete the alias DRM [root @ Localhost ~] #  Unalias DRM 

 

4. Input/Output redirection

Shell pre-defines three file descriptors (0, 1, and 2) for each process, respectively, which correspond:

0 (stdin) Standard Input

1 (stdout) standard output

2 (stderr) standard error output

1)> or> output redirection

Example: ls-L/tmp>/tmp. msg

Date>/tmp. msg

Output redirection, LS-L/ The result of the TMP command is not displayed on the screen, but output to the TMP. MSG file [root @ Localhost ~] #  Ls-L/tmp>/tmp. msg  Let's check the content in the TMP. MSG file [root @ Localhost ~] #  CAT/tmp. msg Total 100 Drwx ------. 2 luxh 4096 Nov 14 keyring- H3yh6mdrwx ------. 2 luxh 4096 Nov 22 05:09 keyring- Ysf-kwldrwx ------. 2 gestational disease 4096 Nov 22 orbit- Gdmdrwx ------. 2 luxh 4096 Nov 22 05:09 orbit- Luxhdrwx ------. 2 gestational disease 4096 Nov 22 05:09 pulse- 84 tzflbulwkgdrwx ------. 2 luxh 4096 Nov 22 05:09 pulse- Ijt6umdvv23edrwx ------. 2 root Root 4096 May 16 2012 pulse- Ztoqiktvdyh9drwx ------. 2 luxh 4096 Nov 22 05:09 virtual-Luxh.2mu7zxdrwx ------. 2 luxh 4096 Nov 13 06:16 virtual- Luxh. deg7dtdrwx ------. 2 luxh 4096 Nov 20 04: 29 virtual- Luxh. ekfxnydrwx ------. 2 luxh 4096 Nov 16 virtual 16 virtual- Luxh. q0xcv9drwx ------. 2 luxh 4096 Nov 15 virtual- Luxh. uib40ldrwx ------. 2 luxh 4096 Nov 21 05:07 virtual- Luxh. yq7gzgdrwx ------. 2 luxh 4096 Nov 14 04:45 virtual- Luxh. zu4sqydrwxrwxrwt. 2 root Root 4096 Nov 15 Vmwarednddrwx ------. 2 luxh 4096 Nov 22 05:09 vmware- Luxhdrwx ------. 2 root Root 36864 Nov 22 05:07 vmware- Root [root @ Localhost ~] #  

 

 Append the result of the date command to TMP. MSG [root @ Localhost ~] #  Date>/tmp. msg [Root @ localhost ~] #  CAT/tmp. msg Total 100 Drwx ------. 2 luxh 4096 Nov 14 keyring- H3yh6mdrwx ------. 2 luxh 4096 Nov 22 05:09 keyring-Ysf-kwldrwx ------. 2 gestational disease 4096 Nov 22 orbit- Gdmdrwx ------. 2 luxh 4096 Nov 22 05:09 orbit- Luxhdrwx ------. 2 gestational disease 4096 Nov 22 05:09 pulse- 84 tzflbulwkgdrwx ------. 2 luxh 4096 Nov 22 05:09 pulse- Ijt6umdvv23edrwx ------. 2 root Root 4096 May 16 2012 pulse- Ztoqiktvdyh9drwx ------. 2 luxh 4096 Nov 22 05:09 virtual- Luxh.2mu7zxdrwx ------. 2 luxh 4096 Nov 13 06:16 virtual- Luxh. deg7dtdrwx ------. 2 luxh 4096 Nov 20 04: 29 virtual-Luxh. ekfxnydrwx ------. 2 luxh 4096 Nov 16 virtual 16 virtual- Luxh. q0xcv9drwx ------. 2 luxh 4096 Nov 15 virtual- Luxh. uib40ldrwx ------. 2 luxh 4096 Nov 21 05:07 virtual- Luxh. yq7gzgdrwx ------. 2 luxh 4096 Nov 14 04:45 virtual- Luxh. zu4sqydrwxrwxrwt. 2 root Root 4096 Nov 15 Vmwarednddrwx ------. 2 luxh 4096 Nov 22 05:09 vmware- Luxhdrwx ------. 2 root Root 36864 Nov 22 05:07 vmware- Rootthu Nov 22 06:59:05 PST 2012[Root @ Localhost ~] # 

2) <input redirection

Example: Wall <user.info

 
[Root @ localhost ~]#Cat user.infoAmani1: 1001: 503:/home/amani1:/bin/Bash amani2: 1002: 503:/home/amani2:/bin/Bash broadcasts the content in the user.info file as input [root@ Localhost ~]#Wall <user.info[Root @ localhost ~]#Broadcast message from root@localhost.localdomain (Thu Nov 22 07:07:56 2012): Amani1: 1001: 503:/home/amani1:/bin/Bash amani2: 1002: 503:/home/amani2:/bin/bash

3) 2> error output redirection

Example: CP-r/usr/backup/usr. Bak 2>/bak. Error backup/usr directory. If an error occurs, output the error message to Bak. Error.

 
To view a non-existent directory, an error message [root@ Localhost ~]#Ls/AAAALs: cannot access/Aaaa: no such file or directory redirects the error message to the LS. Err file [root@ Localhost ~]#Ls/AAAA 2> ls. Err[Root @ localhost ~]#Cat ls. ErrLs: cannot access/Aaaa: no such file or directory [root@ Localhost ~]#

 

5. Pipelines

Send the output of one command to another as the input of another command.

Usage:

Command 1 | command 2 | command 3 | ...... | command n

For example:

Ls-L/etc | more

Ls-L/etc | grep init

Ls-L/etc | grep init | WC-l

Convert LS-L/ The content output by the ETC command is sent to the more command for pagination [root @ Localhost ~] #  Ls-L/etc | more Total 1720 Drwxr -XR-X. 3 Root 4096 May 6 2012 Abrtdrwxr -XR-X. 4 Root 4096 May 6 2012 ACPI -RW-r --. 1 Root 45 Nov 22 08:19 Adjtime -RW-r --. 1 Root 1512 Jan 12 2010 Aliases -RW-r --. 1 Root 12288 May 6 2012 Aliases. dbdrwxr -XR-X. 2 root Root 4096 May 6 2012 Alsadrwxr -XR-X. 2 root Root 4096 May 6 2012 Alternatives -RW-r --. 1 Root 541 Jul 18 2011. Anacrontab -RW-r --. 1 Root 148 May 14 2009 Asound. conf -RW-r --. 1 Root 1 Jun 24 24 2011 At. denydrwxr -X ---. 3 Root 4096 May 6 2012 Audispdrwxr -X ---. 2 root Root 4096 May 6 2012 Auditdrwxr -XR-X. 4 Root 4096 May 6 2012 Avahidrwxr -XR-X. 2 root Root 4096 May 6 2012 Bash_completion.d -RW-r --. 1 Root 2681 Sep 23 2011 Bashrcdrwxr -XR-X. 2 root Root 4096 dec 7 2011 Blkiddrwxr -XR-X. 2 root Root 4096 May 6 2012 Descrithdrwxr -XR-X. 2 root Root 4096 May 6 2012 bonobo- Activation -RW-r --. 1 Root 27 Dec 8 2011 centos- Releasedrwxr -XR-X. 2 root Root 4096 Nov 10 2010 Chkconfig. ddrwxr -XR-X. 5 root Root 4096 May 6 2012 Consolekitdrwxr -XR-X. 2 root Root 4096 May 6 2012 Cron. d -- More -- Set ls -L/ The content output by the ETC command is sent to the grep command to find the line containing init [root @ Localhost ~] # Ls-L/etc | grep init Drwxr-XR-X. 2 root Root 4096 May 6 2012 Initlrwxrwxrwx. 1 Root 11 May 6 2012 init. d-> rc. d/ Init. d -RW-r --. 1 Root 884 May 5 2012 Inittablrwxrwxrwx. 1 Root 15 May 6 2012 RC. sysinit-> rc. d/ RC. sysinit [root @ Localhost ~] #   Set ls -L/ The content output by the ETC command is sent to the grep command to find the line containing init, and then the content output by the grep command is sent to the WC - L command to count the number of rows [root @ Localhost ~]#  Ls-L/etc | grep init | WC-l 4 [Root @ Localhost ~] #  

 

6. Command Connector

1); Use; run the commands at intervals in sequence

For example, to display the current directory, then display the files in the current directory, and finally display the system time [root@ Localhost ~]#PWD; LS; Date/Root2012Documents music templatesa B downloads pictures testabc install. Log public user. infoanaconda-Ks. cfg install. log. syssyslog sudo-1.8. 4p4 videosdesktop ls. Err sudo-1.8.4p4.tar.gz Fri Nov23 05:34:04 PST 2012[Root@ Localhost ~]#

 

2) & There is a logic and relationship between the execution of commands before and after the command. Only after the successful execution of the command before and after it is executed will the command be executed

For example, if you send a love letter to Lily, the [root @ Localhost ~] #  Write lily </root/love.txt & RM/root/love.txt  Run the LS command first, and then run PWD [root @ Localhost ~] #  Ls & pwd 2012 Documents music templatesa B downloads pictures testabc install. Log public user. infoanaconda -Ks. cfg install. log. syssyslog sudo-1.8 . 4p4 videosdesktop ls. Err sudo -1.8.4p4.tar.gz / Root [root @ Localhost ~] #   Execute the La command first. Because there is no la command, an error will be executed, and the following PWD command will not execute [root @ Localhost ~] #  La & pwd  Bash: La: Command not found [root @ Localhost ~] #  

 

3) | the execution of commands before and after has a logic or relationship. Only | the execution of commands after a previous command fails.

Run the LS command first. If the command is successfully executed, the following PWD command will not execute [root@ Localhost ~]#Ls | pwd2012Documents music templatesa B downloads pictures testabc install. Log public user. infoanaconda-Ks. cfg install. log. syssyslog sudo-1.8. 4p4 videosdesktop ls. Err sudo-1.8.4p4.tar.gz execute the La command first. Because there is no la command, an error will be executed, and the following PWD command will execute [root@ Localhost ~]#La | pwdBash: La: Command not found/Root [root@ Localhost ~]#

 

7. Command replacement character

Use the output of one command as the parameter of another command

Format: command 1 'COMMAND 2' is the marker on the left of number 1 on the keyboard

For example, LS-l 'which Touch'

 
The which touch command output is used as the LS-l parameter.
[Root @ localhost ~]#Ls-l 'which Touch'-Rwxr-XR-X. 1 Root 50644 dec 7 2011/bin/Touch [root@ Localhost ~]#

 

 

 

 

 

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.