Common Linux commands (8) -- bash application skills

Source: Internet
Author: User

Common Linux commands (8) -- bash application skills view existing shell www.2cto.com [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 at the beginning of the file, press the <Tab> key to fill in the file name, which is very useful when installing the software package. Because the command of the software package in linux is very long, it is easy to make mistakes by typing letters, it is also troublesome for www.2cto.com 2. The command history allows users to browse previously entered commands and call them again. The history command can display the list of used commands, run the [root @ localhost abc] # history 1005 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 1008 clear 1009 ifconfig 1010 clear 1011 histo Ry 1012 clear 1013 cat/etc/shells 1014 cd bac 1015 cd/abc 1016 ls 1017 history [root @ localhost abc] # use! + The serial number before the command can call the corresponding Command [root @ localhost abc] #! 1016 lsadir 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 to replace the combination of cp alias drm = "rm-rf" commands. You need to enclose it in double quotation marks to view the alias information: alias Delete the alias: unalias copy: view the system alias [root @ localhost ~] # Aliasalias 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 the 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, at a lower level than: 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. The results of the ls-l/tmp command are not displayed on the screen, but output to tmp. [root @ localhost ~] In the msg File # Ls-l/tmp>/tmp. msg let's check the content in the tmp. msg file [root @ localhost ~] # Cat/tmp. msgtotal 100drwx ------. 2 luxh 4096 Nov 14 04:42 keyring-h3yH6mdrwx ------. 2 luxh 4096 Nov 22 keyring-YG0Kwldrwx ------. 2 gestational disease 4096 Nov 22 orbit-gdmdrwx ------. 2 luxh 4096 Nov 22 05:09 orbit-luxhdrwx ------. 2 gestational disease 4096 Nov 22 pulse-84tzFLbuLWkGdrwx ------. 2 luxh 4096 Nov 22 pulse-Ijt6UMdvv23Edrwx ------. 2 root 4096 May 16 2012 pulse- ZtOQIKtvdyh9drwx ------. 2 luxh 4096 Nov 22 virtual-luxh.2MU7ZXdrwx ------. 2 luxh 4096 Nov 13 virtual-luxh.DEg7dTdrwx ------. 2 luxh 4096 Nov 20 04:29 virtual-luxh.eKfxnYdrwx ------. 2 luxh 4096 Nov 16 virtual-luxh.q0XCV9drwx ------. 2 luxh 4096 Nov 15 virtual-luxh.Uib40ldrwx ------. 2 luxh 4096 Nov 21 virtual-luxh.yq7GZgdrwx ------. 2 luxh lux H 4096 Nov 14 virtual-luxh.zu4sqydrwxrwxrwt. 2 root 4096 Nov 15 VMwareDnDdrwx ------. 2 luxh 4096 Nov 22 05:09 vmware-luxhdrwx ------. 2 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. msgtotal 100drwx ------. 2 luxh 4096 Nov 14 04:42 keyring-h3yH6mdrwx ------. 2 luxh 4096 Nov 22 keyring-YG0Kwldrwx ------. 2 gestational disease 4096 Nov 22 orbit-gdmdrwx ------. 2 luxh 4096 Nov 22 05:09 orbit-luxhdrwx ------. 2 gestational disease 4096 Nov 22 pulse-84tzFLbuLWkGdrwx ------. 2 luxh 4096 Nov 22 pulse-Ijt6UMdvv23Edrwx ------. 2 root 4096 May 16 2012 pulse- ZtOQIKtvdyh9drwx ------. 2 luxh 4096 Nov 22 virtual-luxh.2MU7ZXdrwx ------. 2 luxh 4096 Nov 13 virtual-luxh.DEg7dTdrwx ------. 2 luxh 4096 Nov 20 04:29 virtual-luxh.eKfxnYdrwx ------. 2 luxh 4096 Nov 16 virtual-luxh.q0XCV9drwx ------. 2 luxh 4096 Nov 15 virtual-luxh.Uib40ldrwx ------. 2 luxh 4096 Nov 21 virtual-luxh.yq7GZgdrwx ------. 2 luxh lux H 4096 Nov 14 virtual-luxh.zu4sqydrwxrwxrwt. 2 root 4096 Nov 15 VMwareDnDdrwx ------. 2 luxh 4096 Nov 22 05:09 vmware-luxhdrwx ------. 2 root 36864 Nov 22 06:59:05 vmware-rootThu Nov 22 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 user.info as input [root @ localhost ~] # Wall <user.info [root @ localhost ~] # Broadcast message from root@localhost.localdomain (Thu Nov 22 07:07:56 2012): amani1: 1001:/home/amani1:/bin/bash amani2: 503: 1002 :: /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 information to bak. error to view a directory that does not exist. The error message [root @ localhost ~] will be displayed on the screen. # 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. The pipeline sends 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 | wc-l: Pass the content output by the ls-l/etc command to the more command. browse by PAGE [root @ localhost ~] # Ls-l/etc | moretotal 1720drwxr-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 4096 May 6 2012 alsadrwxr-xr-x. 2 root 4096 May 6 2012 alternatives-rw-r --. 1 root 541 Jul 2011 Acrontab-rw-r --. 1 root 148 May 14 2009 asound. conf-rw-r --. 1 root 1 Jun 24 2011. denydrwxr-x ---. 3 root 4096 May 6 2012 audispdrwxr-x ---. 2 root 4096 May 6 2012 auditdrwxr-xr-x. 4 root 4096 May 6 2012 avahidrwxr-xr-x. 2 root 4096 May 6 2012 bash_completion.d-rw-r -- r --. 1 root 2681 Sep 23 2011 bashrcdrwxr-xr-x. 2 root 4096 Dec 7 2011 blkiddrwxr-xr-x. 2 root 4096 May 6 2012 running thdrwxr-xr-x. 2 root 4096 May 6 2012 bonobo-activation-rw-r --. 1 root 27 Dec 8 2011 centos-releasedrwxr-xr-x. 2 root 4096 Nov 10 2010 chkconfig. ddrwxr-xr-x. 5 root 4096 May 6 2012 ConsoleKitdrwxr-xr-x. 2 root 4096 May 6 2012 cron. d -- More -- pass the content output by the ls-l/etc command to the grep command to find the line containing init [root @ localhost ~] # Ls-l/etc | grep initdrwxr-xr-x. 2 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 ~] # Pass the content output by the ls-l/etc command to the grep command to find the line containing init, then, send the grep command output content to the wc-l command to count the number of rows [root @ localhost ~] # Ls-l/etc | grep init | wc-l4 [root @ localhost ~] #6. Command connector 1); Use; the commands at intervals are executed sequentially. For example, the current directory is displayed, and then the files in the current directory are displayed, last display system time [root @ localhost ~] # Pwd; ls; date/root2012 Documents Music Templatesa B Downloads Pictures testabc install. log Public user. infoanaconda-ks.cfg install. log. syslog sudo-1.8.4p4 VideosDesktop ls. err sudo-1.8.4p4.tar.gzFri Nov 23 05:34:04 PST 2012 [root @ localhost ~] #2) & There is a logic and relationship between the execution of commands before and after. Only after the execution of the command before & is successful will the execution of the command after it be executed. For example, send a love letter to Lily, delete [root @ localhost ~] if the love letter is successfully sent. # Write Lily </root/love.txt & rm/root/love.txt run the ls command first, and then run pwd [root @ localhost ~] # Ls & pwd2012 administrative ents Music Templatesa B Downloads Pictures testabc install. log Public user. infoanaconda-ks.cfg install. log. syslog 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 & pwdbash: la: command not found [root @ localhost ~] #3) | the execution of commands before and after has a logic or relationship. Only | after the execution of the preceding command fails, the command after it is executed will execute the ls command first, and the execution is successful, the following pwd command will not execute [root @ localhost ~] # Ls | pwd2012 Documents Music Templatesa B Downloads Pictures testabc install. log Public user. infoanaconda-ks.cfg install. log. syslog sudo-1.8.4p4 VideosDesktop ls. err sudo-1.8.4p4.tar.gz first execute the la command, because there is no la command, it will execute the error, the following pwd command will execute [root @ localhost ~] # La | pwdbash: la: command not found/root [root @ localhost ~] #7. The command replacement operator uses the output of one command as the parameter format of another command: command 1 'COMMAND 2' is the marker on the left of number 1 on the keyboard, for example: the output of the ls-l 'which touch' which touch command 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.