linux shell pgrep命令使用方法(pgrep指令)获取进程号、统计进程数量(学会区分Linux进程进程名)

这篇具有很好参考价值的文章主要介绍了linux shell pgrep命令使用方法(pgrep指令)获取进程号、统计进程数量(学会区分Linux进程进程名)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

问题背景

按照我之前,在脚本中,获取除脚本自身进程之外与脚本同名进程号的方法:

ps -ef | grep "${SCRIPT_NAME}" | grep -v "grep" | awk '{print $2}' | grep -v "$PID"

这种方法有很大问题,莫名奇妙的,它无法正常过滤掉grep的进程(这里面还有点复杂,我一时半会也搞不明白咋回事,据说是grep会开子进程,并非grep那个子进程,而是开了一个与脚本相同的进程,导致出现问题,具体参考:linux shell脚本执行命令时创建子进程问题(特定的情况,例如后台运行、管道、分支或子shell等,脚本可能会创建子进程执行命令)grep)

后来我改用pgrep指令,用这个命令的好处是,不用使用grep命令了,它直接找出来就是进程号,而且不会带入额外的进程号,下面我们来看下pgrep指令的具体用法。

pgrep指令

pgrep命令用于根据进程的名称或其他属性来查找和列出匹配的进程ID(PID)。它可以根据不同的选项进行灵活的进程查找和过滤。

help文档

root@ubuntu:/ky/boot# pgrep --help

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).

中文翻译:

root@ubuntu:/ky/boot# pgrep --help

用法:
 pgrep [选项] <模式>

选项:
 -d, --delimiter <字符串>  指定输出分隔符
 -l, --list-name           列出PID和进程名称
 -a, --list-full           列出PID和完整命令行
 -v, --inverse             反转匹配结果
 -w, --lightweight         列出所有TID
 -c, --count               统计匹配进程的数量
 -f, --full                使用完整进程名称进行匹配
 -g, --pgroup <PGID,...>   匹配指定的进程组ID
 -G, --group <GID,...>     匹配真实组ID
 -i, --ignore-case         不区分大小写进行匹配
 -n, --newest              选择最近启动的进程
 -o, --oldest              选择最早启动的进程
 -P, --parent <PPID,...>   仅匹配给定父进程的子进程
 -s, --session <SID,...>   匹配会话ID
 -t, --terminal <tty,...>  通过控制终端进行匹配
 -u, --euid <ID,...>       通过有效ID进行匹配
 -U, --uid <ID,...>        通过真实ID进行匹配
 -x, --exact               精确匹配命令名称
 -F, --pidfile <文件>      从文件中读取PID
 -L, --logpidfile          如果PID文件未锁定,则失败
 -r, --runstates <状态>    匹配运行状态 [D,S,Z,...]
 --ns <PID>                匹配与<pid>相同命名空间的进程
 --nslist <ns,...>         列出将用于--ns选项的命名空间
                           可用的命名空间:ipc, mnt, net, pid, user, uts

 -h, --help     显示此帮助信息并退出
 -V, --version  输出版本信息并退出

更多详细信息请参阅pgrep(1)

请注意,上面的<pattern>是要匹配的进程名称或其他属性的模式。可以根据实际情况替换为具体的值。

使用示例

以下是pgrep命令不同选项的使用示例:

我们在这个容器中测试:

注意:我们首先要学会区分什么是进程的进程名!
进程名就是那个进程的可执行文件,进程名只有一个,除去进程名,其他的都是路径和参数。
比如/bin/bash /usr/local/bin/entrypoint.sh,进程名是bash

root@5940438e0ee6:/build/libevent# echo "=====输出所有进程完整进程信息:"
=====输出所有进程完整进程信息:
root@5940438e0ee6:/build/libevent# ps -ef 
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Jun27 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root           7       1  0 Jun27 pts/0    00:02:56 ./kyai_rest
root          43       0  0 23:38 pts/1    00:00:00 /bin/bash
root          56      43  0 23:40 pts/1    00:00:00 ps -ef
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# echo "输出所有进程进程名:"
=====输出所有进程进程名:
root@5940438e0ee6:/build/libevent# ps -e -o comm=
bash
kyai_rest
bash
ps
root@5940438e0ee6:/build/libevent# 
1. 列出匹配进程的PID和进程名称(-l)(默认只能从进程名的子集字符串匹配,如果要使用完整进程名的子集字符串匹配,请加-f参数,下同)
pgrep -l <pattern>
pgrep --list-name <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ky
7 kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ./
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ./ky
root@5940438e0ee6:/build/libevent#
root@5940438e0ee6:/build/libevent# pgrep -l -f ./ky
7 kyai_rest

