用户工具

站点工具


linux:linux常用命令

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
linux:linux常用命令 [2026/10/13 22:06] – 外部编辑 127.0.0.1linux:linux常用命令 [2026/11/05 16:31] (当前版本) – [13. sort] user01
行 2: 行 2:
 ## - 删除N天前最老的目录或文件 ## - 删除N天前最老的目录或文件
 删除3天前最老的目录或文件,find时仅限搜索一层。 -- 感觉这玩意有时候不灵,不太好用。 删除3天前最老的目录或文件,find时仅限搜索一层。 -- 感觉这玩意有时候不灵,不太好用。
-<code bash>find /your_dir/ -maxdepth 1 -mtime +3 | head -1 | xargs rm -rf </code>+ 
 +```bash 
 +find /your_dir/ -maxdepth 1 -mtime +3 | head -1 | xargs rm -rf 
 +``` 
  
  
 ## - 解压 ## - 解压
-<code>+ 
 +```
 Main operation mode: Main operation mode:
        -c, --create        -c, --create
行 28: 行 33:
        -C, --directory=DIR        -C, --directory=DIR
               change to directory DIR               change to directory DIR
-</code>+```
  
  
  
-  * 解压.tar到指定目录  <code>tar -xvf xxx.tar.gz -C /tmp/</code> + 
-  * 解压tar.gz到指定目录  <code>tar -zxvf xxx.tar.gz -C /tmp/</code> +  * 解压.tar到指定目录   
-  * 解压bz2到指定目录  <code>tar -jxvf xxx.tar.bz2 -C /tmp/</code>+``` 
 +tar -xvf xxx.tar.gz -C /tmp/ 
 +``` 
 + 
 +  * 解压tar.gz到指定目录   
 +``` 
 +tar -zxvf xxx.tar.gz -C /tmp/ 
 +``` 
 + 
 +  * 解压bz2到指定目录   
 +``` 
 +tar -jxvf xxx.tar.bz2 -C /tmp/ 
 +``` 
  
  
行 41: 行 59:
  
  
-<code>+ 
 +```
 cksum [FILE]... cksum [FILE]...
-</code>+``` 
  
 一般网上下载软件的时候都需要check crc值,来确保下载数据有没有问题,有时候即使文件大小,crc也是check不过的,下载下来的数据包有问题。 一般网上下载软件的时候都需要check crc值,来确保下载数据有没有问题,有时候即使文件大小,crc也是check不过的,下载下来的数据包有问题。
行 51: 行 71:
 ## - mount ## - mount
 ### - NFS ### - NFS
-<code>mount -t nfs 192.168.2.22:/home/example/rootfs /mnt/nfs</code>+ 
 +``` 
 +mount -t nfs 192.168.2.22:/home/example/rootfs /mnt/nfs 
 +``` 
  
  
 ### - cdrom ### - cdrom
-<code>+ 
 +```
 mount -t iso9660 /dev/scd0 /media/dvd1 mount -t iso9660 /dev/scd0 /media/dvd1
 mount -t iso9660 /dev/scd1 /media/dvd2 mount -t iso9660 /dev/scd1 /media/dvd2
-</code>+``` 
  
  
行 68: 行 94:
 **bash**  **bash** 
  
-<code bash>+ 
 +```bash
 alias cd='new() { cd $1; ls; }; new' alias cd='new() { cd $1; ls; }; new'
-</code>+``` 
  
  
 **csh/tcsh**  **csh/tcsh** 
  
-<code bash>+ 
 +```bash
 alias cd 'cd \!*; ls' alias cd 'cd \!*; ls'
  
行 90: 行 119:
 !:x* Like x-$( $ is the last argument) above. !:x* Like x-$( $ is the last argument) above.
 !:x- Like x* except that word$ is omitted. !:x- Like x* except that word$ is omitted.
 +```
  
-</code> 
  
  
 ## - diff ## - diff
-<code bash>+ 
 +```bash
 diff -r -q dir1 dir2 | grep differ | awk '{print "gvimdiff",$2,$4}' diff -r -q dir1 dir2 | grep differ | awk '{print "gvimdiff",$2,$4}'
  
 alias tt 'diff -r -q \!* | grep differ | awk ' "'" '{print "gvimdiff",$2,$4}' "'" alias tt 'diff -r -q \!* | grep differ | awk ' "'" '{print "gvimdiff",$2,$4}' "'"
-</code>+``` 
  
 ## - 管道 ## - 管道
 **格式**   **格式**  
