> 文章列表 > Linus命令记录(持续编辑版)

Linus命令记录(持续编辑版)

Linus命令记录(持续编辑版)

目录

一、前言

二、2023年2月查找Linus命令记录

1、竖线 '|',双竖线 '||',&和&&

2、wc

3、free 和 top

4、c 库函数 strcpy()

5、c 库函数 memmove()

6、open

三、2023年3月查找Linus命令记录

1、sort

2、uniq


一、前言

有时候遇到不懂的Linus命令时我就去查找,了解命令意思后解决了疑问,但是当下一次遇到相似的命令,如果想不清晰又去查找,这样效率不高,也不便于我复习或追溯我曾经查过什么命令,所以我干脆写一个查找Linus命令的笔记记录,毫无疑问,这篇博客会持续更新很久。

二、2023年2月查找Linus命令记录

1、竖线 '|',双竖线 '||',&和&&

1)竖线 '|',在 Linux 中是作为管道符的,将 '|' 前面命令的输出作为 '|' 后面的输入。

2)双竖线 '||',用双竖线 '||' 分割的多条命令,执行的时候遵循如下规则,如果前一条命令为真,则后面的命令不会执行,如果前一条命令为假,则继续执行后面的命令。

3)& 同时执行多条命令,不管命令是否执行成功。

4)&& 可同时执行多条命令,当碰到执行错误的命令时,将不再执行后面的命令。如果一直没有错误的,则执行完毕。

2、wc

参考链接:Linux wc命令 | 菜鸟教程 (runoob.com)

wc 命令用于计算字数。

利用 wc 指令我们可以计算文件的 Byte数、字数、或是列数;

若不指定文件名称、或是所给予的文件名为 "-",则 wc 指令会从标准输入设备读取数据。

!注!:详细解析与例子请看上述链接。

3、free 和 top

  • 单独查看内存使用情况的命令:free -m
  • free的默认单位是kb
  • [Mem:] [total] 的值就是当前系统的内存大小 (MB)
  • 功能说明:显示内存状态。
  • 补充说明:free 指令会显示内存的使用情况,包括实体内存,虚拟的交换文档内存,共享内存区段,连同系统核心使用的缓冲区等。
  • 参数:
  • -b   以Byte为单位显示内存使用情况。
  • -k   以KB为单位显示内存使用情况。
  • -m  以MB为单位显示内存使用情况。
  • -o   不显示缓冲区调节列。
  • -s      持续观察内存使用状况。
  • -t    显示内存总和列。
  • -V  显示版本信息。

参考链接:Linux free命令 | 菜鸟教程

top 命令可以查看系统的 CPU、内存、运行时间、交换分区、执行的线程等信息

# 也可以使用增强版 top

apt-get install htop

htop

4、c 库函数 strcpy()

The function prototype of strcpy() is:

char* strcpy(char* destination, const char* source);
  • The strcpy() function copies the string pointed by source (including the null character) to the destination.
  • The strcpy() function also returns the copied string.
  • The strcpy() function is defined in the string.h header file.

5、c 库函数 memmove()

void *memmove(void *str1, const void *str2, size_t n) 
  • 从 str2 复制 n 个字符到 str1
  • 但是在重叠内存块这方面,memmove() 是比 memcpy() 更安全的方法。如果目标区域和源区域有重叠的话,memmove() 能够保证源串在被覆盖之前将重叠区域的字节拷贝到目标区域中,复制后源区域的内容会被更改。如果目标区域与源区域没有重叠,则和 memcpy() 函数功能相同。
  • str1 -- 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针。
  • str2 -- 指向要复制的数据源,类型强制转换为 void* 指针。
  • n -- 要被复制的字节数。

6、open

open(const char *path, int oflag, ...);

The file name specified by path is opened for reading and/or writing, as specified by the argument oflag; the file descriptor is returned to the calling process.The oflag argument may indicate that the file is to be created if it does not exist (by specifying the O_CREAT flag).  In this case, open() and openat() require an additional argument mode_t mode; the file is created with mode mode as described in chmod(2) and modified by the process' umask value (see umask(2)).

关于open的更多内容见联机帮助。

RETURN VALUES

If successful, open() returns a non-negative integer, termed a file descriptor.  It returns -1 on failure, and sets errno to indicate the error.

oflag取0,说明是以只读方式打开文件,相当于 O_RDONLY。

三、2023年3月查找Linus命令记录

1、sort

Linux sort 命令用于将文本文件内容加以排序

sort 可针对文本文件的内容,以行为单位来排序。

语法:

sort [-bcdfimMnr][-o<输出文件>][-t<分隔字符>][+<起始栏位>-<结束栏位>][--help][--verison][文件][-k field1[,field2]]

参数详情见:Linux sort命令 | 菜鸟教程 (runoob.com)

2、uniq

Linux uniq 命令用于检查及删除文本文件中重复出现的行列,一般与 sort 命令结合使用。

uniq 可检查文本文件中重复出现的行列。

语法:

uniq [-cdu][-f<栏位>][-s<字符位置>][-w<字符位置>][--help][--version][输入文件][输出文件]

参数详情见:Linux uniq 命令 | 菜鸟教程 (runoob.com)

举例(查看物理CPU数目,并用管道排序去重后输出):

cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l