2. 列出匹配进程的PID和完整的命令行(-a)
pgrep -a <pattern>
pgrep --list-full <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a ./ky
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -f ./ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -af ./ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 

3. 统计匹配进程的数量(-c)
pgrep -c <pattern>
pgrep --count <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c ky
1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c bash
2
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c ./ky
0
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c -f ./ky
1
root@5940438e0ee6:/build/libevent# 

4. 使用完整的进程名称(包括参数)的子集进行匹配(-f)(如果pattern跨越进程命令与参数,需要用双引号括起来)★★★★★
pgrep -f <pattern>
pgrep --full <pattern>

比如有一个进程全名为python3 -u /ky/alg/kyai/nv/m/people/alg/main.py,用:

pgrep -f <pattern>

pattern为进程全名的任意字符串子集,都能匹配到。

示例1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f ky
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f ./ky
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep ./ky
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep /usr/local/bin/entrypoint.sh
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f /usr/local/bin/entrypoint.sh
1
root@5940438e0ee6:/build/libevent# 

示例2

pgrep,linux,shell,linux,运维

5. 不区分大小写进行匹配(-i)
pgrep -i <pattern>
pgrep --ignore-case <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i KyAi
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i entry
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i -f eNtry
1
root@5940438e0ee6:/build/libevent# 

6. 选择最近启动的进程(n)
pgrep -n <pattern>
pgrep --newest <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -n bash
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -n bash
43
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 

7. 选择最早启动的进程(-o)
pgrep -o <pattern>
pgrep --oldest <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -o bash
1 /bin/bash /usr/local/bin/entrypoint.sh
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -o bash
1
root@5940438e0ee6:/build/libevent# 

8. 仅匹配给定父进程的子进程(-P)
pgrep -P <PPID> <pattern>
pgrep --parent <PPID> <pattern>

示例:

比如0号进程有1号何2号两个子进程:

pgrep,linux,shell,linux,运维

pgrep -P 0能将0号进程的子进程找出来:

root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0
1
2
root@ubuntu:~# 

在查找到时对子进程筛选:

root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0 "system"
1
root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0 "thread"
2
root@ubuntu:~# 
root@ubuntu:~# 

注意:有时用-f参数从非进程名的字符串段匹配筛选时,注意双引号的使用,以及使用双引号后,仍应注意的问题:

下面测试中:pgrep -f -P 0 --systempgrep -f -P 0 "--system"都是报错的,只有pgrep -f -P 0 " --system"没出问题。

root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 --system
pgrep: unrecognized option '--system'

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).
root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 "--system"
pgrep: unrecognized option '--system'

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 " --system"
1
root@ubuntu:~# 
root@ubuntu:~# 

9. 通过控制终端进行匹配(-t)
用途

指定特定终端名称进行搜索的用途之一是限定搜索范围。在多用户或多终端环境中,可能会有多个终端同时运行着相同的进程。通过指定终端名称,你可以仅在特定终端中搜索匹配的进程,而不是在所有终端中搜索。

这对于需要在特定终端上执行操作或监控特定终端上的进程非常有用。例如,你可能希望在某个特定的终端上查找正在运行的某个应用程序的进程,或者在某个特定的终端上查找与某个用户相关的进程。

另外,指定终端名称还可以用于在脚本或自动化任务中进行进程管理。通过指定特定的终端,你可以确保只对特定终端上的进程进行操作,而不会影响其他终端上的进程。

总而言之,指定特定终端名称进行搜索可以提供更精确和有针对性的进程查找和管理。

命令
pgrep -t <tty> <pattern>
pgrep --terminal <tty> <pattern>
测试步骤

按照以下步骤进行测试:

  1. 打开终端。
  2. 运行 tty 命令,获取当前终端的名称。例如,如果终端名称是 /dev/tty1,则将 <tty> 替换为 tty1
  3. 运行 pgrep -t <tty> <pattern> 命令,将 <pattern> 替换为你想要查找的进程名称或关键字。例如,如果你想要查找所有运行着的 bash 进程,可以运行 pgrep -t tty1 bash
  4. 如果命令成功执行,它将输出匹配的进程 ID。
  5. 你也可以尝试运行 pgrep --terminal <tty> <pattern> 命令,它与上述命令的作用相同。

请注意,pgrep 命令用于在进程列表中查找匹配的进程,并输出它们的进程 ID。<tty> 是终端名称,<pattern> 是要查找的进程名称或关键字。你需要根据你的实际情况替换这些参数。

