Dialog UNIX: Learn More command line skills and operators

Source: Internet
Author: User
Article Title: Dialog UNIX: Learn More command line skills and operators. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Better understanding of UNIX? The "strange" characters entered by the user. Learn how to use pipelines, redirection, operators, and other features in UNIX.
Now you are at IBM? AIX? I have been working for a while. You have learned several basic commands to move, create, and modify files in the directory structure, view running processes, and manage users and systems. This is good, but do you want to know about UNIX? What does the command entered by the Administrator mean. These commands contain many strange symbols. In this article, we understand the symbols such as |,>,>, <, <, [and] in UNIX and Linux? And how to use &, ||,<,<=and! = Operator.

MPs queue

If you are familiar with UNIX, pipelines (or pipe) are something you need to access every day. The pipeline was initially developed by Malcolm McIlroy. You can use the pipeline to direct the standard output (stdout) of a command to the standard input (stdin) of the next command ), in this way, the command chain for continuous execution is formed. You can use multiple pipelines on one command line. In many cases, the stdout of a command is used as the stdin of the next command, and the stdout of the second command is redirected to the stdin of another command, and so on.

For example, when troubleshooting or performing routine checks, one of the first tasks that most UNIX administrators do is to view the processes currently running on the system. Listing 1 demonstrates this check.


Listing 1. Routine process check example

# Ps? Ef

UID PID PPID C STIME TTY TIME CMD
Root 1 0 0 Jul 27-0: 05/etc/init
Root 53442 151674 0 Jul 27-/usr/sbin/syslogd
Root 57426 1 0 Jul 27-0: 00/usr/lib/errdemon
Root 61510 1 0 Jul 27-23:55/usr/sbin/syncd 60
Root 65634 1 0 Jul 27-0: 00/usr/ccs/bin/shlap64
Root 82002 110652 0 Jul 27-/usr/lpp/X11/bin/X-x abx
-X dbe-x GLX-D/usr/lib/X11 // rgb-T-force: 0-auth/var/dt/A: 0-SfIdMa
Root 86102 1 0 Jul 27-0: 00/usr/lib/methods/ssa_daemon-l ssa0
Root 106538 151674 0 Jul 27-sendmail: accepting connections
Root 110652 1 0 Jul 27-0: 00/usr/dt/bin/dtlogin-daemon
Root 114754 118854 0 Jul 27-dtgreet
Root 118854 110652 0 Jul 27-dtlogin <: 0>-daemon
Root 131088 1 0 Jul 27-0:07/usr/atria/etc/lock
-A-A/var/adm/atria/almd-q 1024-u 256-f 256
Root 147584 1 0 Jul 27-0: 01/usr/sbin/cron
Root 155816 151674 0 Jul 27-/usr/sbin/portmap
Root 163968 151674 0 Jul 27-/usr/sbin/qdaemon
Root 168018 151674 0 Jul 27-/usr/sbin/inetd
Root 172116 151674 0 Jul 27-/usr/sbin/xntpd
Root 180314 151674 0 Jul 27-/usr/sbin/snmpmibd
Root 184414 151674 0 Jul 27-/usr/sbin/aixmibd
Root 188512 151674 0 Jul 27-/usr/sbin/hostmibd
Root 192608 151674 0 Jul 27-/usr/sbin/muxatmd
Root 196718 151674 0 11:00:27-/usr/sbin/rpc. mountd
Root 200818 151674 0 Jul 27-/usr/sbin/biod 6
Root 213108 151674 0 Jul 27-/usr/sbin/nfsd 3891
Root 221304 245894 0 Jul 27-/bin/nsrexmcm
Daemon 225402 151674 0 11:00:27-/usr/sbin/rpc. statd
Root 229498 151674 0 11:00:27-/usr/sbin/rpc. lockd
Root 241794 151674 0 Jul 27-/usr/lib/netsvc/yp/ypbind
Root 245894 1 0 Jul 27-/bin/nsrexmcm
Root 253960 1 0 Jul 27-./mflm_manager
Root 274568 151674 0 Jul 27-/usr/sbin/sshd-D
Root 282766 1 0 Jul 27 lft0 0 0: 00/usr/sbin/getty/dev/console
Root 290958 1 0 Jul 27-0: 00/usr/lpp/diagnostics/bin/diagd
Root 315646 151674 0 Jul 27-/usr/sbin/lpd
Root 319664 1 0 Jul 27-0: 00/usr/atria/etc/albd_server
Root 340144 168018 0 12:34:56-rpc. ttdbserver 100083 1
Root 376846 168018 0 Jul 30-rlogind
Cortana 409708 569522 0 19:29:27 pts/1-ksh
Root 569522 168018 0 19:29:26-rlogind
Cortana 733188 409708 3 19:30:34 pts/1 ps-ef
Root 749668 168018 0 Jul 30-rlogind

The list of currently running processes on the system may be as simple as listing 1; however, most production systems run more processes, which leads to longer ps output. In order to shorten the list to the desired range, you can use pipelines to put ps? Ef's standard output is redirected to grep to search for the expected results. Listing 2 redirects the process list produced by listing 1 to grep and searches for the strings "rpc" and "ksh ".

Listing 2. Redirect the process list to grep

# Ps? Ef | grep? E "rpc | ksh"

Root 196718 151674 0 11:00:27-/usr/sbin/rpc. mountd
Daemon 225402 151674 0 11:00:27-/usr/sbin/rpc. statd
Root 229498 151674 0 11:00:27-/usr/sbin/rpc. lockd
Root 340144 168018 0 12:34:56-rpc. ttdbserver 100083 1
Cortana 409708 569522 0 19:29:27 pts/1-ksh
Cortana 733202 409708 0 19:52:20 pts/1 grep-E rpc | ksh

When stdout is redirected to stdin multiple times, the pipeline usage can be complicated. In the following example, the ps and grep examples are extended to redirect its stdout to another grep, which is used to exclude strings containing "grep" or "ttdbserver. When the last grep operation is complete, use the pipeline again to redirect stdout to an awk statement. The function is to output all processes whose ID (PID) is greater than 200,000:

 
# ps ?ef | grep ?E "rpc|ksh" | grep -vE "grep|rpc.ttdbserver" |    awk -v _MAX_PID=200000 '{if ($2 > _MAX_PID) {print "PID for    process",$8,"is greater than", _MAX_PID}}'PID for process /usr/sbin/rpc.statd is greater than 200000PID for process /usr/sbin/rpc.lockd is greater than 200000PID for process -ksh is greater than 200000

Figure 1 graphically describes the sequence in which stdout redirects the command to stdin of subsequent commands.

Figure 1. Pipeline example

[1] [2] [3] [4] [5] [6] [7] Next page

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.