Share 10 Linux commands you may have never used

Source: Internet
Author: User
Tags qmail
The following may be the ten Linux commands you have never used. But it is quite useful. To help you

1) pgrep

There is a p in front of the pgrep name. we can guess that it is related to the process, and it is also a grep command related to the process. However, this command is mainly used to list process IDs. For example:


Copy codeThe code is as follows:
$ Pgrep-u hchen
22441
22444

This command is equivalent:


Copy codeThe code is as follows:
Ps-ef | egrep '^ hchen' | awk' {print $2 }'

2) pstree

This command can list processes in a tree. As follows:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] $ Pstree
Init-+-acpid
|-Auditd-+-python
| '-{Auditd}
|-Automount --- 4 * [{automount}]
|-Backup. sh --- sleep
|-Example-daemon
|-Events/0
|-Events/1
|-Hald --- hald-runner --- hald-addon-acpi
|-Httpd --- 10 * [httpd]
|-Irqbalance
|-Khelper
|-Klogd
|-Ksoftirqd/0
|-Ksoftirqd/1
|-Kthread-+-aio/0
|-Aio/1
|-Ata/0
|-Ata/1
|-Ata_aux
|-Cqueue/0
|-Cqueue/1
|-Kacpid
|-Kauditd
|-Kblockd/0
|-Kblockd/1
|-Kedac
|-Khubd
|-6 * [kjournald]
|-Kmirrord
|-Kpsmoused
|-Kseriod
|-Kswapd0
|-2 * [pdflush]
|-Scsi_eh_0
|-Scsi_eh_1
|-Xenbus
| '-Xenwatch
|-Migration/0
|-Migration/1
|-6 * [mingetty]
|-3 * [multilog]
|-Mysqld_safe --- mysqld --- 9 * [{mysqld}]
|-Smartd
|-Sshd --- bash --- pstree
|-Svscanboot --- svscan-+-3 * [supervise --- run]
|-Supervise --- qmail-send-+-qmail-clean
|-Qmail-lspawn
| '-Qmail-rspawn
| '-2 * [supervise --- tcpserver]
|-Syslogd
|-Udevd
|-Watchdog/0
|-Watchdog/1
'-Xinetd

3) bc

This command is mainly used for a mathematical operation with high accuracy. Such as square root. The following is a script written using the bc command (File name: sqrt)


Copy codeThe code is as follows:
#! /Bin/bash
If [$ #-ne 1]
Then
Echo 'Usage: sqrt number'
Exit 1
Else
Echo-e "sqrt ($1) \ nquit \ n" | bc-q-I
Fi

Therefore, we can use this script to perform the square root operation as follows:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5] $./sqrt 36
6
[Hchen @ RHELSVR5] $./sqrt 2.0000
1.4142
[Hchen @ RHELSVR5] $./sqrt 10.0000
3.1622

4) split

If you have a large file and want to split it into some small files, this command is for this purpose.


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 applebak] # ls-l largefile.tar.gz
-Rw-r -- 1 hchen 436774774 04-17 largefile.tar.gz

[Hchen @ RHELSVR5 applebak] # split-B 50 m largefile.tar.gz LF _

[Hchen @ RHELSVR5] # ls-l LF _*
-Rw-r -- 1 hchen 52428800 05-10 LF_aa
-Rw-r -- 1 hchen 52428800 05-10 LF_ AB
-Rw-r -- 1 hchen 52428800 05-10 LF_ac
-Rw-r -- 1 hchen 52428800 05-10 LF_ad
-Rw-r -- 1 hchen 52428800 05-10 LF_ AE
-Rw-r -- 1 hchen 52428800 05-10 LF_af
-Rw-r -- 1 hchen 52428800 05-10 LF_ag
-Rw-r -- 1 hchen 52428800 05-10 LF_ah
-Rw-r -- 1 hchen 17344374 05-10 LF_ai

You only need to use simple merge to merge files, for example:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5] # cat LF _ *> largefile.tar.gz

5) nl

The nl command is similar to the cat command, except that it has a line number. As follows:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 include] # nl stdio. h | head-n 10
1/* Define iso c stdio on top of C ++ iostreams.
2 Copyright (C) 2006-, Free Software Foundation, Inc.
3 This file is part of the gnu c Library.

4 The gnu c Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.

8 The gnu c Library is distributed in the hope that it will be useful,

6) mkfifo

Anyone familiar with Unix should know that this is a system call or command to create a famous pipeline. In normal times, we use the vertical line "|" on the command line to concatenate commands using a life-Free pipeline. While mkfifo is used for famous pipelines. The following is an example:

The following shows how to create a famous pipeline:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] # Mkfifo/tmp/hchenpipe

[Hchen @ RHELSVR5 ~] # Ls-l/tmp
Prw-rw-r -- 1 hchen 0 05-10 18:58 hchenpipe

Then, run the following command in a shell. this command will not be returned unless someone reads the information from this famous pipeline.


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] # Ls-al>/tmp/hchenpipe

We read the information in this pipeline in another command window: (it will cause the previous command to return)


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] # Head/tmp/hchenpipe
Drwx ------ 8 hchen 4096 05-10.
Drwxr-xr-x 7 root 4096 03-05 ..
Drwxr-xr-x 3 hchen 4096 03-01 backup
-Rw ------- 1 hchen 721 05-05. bash_history
-Rw-r -- 1 hchen 24 02-28 22:20. bash_logout
-Rw-r -- 1 hchen 176 02-28. bash_profile
-Rw-r -- 1 hchen 124 02-28. bashrc
-Rw-r -- 1 root 14002 03-07 00:29 index.htm
-Rw-r -- 1 hchen 31465 03-01 index. php

7) ldd

This command shows that one of your executable files uses a dynamic link library. For example:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] # Ldd/usr/bin/java
Linux-gate.so.1 => (0x00cd9000)
Libgij. so.7rh =>/usr/lib/libgij. so.7rh (0x00ed3000)
Libgcj. so.7rh =>/usr/lib/libgcj. so.7rh (0x00ed6000)
Libpthread. so.0 =>/lib/i686/nosegneg/libpthread. so.0 (0x00110000)
Librt. so.1 =>/lib/i686/nosegneg/librt. so.1 (0x009c8000)
Libdl. so.2 =>/lib/libdl. so.2 (0x008b5000)
Libz. so.1 =>/usr/lib/libz. so.1 (0x00bee000)
Libgcc_s.so.1 =>/lib/libgcc_s.so.1 (0x00aa7000)
Libc. so.6 =>/lib/i686/nosegneg/libc. so.6 (0x0022f000)
Libm. so.6 =>/lib/i686/nosegneg/libm. so.6 (0x00127000)
/Lib/ld-linux.so.2 (0x00214000)

8) col

This command allows you to convert man files into plain text files. Example:


Copy codeThe code is as follows:
# PAGER = cat
# Man less | col-B> less.txt

9) xmlwf

This command allows you to check whether the next XML document contains all tags. For example:


Copy codeThe code is as follows:
[Hchen @ RHELSVR5 ~] # Curl 'http: // cocre.com /? Feed = rss2 '> core. xml
% Total % Received % Xferd Average Speed Time Current
Dload Upload Total Spent Left Speed
100 64882 0 64882 0 0 86455 0 --: -- 2073 k
[Hchen @ RHELSVR5 ~] # Xmlwf core. xml
[Hchen @ RHELSVR5 ~] # Perl-I-pe's @ @
@ G'cocret. xml
[Hchen @ RHELSVR5 ~] # Xmlwf core. xml
Core. xml: 13: 23: mismatched tag

10) lsof

You can list opened files.


Copy codeThe code is as follows:
[Root @ RHELSVR5 ~] # Lsof | grep TCP
Httpd 548 apache 4u IPv6 14300967 TCP *: http (LISTEN)
Httpd 548 apache 6u IPv6 14300972 TCP *: https (LISTEN)
Httpd 561 apache 4u IPv6 14300967 TCP *: http (LISTEN)
Httpd 561 apache 6u IPv6 14300972 TCP *: https (LISTEN)
Sshd 1764 root 3u ipv6-4993 TCP *: ssh (LISTEN)
Tcpserver 8965 root 3u IPv4 153795500 TCP *: pop3 (LISTEN)
Mysqld 10202 mysql 10u IPv4 73819697 TCP *: mysql (LISTEN)
Sshd 10735 root 3u IPv6 160731956 TCP 210.51.0.133: ssh-> 123.117.239.68: 31810 (ESTABLISHED)
Sshd 10767 hchen 3u IPv6 160731956 TCP 210.51.0.133: ssh-> 123.117.239.68: 31810 (ESTABLISHED)
Vsftpd 11095 root 3u IPv4 152157957 TCP *: ftp (LISTEN)

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.