程序员

6个你可能不熟悉的Linux实用命令

作者:admin 2021-08-11 我要评论

Linux是一个强大的操作系统,这篇文章收集了6个你可能没有用过的Linux命令,但却相当的有用,供大家参考。 1. bc 这个Linux命令用于精度比较高的数学运算。如:...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

Linux是一个强大的操作系统,这篇文章收集了6个你可能没有用过的Linux命令,但却相当的有用,供大家参考。

1. bc

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

  1. #!/bin/bash 
  2. if [ $ 
  3. then 
  4.     echo 'Usage: sqrt number' 
  5.     exit 1 
  6. else 
  7.     echo -e "sqrt($1)\nquit\n" | bc -q -i 
  8. fi 

接着,可使用这个脚本进行平方根运算:

  1. [hchen@RHELSVR5]$ ./sqrt 36 
  2. [hchen@RHELSVR5]$ ./sqrt 2.0000 
  3. 1.4142 
  4. [hchen@RHELSVR5]$ ./sqrt 10.0000 
  5. 3.1622 

2. split

如果你的文件很大,却接到命令要把它分割成小文件,那么这个命令就派上用场了。

  1. [hchen@RHELSVR5 applebak]# ls -l largefile.tar.gz 
  2. -rw-r--r-- 1 hchen hchen 436774774 04-17 02:00 largefile.tar.gz 
  3. [hchen@RHELSVR5 applebak]# split -b 50m largefile.tar.gz LF_ 
  4. [hchen@RHELSVR5]# ls -l LF_* 
  5. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_aa 
  6. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ab 
  7. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ac 
  8. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ad 
  9. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ae 
  10. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_af 
  11. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ag 
  12. -rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ah 
  13. -rw-r--r-- 1 hchen hchen 17344374 05-10 18:35 LF_ai 

反而来,合并也只需要简单的合并就行,如:

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

3. pgrep

pgrep名字前有个p,可以猜想它可能和grep有关,确实这是进程相关的grep命令。不过,这个命令主要是用来列举进程ID的。如:

  1. $ pgrep -u hchen 
  2. 22441 
  3. 22444 

这个命令相当于:

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

4. nl

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

  1. [hchen@RHELSVR5 include]# nl stdio.h | head -n 10 
  2.      1  /* Define ISO C stdio on top of C++ iostreams. 
  3.      2     Copyright (C) 1991,1994-2004,2005,2006 Free Software Foundation, Inc. 
  4.      3     This file is part of the GNU C Library. 
  5.      4     The GNU C Library is free software; you can redistribute it and/or 
  6.      5     modify it under the terms of the GNU Lesser General Public 
  7.      6     License as published by the Free Software Foundation; either 
  8.      7     version 2.1 of the License, or (at your option) any later version. 
  9.      8     The GNU C Library is distributed in the hope that it will be useful, 

5. ldd

这个命令,用来可执行文件所使用了动态链接库。如:

  1. [hchen@RHELSVR5 ~]# ldd /usr/bin/java 
  2.         linux-gate.so.1 => (0x00cd9000) 
  3.         libgij.so.7rh => /usr/lib/libgij.so.7rh (0x00ed3000) 
  4.         libgcj.so.7rh => /usr/lib/libgcj.so.7rh (0x00ed6000) 
  5.         libpthread.so.0 => /lib/i686/nosegneg/libpthread.so.0 (0x00110000) 
  6.         librt.so.1 => /lib/i686/nosegneg/librt.so.1 (0x009c8000) 
  7.         libdl.so.2 => /lib/libdl.so.2 (0x008b5000) 
  8.         libz.so.1 => /usr/lib/libz.so.1 (0x00bee000) 
  9.         libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00aa7000) 
  10.         libc.so.6 => /lib/i686/nosegneg/libc.so.6 (0x0022f000) 
  11.         libm.so.6 => /lib/i686/nosegneg/libm.so.6 (0x00127000) 
  12.         /lib/ld-linux.so.2 (0x00214000) 

6. col

这个命令,能将man文件转成纯文本文件。如下示例:

  1. PAGER=cat 
  2. # man less | col -b > less.txt 
【责任编辑:赵宁宁 TEL:(010)68476606】
本文转载自网络,原文链接:https://www.toutiao.com/i6888861049538216451/

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 十月更新修复了Windows 10的Ping of De

    十月更新修复了Windows 10的Ping of De

  • Windows10 UAC弹窗太烦但又不能关?教

    Windows10 UAC弹窗太烦但又不能关?教

  • 老大手把手教我玩 Git 变基!

    老大手把手教我玩 Git 变基!

  • 在Linux终端中展示幻灯片

    在Linux终端中展示幻灯片