-<code>+ 
 +```
 command1 | command2 command1 | command2
 command1 | command2 [ | commandN... ] command1 | command2 [ | commandN... ]
-</code>+``` 
  
 当在两个命令之间设置管道时,管道符|左边命令的输出就变成了右边命令的输入。只要第一个命令向`标准输出`写入,而第二个命令是从`标准输入`读取,那么这两个命令就可以形成一个管道。 当在两个命令之间设置管道时,管道符|左边命令的输出就变成了右边命令的输入。只要第一个命令向`标准输出`写入,而第二个命令是从`标准输入`读取,那么这两个命令就可以形成一个管道。
行 113: 行 146:
  
 ## - bshell prompt ## - bshell prompt
-<code bash>+ 
 +```bash
 Sequence Value Displayed Sequence Value Displayed
 \a ASCII bell. This makes the computer beep when it is encountered. \a ASCII bell. This makes the computer beep when it is encountered.
行 145: 行 179:
 cursor or changing text colors. cursor or changing text colors.
 \] Signals the end of a non-printing character sequence. \] Signals the end of a non-printing character sequence.
 +```
  
-</code> 
  
  
  
 ## - cshell prompt ## - cshell prompt
-<code bash>+ 
 +```bash
 prompt prompt
 The string which is printed before reading each command from the terminal. prompt may include any of the following formatting sequences (+), which are replaced by the given informa- tion: The string which is printed before reading each command from the terminal. prompt may include any of the following formatting sequences (+), which are replaced by the given informa- tion:
行 228: 行 263:
  
 Set by default to ‘%# ’ in interactive shells. Set by default to ‘%# ’ in interactive shells.
-</code>+``` 
  
  
行 234: 行 270:
 参考文件:http://tldp.org/HOWTO/Xterm-Title-4.html 参考文件:http://tldp.org/HOWTO/Xterm-Title-4.html
  
-使用csh时,可以在.cshrc文件中添加如下设置: set prompt = “<color #ed1c24>%{\033]0;%C2\007%}</color><color #22b14c>%/</color>”+使用csh时,可以在.cshrc文件中添加如下设置: set prompt = “<span style="color:#ed1c24">%{\033]0;%C2\007%}</span><span style="color:#22b14c">%/</span>”
  
 其中红色部分是设置title名字为%C2,绿色是命令行提示符为%/。 其中红色部分是设置title名字为%C2,绿色是命令行提示符为%/。
  
 ## - cshrc ## - cshrc
-<code bash>+ 
 +```bash
  
 set title = "%{\033]0;%C2\007%}" set title = "%{\033]0;%C2\007%}"
行 258: 行 295:
 alias   ..          "cd .." alias   ..          "cd .."
 alias   g           "gvim" alias   g           "gvim"
 +```
  
-</code> 
  
  
 ## - 不同机器之间手动同步时间 ## - 不同机器之间手动同步时间
-<code bash>+ 
 +```bash
 /usr/sbin/ntpdate 192.168.0.115 /usr/sbin/ntpdate 192.168.0.115
-</code>+``` 
  
  
  
 ## - sort ## - sort
-<code bash [enable_line_numbers="true",highlight_lines_extra="10,11"]>+ 
 +```bash [enable_line_numbers="true",highlight_lines_extra="10,11"]
 sort   [选项参数]   [-o<输出文件>]   [-t<分隔字符>]   [+<起始栏位>   -<结束栏位>]   [文件] sort   [选项参数]   [-o<输出文件>]   [-t<分隔字符>]   [+<起始栏位>   -<结束栏位>]   [文件]
    
行 291: 行 331:
  + ===> <起始栏位> -<结束栏位> 以指定的栏位来排序,范围由起始栏位到结束栏位的前一栏位(从0开始)  + ===> <起始栏位> -<结束栏位> 以指定的栏位来排序,范围由起始栏位到结束栏位的前一栏位(从0开始)
 -o ===> <输出文件> 将排序后的结果存入指定的文件 -o ===> <输出文件> 将排序后的结果存入指定的文件
-———————————————— +``` 
-版权声明:本文为CSDN博主「IT蓝月」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 + 
-原文链接:https://blog.csdn.net/ITlanyue/article/details/105013828 +用 **`sort -V`(版本排序 / 自然排序)**,专门处理 `row0 row1 row10 row2` 这种字母 + 数字混合,让里面数字按数值走: 
-</code>+ 
 +``` 
 +# data.txt 
 +row0 
 +row1 
 +row10 
 +row2 
 +``` 
 + 
 +``` 
 +sort -V data.txt 
 +``` 
 + 
 +输出: 
 + 
 +``` 
 +row0 
 +row1 
 +row2 
 +row10 
 +``` 
 + 
 +降序: 
 + 
 +``` 
 +sort -Vr data.txt 
 +``` 
 + 
 +区别: 
 + 
 +- `sort -n`:是把**整行当成数字**,你的行是 `rowxx` 带前缀字母,`-n` 无效 
 +- `sort` 默认:ASCII 字典序 → `row0,row1,row10,row2`(就是你现在不对的结果) 
 +- `sort -V`:自然排序,字符串分段比较,遇到数字段自动按数值比较,完美匹配你这个场景 
  
  
