First glance at Linuxshell tools

Source: Internet
Author: User
I. common shell tools linux shell tools are divided into two types: Image interface shell (GUI) and command line form (CLI. GUI tools include Xwindowmanger, CDE, GNOME, KDE, and XFCE2.CLI tools including bsh, csh, tcsh, ksh, bash, and zsh. Bash is the default shell tool for most popular Linux distributions. 2. bash command prompt 1. when you log on
I. common shell tools linux shell tools are divided into two types: Image interface shell (GUI) and command line form (CLI. GUI tools include X window manger, CDE, GNOME, KDE, and XFCE2.CLI tools including bsh, csh, tcsh, ksh, bash, and zsh. Bash is the default shell tool for most popular Linux distributions today. 2. bash command prompt 1. after logging on to bash, you will see some prompts on the left side of the command line, such as [root @ centos6 ~]. #; The content in the command prompt in the example represents root: currently logged-in user centos6: Computer Name ~: Current directory (~ Represents the user's home directory in linux) #: represents the current login user level (# represents the root user, $ represents other users except the root user) 2. you can change the command prompt through the variable $ PS1. you can enter echo $ PS1 in the command to view the current settings, as shown below: [root @ centos6 ~] # Echo $ PS1 [\ u @ \ h \ W] \ $ reset the command prompt format: [root @ centos6 ~] # PS1 = "[\ u @ \ h \ W] \ $" [\ u @ \ h \ W] \ $ \ u represents the current login user; \ h indicates the current host name; \ W indicates the current directory; \ $ indicates the current login user level. Other characters have no special meaning and only indicate the meaning of the characters. Common symbols in the command prompt ($ PS1 environment variable): \ d: represents the date, in the format of weekday month date \ H: Wang Zheng's host name \ h: obtain only the first host name \ t: The display time is in the 24-hour format, for example, HH: MM: SS \ T: The display time is in the 12-hour format \: the display time is in the 24-hour format: HH: MM \ u: current account name \ v: BASH version \ w: complete working directory name ~ Replace \ W: use basename to get the name of the working directory. Therefore, only the last directory \ #: issued command \ $: prompt is displayed. if it is root, the prompt is #, common users are $3 and bash commands. builtin: the commands implemented in shell programs are built-in commands. external commands: in a file system, an executable file corresponding to the command name is located at a certain location. you can use the command type to determine the command type. shell sets multiple paths through PATH in advance, when you enter a command, shell will automatically go to these paths (from left to right) to view executable files with the same command name, commands that have been found and executed are saved to a hash query table. you can use the hash command to view the table. You can use the which command to view the specific path of an executable program.
[root@centos6 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin[root@centos6 ~]# hashhitscommand   1/bin/grep   1/usr/bin/man   2/usr/bin/info   1/bin/ls[root@centos6 ~]# which lsalias ls='ls --color=auto'/bin/ls
4. in Linux, a command is usually composed of three parts: command name, command option, and command parameter, the command is separated by blank characters such as blank separators or tabs in the middle. the command options arguments command option parameters generally start with a single character starting with the minus sign, different from the UNIX system, the Linux system also provides command options marked with the double minus sign "--" as the starting marker (called the GUN option ), the option is generally a single English word understood literally, or a phrase consisting of words and hyphens. Except for some command options (such as "-- help"), the options marked with double minus signs "--" are mostly synonyms of single-character command options, which share the same meaning on the right, therefore, it can be replaced. In the command line structure, only the command name is required. command options and command parameters can be omitted. a simplest command can only contain the command name, in this case, the default value is used for both command options and parameters.
[Root @ centos6 ~] # Date Tuesday, September 16, 2014 07:29:12 CST
In actual application, you can select or omit command options as needed, and the command options and parameters can be combined with the command name in any form. For example, the following command only consists of a command and a command option "-n". The omitted command parameter is used to list the system name.
[root@centos6 ~]# uname -ncentos6.5_X64
The following commands are composed of command names and command parameters, while the command options are omitted. they are used to list files in a specified directory in the form of simple output.
[root@centos6 ~]# ls /bin   etc   lib64       mnt   root     srv  usrboot  home  lost+found  opt   sbin     sys  vardev   lib   media       proc  selinux  tmp
You can merge or separate multiple options of a single character starting with "-" (the options starting with "--" cannot be merged together)
[Root @ centos6 opt] # total ls-la/opt usage: 24drwxr-xr-x. 3 root 4096 September 23 2011. dr-xr-x. 22 root 4096 September 15 17:05 .. drwx ------. 2 root 16384 17:34 lost + found [root @ centos6 opt] # ls-l-a/opt total usage 24drwxr-xr-x. 3 root 4096 September 23 2011. dr-xr-x. 22 root 4096 September 15 17:05 .. drwx ------. 2 root 16384 September 13 17:34 lost + found
The command option mainly limits the specific functions of the command, and also determines the final running result of the command. in Linux, each command usually provides a large number of options, so the right-side function is rich. Options can be provided separately or in combination. If the option itself has parameters, such options and their parameters must be listed separately. In the following sorting commands, parameters are required because command options such as "-k" and "-o ",
[Root @ centos6/] # ls-al | sort-k 5-n-o/root/test [root @ centos6/] # cat/root/testdrwxr-xr-x. 13 root 0 September 15 17:05 sysdrwxr-xr-x. 7 root 0 September 15 17:05 selinuxdr-xr-x. 114 root 0 September 15 17:05 proc-rw-r --. 1 root 0 September 15 17:05. total autofsck usage 98dr-xr-xr-x. 5 root 1024 September 13 19:51 bootdrwxr-xr-x. 16 root 3640 September 15 17:05 devdrwxrwxrwt. 4 root 4096 September 16 07:35 tmpdrwxr-xr-x. 14 root 4096 September 13 17:35 usrdrwxr-xr-x. 18 root 4096 September 13 19:08 vardrwxr-xr-x. 2 root 4096 September 23 2011 mediadrwxr-xr-x. 2 root 4096 September 23 2011 mntdrwxr-xr-x. 2 root 4096 September 23 2011 srvdrwxr-xr-x. 3 root 4096 September 23 2011 homedrwxr-xr-x. 3 root 4096 September 23 2011 optdrwxr-xr-x. 74 root 4096 17:05 September 15 etcdr-xr-x ---. 6 root 4096 September 16 09:25 rootdr-xr-x. 22. root 4096 09:25, January 1, September 16. dr-xr-x. 22 root 4096 September 16 09:25 .. dr-xr-x. 2 root 4096 September 13 19:49 bindr-xr-x. 8 root 4096 September 13 17:35 libdr-xr-x. 2 root 12288 September 13 19:50 sbindr-xr-x. 9 root 12288 September 13 19:49 lib64drwx ------. 2 root 16384 September 13 17:34 lost + found
5 in "-k 5" is the parameter of "-k", which indicates sorting with 5th fields as keywords. The "-n" option indicates sorting by numerical values. In "-o/root/test", de/root/test is also the option-o parameter, indicating to store the final sorting result output file. In a Linux command prompt, only one command is usually input at a time. If you want to, you can enter multiple commands at a time and separate them with semicolons. You can also use parentheses to combine several commands to form a combined command.
[Root @ centos6/] # date; who September 16, 2014 09:34:44 CSTroot tty1 21: 54 root pts/0 (192.168.0.56) root pts/1 (192.168.0.56) [root @ centos6/] # (date; who) 09:34:50 CSTroot tty1 September 16, 2014 21: 54 root pts/0 (192.168.0.56) root pts/1 (192.168.0.56)
In addition to brackets, the two commands have the same form, and sometimes the effect is the same, but the meaning of the two commands is quite different. The first command form only inputs multiple commands concurrently on a logical line. The Effects of inputting one command at a time are basically the same, and they are all run in the current shell. The second command form is to regard multiple commands as a combined command. when running in a sub-shell, the output data of all commands will be merged into an output stream, the difference is particularly obvious in pipeline operations (two forms of difference can be compared by calculating the number of read rows through wc ).
[Root @ centos6/] # date; who | wc-l Tuesday, September 16, 2014 10:17:04 CST3 [root @ centos6/] # (date; who) | wc-l4
If the command is longer than Kandu of a physical line, you can use the backslash "\" to write it to a physical line. You can also continue the input and the system automatically extends to the subsequent rows. As mentioned above, many GNU applications support the option starting. These options are either an alternative form of the original single minus sign "-" option, or an extension of the command function. For example, the double minus sign option corresponding to the "-k" option of the sort command is "-- key ". If the GNU command is used, you can rewrite the preceding sort command as follows:
[root@centos6 /]# ls -al|sort --key 5 -n -o /root/test

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.