示例
root@ubuntu:~# 
root@ubuntu:~# tty
/dev/pts/0
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0 bash
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0 sy
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0
root@ubuntu:~# 
root@ubuntu:~# pgrep -t "/dev/pts/0"
root@ubuntu:~# 
root@ubuntu:~# pgrep -t "/dev/pts/0" bash
root@ubuntu:~# 
root@ubuntu:~# 

尴尬,我这啥也搜不出来

10. 通过有效ID进行匹配(-u)
用途

pgrep -u <ID> <pattern>pgrep --euid <ID> <pattern> 命令用于在指定用户 ID 或有效用户 ID 下查找匹配的进程。

  • <ID> 参数用于指定用户 ID 或有效用户 ID。你可以使用用户的用户名或用户 ID 来替换 <ID>
  • <pattern> 参数用于指定要查找的进程名称或关键字。
命令
pgrep -u <ID> <pattern>
pgrep --euid <ID> <pattern>
测试步骤
  1. 打开终端。
  2. 运行 id 命令,获取当前用户的用户 ID 和有效用户 ID。例如,如果用户 ID 是 1000,有效用户 ID 是 1000,则将 <ID> 替换为 1000
  3. 运行 pgrep -u <ID> <pattern> 命令,将 <pattern> 替换为你想要查找的进程名称或关键字。例如,如果你想要查找当前用户下所有运行着的 bash 进程,可以运行 pgrep -u 1000 bash
  4. 如果命令成功执行,它将输出匹配的进程 ID。
  5. 你也可以尝试运行 pgrep --euid <ID> <pattern> 命令,它与上述命令的作用相同。

请注意,pgrep 命令用于在进程列表中查找匹配的进程,并输出它们的进程 ID。-u--euid 选项用于指定用户 ID 或有效用户 ID。<ID> 是用户 ID 或有效用户 ID,<pattern> 是要查找的进程名称或关键字。你需要根据你的实际情况替换这些参数。

示例
root@ubuntu:~# 
root@ubuntu:~# id
uid=0(root) gid=0(root) groups=0(root)
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 0000 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 0 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 1000 bash
root@ubuntu:~# 
root@ubuntu:~# ps -ef | grep bash
root        1061       1  0 19:27 ?        00:00:00 /bin/bash /etc/systemd/nvmemwarning.sh
root        1260       1  0 19:28 ?        00:00:00 /bin/bash /ky/boot/kyai_nv_server.sh
root        1276       1  0 19:28 ?        00:00:00 /bin/bash /etc/systemd/nvgetty.sh
root        3058    2914  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root        3955    3915  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root       23187   23106  0 21:46 pts/0    00:00:00 -bash
root       36607   23187  0 23:39 pts/0    00:00:00 grep --color=auto bash
root@ubuntu:~# 
root@ubuntu:~# 

pgrep,linux,shell,linux,运维

11. 通过真实ID进行匹配(-U)

具体请参见有效id和真实id,我目前还不是很理解。

命令
pgrep -U <ID> <pattern>
pgrep --uid <ID> <pattern>
示例
root@ubuntu:~# 
root@ubuntu:~# pgrep -U 0000 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# 

12. 精确匹配命令名称(-x)★★★
命令
pgrep -x <pattern>
pgrep --exact <pattern>
示例
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# ps -ef 
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root           8       1  0 19:28 pts/0    00:00:39 ./kyai_rest
root          41       0  0 23:45 pts/1    00:00:00 /bin/bash
root          54      41  0 23:46 pts/1    00:00:00 ps -ef
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x kyai 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x kyai_rest
8
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f ./kyai_rest
8
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x bash          
1
41
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f /bin/bash
41
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f /bin/bash /usr/local/bin/entrypoint.sh
pgrep: only one pattern can be provided
Try `pgrep --help' for more information.
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f "/bin/bash /usr/local/bin/entrypoint.sh"
1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 

注意:精准匹配,是包含参数的所有完整匹配

pgrep,linux,shell,linux,运维文章来源地址https://www.toymoban.com/news/detail-734107.html

到了这里,关于linux shell pgrep命令使用方法(pgrep指令)获取进程号、统计进程数量(学会区分Linux进程进程名)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Linux命令行工具使用HTTP代理的方法详解

    Linux命令行工具使用HTTP代理的方法详解

    亲爱的Linux用户们,有没有想过在命令行世界里,你的每一个指令都能悄无声息地穿越千山万水,而不被外界窥探?哈哈,没错,就是通过HTTP代理!今天,我们就来一起探索如何在Linux命令行工具中使用HTTP代理,让你的指令行走江湖更加神秘莫测! 一、设置环境变量 首先,

    2024年04月24日
    浏览(9)
  • linux ssh上传下载文件命令SCP使用方法

    在linux环境里,我们从服务器上下载或者从本地上传文件到服务器上可以通过 SCP命令 来实现。 SCP即Security Copy,是基于SSH登录实现的远程文件拷贝命令 。 命令参数: -r: 递归复制整个文件夹 -i :询问是否覆盖 -p :保留文件 具体使用方法如下: scp 本地文件路径 用户名@ServerIP:

    2024年02月16日
    浏览(11)
  • linux下tar命令的压缩和解压详细使用方法

    在Linux系统中, tar 命令用于创建、查看、提取和解压 tar 存档文件。以下是 tar 命令的一些常见用法: 压缩文件或目录: 选项说明: -c : 创建新的归档文件 -z : 使用 gzip 格式压缩/解压缩 -j : 使用 bzip2 格式压缩/解压缩 -J : 使用 xz 格式压缩/解压缩 -v : 显示详细信息 -f : 指定归

    2024年04月27日
    浏览(8)
  • linux下下载文件的常用命令wget,curl等使用方法及使用示例

    linux下下载文件的常用命令wget,curl等使用方法及使用示例

    在 Linux 操作系统中,有许多下载文件的工具可供选择。这些工具包括命令行工具和图形界面工具,每个工具都有其自身的特点和用途。以下是一些常用的下载文件工具: wget :一个功能强大的命令行下载工具,支持 HTTP、HTTPS、FTP 等协议,能够断点续传、递归下载等。 curl :

    2024年04月17日
    浏览(12)
  • 【linux命令讲解大全】076.pgrep命令:查找和列出符合条件的进程ID

    根据用户给出的信息在当前运行进程中查找并列出符合条件的进程ID(PID) 补充说明 pgrep 命令以名称为依据从运行进程队列中查找进程,并显示查找到的进程ID。每一个进程ID以一个十进制数表示,通过一个分割字符串和下一个ID分开,默认的分割字符串是一个新行。对于每个

    2024年02月09日
    浏览(21)
  • 深入篇【Linux】学习必备:Shell命令运行原理 + 基本指令

    Linux严格意义上来说是一个操作系统,我们称为\\\"核心\\\",但我们一般用户,是不能直接使用这个\\\"核心\\\"。而是通过\\\"核心\\\"的外壳程序,也就是所谓的Shell来与\\\"核心\\\"沟通。 其实我们所有的指令都要在OS内部运行,但是OS使用的难道太高,我们用户很难直接与OS打交道。 从技术角度

    2024年02月07日
    浏览(6)
  • 【linux命令讲解大全】073.“Linux文件搜索工具:bzgrep和egrep的使用方法“

    使用正则表达式搜索 .bz2 压缩包中的文件。 补充说明 bzgrep 命令用于在 .bz2 压缩包中搜索符合正则表达式的内容,并将匹配的行输出到标准输出。 语法 参数 pattern : 指定要搜索的模式。 bz2_file : 指定要搜索的 .bz2 压缩包。 在文件内查找指定的字符串。 补充说明 egrep 命令用于

    2024年02月09日
    浏览(12)
  • 【linux命令讲解大全】106.使用eject命令退出抽取式设备的方法和选项

    用来退出抽取式设备 eject 命令用来退出抽取式设备。若设备已挂入,则 eject 命令会先将该设备卸除再退出。 eject 允许可移动介质(典型是cd-ROM、软盘、磁带、或者JAZ以及zip磁盘)在软件控制下弹出。该命令也可以控制一些多盘片CD-ROM控制器,控制一些设备支持的自动弹出功

    2024年02月08日
    浏览(10)
  • linux usermod命令、groupmod命令使用方法(bad names(不良名称))(GECOS field(GECOS字段))

    usermod 命令用于修改用户账户的属性。它可以用来修改用户的用户名、用户ID、用户组ID、用户家目录、用户登录Shell等属性。例如,要将用户的登录Shell修改为 /bin/bash ,可以使用以下命令: 其中, username 是要修改的用户的用户名。 翻译: 什么是bad names(不良名称)? \\\"bad n

    2024年02月12日
    浏览(9)
  • java:获取本机IP,Linux环境下使用InetAddress.getLocalHost()方法获得127.0.0.1

    java:获取本机IP,Linux环境下使用InetAddress.getLocalHost()方法获得127.0.0.1

    知道InetAddress.getLocalHost()方法是可以获取本地ip的,但是在mac电脑上执行的时候,偶尔会得到127.0.0.1的输出,这样拿到本地ip很不稳定,感觉就很不靠谱了 代码 mac上输出 在 windows环境 : 使用InetAddress.getLocalHost()方法看似正常能获得本地ip,实际也有不确定性( 多网卡协同工作环

    2024年02月01日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包