行 302: 行 375:
 tail - output the last part of files tail - output the last part of files
  
-<code>+ 
 +```
 tail -n 20 file; # 输出文件的最后20行 tail -n 20 file; # 输出文件的最后20行
 tail -n +20 file; # 从文件的第20行开始输出 tail -n +20 file; # 从文件的第20行开始输出
 +```
  
-</code> 
  
 ## - head ## - head
 head - output the first part of files head - output the first part of files
-<code>+ 
 +```
 head -n 20 file; # 输出文件的前20行内容 head -n 20 file; # 输出文件的前20行内容
-</code>+``` 
  
  
行 318: 行 394:
 ### - 基本用法 ### - 基本用法
 sed 常用命令 sed 常用命令
-<code bash>+ 
 +```bash
 sed -i 's/regexp/replace' xxx.txt;   替换文件内容,并修改文件 sed -i 's/regexp/replace' xxx.txt;   替换文件内容,并修改文件
 sed -n 'p' xxx.txt    ;   #  全部打印输出文件内容 sed -n 'p' xxx.txt    ;   #  全部打印输出文件内容
行 324: 行 401:
 sed -n '1,3p' xxx.txt;    # 只打印输出文件的1到3行 sed -n '1,3p' xxx.txt;    # 只打印输出文件的1到3行
 sed -n '2p' xxx.txt;    # 只打印输出文件第2行 sed -n '2p' xxx.txt;    # 只打印输出文件第2行
-</code>+``` 
 + 
  
-<code bash>+```bash
  
 sed 's/regexp/replacement/' distros.txt sed 's/regexp/replacement/' distros.txt
行 339: 行 418:
 # -i, 将替换后的结果写回原文件中 # -i, 将替换后的结果写回原文件中
 sed -i 's/\(regexp\)/new_\1/' distros.txt sed -i 's/\(regexp\)/new_\1/' distros.txt
-</code>+``` 
  
  
行 345: 行 425:
  
 对某个字符串进行替换 对某个字符串进行替换
-<code bash>+ 
 +```bash
 [me@linuxbox ~]$ echo "front" | sed 's/front/back/' [me@linuxbox ~]$ echo "front" | sed 's/front/back/'
 back back
-</code>+``` 
  
  
行 358: 行 440:
   * P -- 打印多行中的一行   * P -- 打印多行中的一行
  
-<code bash>+ 
 +```bash
 sed '/ee/N;   s/\n/ /' tmp.txt;   -- 按行匹配到ee后,读出下一行内容形成两行匹配,将其中的换行符替换为 空格。 sed '/ee/N;   s/\n/ /' tmp.txt;   -- 按行匹配到ee后,读出下一行内容形成两行匹配,将其中的换行符替换为 空格。
-</code>+``` 
  
 ## - basename ## - basename
-<code tcsh>+ 
 +```tcsh
 # csh # csh
 set a = '/home/xxx' set a = '/home/xxx'
行 369: 行 454:
 echo $name echo $name
 > xxx > xxx
-</code>+``` 
 ## - cut ## - cut
 cut是一个简单功能的字段截取工具,推荐使用更强功能的awk [awk语法速查](语法:awk语法速查) cut是一个简单功能的字段截取工具,推荐使用更强功能的awk [awk语法速查](语法:awk语法速查)
  
-<code>+ 
 +```
 cut OPTION... [FILE]... cut OPTION... [FILE]...
 -c:仅显示行中指定范围的字符; -c:仅显示行中指定范围的字符;
 -d:指定字段的分隔符,默认的字段分隔符为“TAB”; -d:指定字段的分隔符,默认的字段分隔符为“TAB”;
 -f:显示指定字段的内容; -f:显示指定字段的内容;
 +```
 +
  
-</code> +```
-<code>+
 # cat test.txt # cat test.txt
 No Name Mark Percent No Name Mark Percent
行 422: 行 510:
 jack jack
 alex alex
 +```
  
-</code> 
  
 ## - wget批量下载文件 ## - wget批量下载文件
行 449: 行 537:
  
 ## - iconv 文件编码转换 ## - iconv 文件编码转换
-<code>+ 
 +```
  iconv - convert text from one character encoding to another  iconv - convert text from one character encoding to another
 SYNOPSIS SYNOPSIS
        iconv [options] [-f from-encoding] [-t to-encoding]        iconv [options] [-f from-encoding] [-t to-encoding]
        [inputfile]...        [inputfile]...
 +```
  
-</code> 
linux/linux常用命令.1791900372.txt.gz · 最后更改: 由 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki