被遗忘的十条Linux命令,沧海明珠,关键时刻能帮你大
发布时间: 2023-07-11

Linux,作为被全球程序员维护的一个开源系统,被全球程序员所喜爱,而随着信息化产业的发展以及大数据、人工智能的发展,服务器成为一个重要的资源,而Linux无论是在运维还是开发上,都占有越来越重要的地位,除了常见的一个命令之外,你知道这十条Linux使用命令吗?虽然不常用,但是在关键的时候他能帮你大忙,提升你的工作效率,而Linux的使用场景也是相当丰富,尤其是在现在的互联网开发中。

这边文文章主要从两个方向进行讲解

1、不常用但是很好用的10条Linux命令

2、Linux的使用场景

1)pgrep

pgrep名字前有个p,我们可以猜到这和进程相关,又是grep,当然这是进程相关的grep命令。不过,这个命令主要是用来列举进程ID的。如:

这个命令相当于:

ps -ef | egrep '^hchen' | awk '{print $2}'

2)pstree

这个命令可以以树形的方式列出进程。如下所示:

[hchen@RHELSVR5 ~]$ pstree

init-+-acpid

-auditd-+-python

`-{auditd}

-automount---4*[{automount}]

-backup.sh---sleep

-dbus-daemon

-events/0

-events/1

-hald---hald-runner---hald-addon-acpi

-]

-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---sshd---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

这个命令主要是做一个精度比较高的数学运算的。比如开平方根等。下面是一个我们利用bc命令写的一个脚本(文件名:sqrt)

#!/bin/bash

if [ $

then

echo 'Usage: sqrt number'

exit 1

else

echo -e "sqrt($1)\nquit\n" | bc -q -i

fi

于是,我们可以这样使用这个脚本进行平方根运算:

[hchen@RHELSVR5]$ ./sqrt 36

6

[hchen@RHELSVR5]$ ./sqrt 2.0000

1.4142

[hchen@RHELSVR5]$ ./sqrt 10.0000

3.1622

4)split

如果你有一个很大的文件,你想把其分割成一些小的文件,那么这个命令就是干这件事的了。

[hchen@RHELSVR5 applebak]# ls -l largefile.tar.gz

-rw-r--r-- 1 hchen hchen 436774774 04-17 02:00 largefile.tar.gz

[hchen@RHELSVR5 applebak]# split -b 50m largefile.tar.gz LF_

[hchen@RHELSVR5]# ls -l LF_*

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_aa

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ab

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ac

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ad

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ae

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_af

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ag

-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ah

-rw-r--r-- 1 hchen hchen 17344374 05-10 18:35 LF_ai

文件合并只需要使用简单的合并就行了,如:

[hchen@RHELSVR5]# cat LF_* >largefile.tar.gz

5)nl

nl命令其它和cat命令很像,只不过它会打上行号。如下所示:

[hchen@RHELSVR5 include]# nl stdio.h | head -n 10

1 /* Define ISO C stdio on top of C++ iostreams.

2 Copyright (C) 1991,1994-2004,2005,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

熟悉Unix的人都应该知道这个是一个创建有名管道的系统调用或命令。平时,我们在命令行上使用竖线“|”把命令串起来是使用无命管道。而我们使用mkfifo则使用的是有名管道。下面是示例:

下面是创建一个有名管道:

[hchen@RHELSVR5 ~]# mkfifo /tmp/hchenpipe

[hchen@RHELSVR5 ~]# ls -l /tmp

prw-rw-r-- 1 hchen hchen 0 05-10 18:58 hchenpipe

然后,我们在一个shell中运行如下命令,这个命令不会返回

微信