od将指定文件内容以八进制数、十进制数、十六进制数、浮点数或ASCII字符的方式输出到标准输出显示

功能说明:od将指定文件内容以八进制数、十进制数、十六进制数、浮点数或ASCII字符方式输出到标准输出显示,并且最左边一列显示字节地址偏移量,从0开始

语  法:od [OPTION…] [FILE…]

补充说明:od命令默认的显示方式是八进制数。常见的文件为文本文件和二进制文件。od命令通常用于显示或查看文件中不能直接显示在终端的字符,主要用来查看保存在二进制文件中的数据,按照指定格式解释文件中的数据并输出,不管是IEEE754格式的浮点数还是ASCII码,od命令都能按照需求输出它们的值。大家也可以了解一下hexdump命令,默认以十六进制数输出数据,但感觉hexdump命令没有od命令强大。

          项:

-A RADIX或–address-radix=RADIX        选择以何种基数表示字节地址偏移量。默认以八进制数显示

-j BYTES或–skip-bytes=BYTES               跳过指定数目的字节

-N BYTES或–read-bytes=BYTES             输出指定字节个数

-S [BYTES]或–strings[=BYTES]               输出长度不小于指定字节数的字符串,BYTES 缺省值为 3

-v或–output-duplicates                               输出时不省略重复的数据

-w [BYTES]或–width[=BYTES]                设置每行最多显示的字节个数,BYTES 缺省为 32 字节

-t TYPE或–format=TYPE                          指定输出格式,格式包括 a、c、d、f、o、u 和 x,各含义如下:

  • a:具名字符。比如换行符显示为 nl
  • c:可打印字符或反斜杠表示的转义字符。比如换行符显示为 \n
  • d[SIZE]:SIZE 字节组成一个有符号十进制整数。SIZE 缺省值为 sizeof(int)
  • f[SIZE]:SIZE 字节组成一个浮点数。SIZE 缺省为 sizeof(double)
  • o[SIZE]:SIZE 字节组成一个八进制整数。SIZE 缺省为 sizeof(int)
  • u[SIZE]:SIZE 字节组成一个无符号十进制整数。SIZE 缺省为 sizeof(int)
  • x[SIZE]:SIZE 字节组成一个十六进制整数。SIZE 缺省为 sizeof(int)

SIZE可以1数字,也可以是大写字母。如果 TYPE 是 [doux] 中的一个,那么SIZE 可以是C = sizeof(char),S = sizeof(short),I = sizeof(int),L = sizeof(long)。如果 TYPE 是 f,那么 SIZE 可以是 F = sizeof(float),D = sizeof(double) ,L = sizeof(long double)

–help           显示帮助信息

–version       显示版本信息

参  数:

FILE…         要显示内容数据的一个或多个文件

   例:

实例1
$ cat test.txt
abcd 12345
$ od test.txt 
0000000 061141 062143 030440 031462 032464 000012
0000013
输出中的第一列是字节地址偏移量,默认以八进制数显示。

实例2
设置第一列的字节偏移地址以十进制显示:
$ od -Ad test.txt 
0000000 061141 062143 030440 031462 032464 000012
0000011

实例3
不显示第一列偏移地址:
$ od -An test.txt 
 061141 062143 030440 031462 032464 000012

实例4
以十六进制数输出,默认以四字节为一组(一列)显示:
$ od -tx test.txt 
0000000 64636261 33323120 000a3534
0000013

实例5
以十六进制数输出,每列输出1个字节:
$ od -tx1 test.txt
0000000 61 62 63 64 20 31 32 33 34 35 0a
0000013

实例6
以具名字符显示ASCII字符:
$ od -ta test.txt
0000000   a   b   c   d  sp   1   2   3   4   5  nl
0000013
以可打印字符或反斜杠表示的转义字符显示ASCII字符:
$ od -tc test.txt
0000000   a   b   c   d       1   2   3   4   5  \n
0000013

实例7
以十六进制数显示的同时显示原字符:
$ od -tcx1 test.txt
0000000   a   b   c   d       1   2   3   4   5  \n
         61  62  63  64  20  31  32  33  34  35  0a
0000013

实例8
指定每行显示512字节:
$ od -w8 -tc test.txt
0000000   a   b   c   d       1   2   3
0000010   4   5  \n
0000013

实例9
实现od命令输出时去除列与列之间的空格符的方法:
1	使用-An不输出偏移地址;
2 使用-v输出时不省略重复的数据;
3 使用-tx1以单个字节为一组按照十六进制输出,-w1每列输出一个字节;
4 最后通过管道传递给 awk 的标准输入,通过awk不换行输出所有行,拼接为一行输出。
$ od -An -w1 -tx1 test.txt|awk '{for(i=1;i<=NF;++i){printf "%s",$i}}'
616263642031323334350a

Linux xargs Command Passes Arguments to Other Commands

Description: xargs is used to pass arguments to other commands and is an essential component for building one-liner commands.

Syntax:
xargs [OPTIONS] [COMMAND]

Overview:
xargs takes input from stdin, separated by spaces or newline characters, and passes it as space-separated arguments to other commands. However, be careful when filenames or strings contain spaces, as xargs may misinterpret them.

Options:

  • -0, --null: Default option. If stdin contains special characters like backticks (), backslashes (\), or spaces, xargs` restores them to regular characters.
  • -a, --arg-file=FILE: Reads input from the specified file instead of stdin.
  • -d, --delimiter=DEL: Specifies the delimiter to separate input. By default, xargs uses spaces and newlines, outputting arguments separated by spaces.
  • -E EOF_STR: Sets an end-of-input string. If none is specified, input has no terminator. EOF_STR must be a separate field (i.e., space or newline separated).
  • -e, --eof[=EOF_STR]: Same as -E, but non-POSIX compliant. Use -E if available.
  • -I REPLACE_STR: Assigns each argument to the specified placeholder (e.g., {}, $, @). Useful for positioning arguments when there are multiple parameters. For example:find . -name "*.txt" | xargs -I {} cp {} /tmp/{}.bak
  • -i, --replace[=REPLACE_STR]: Same as -I, but REPLACE_STR is optional and defaults to {}. Use -I for POSIX compliance.
  • -L MAX_LINES: Limits the number of input lines per execution, implying the -x option.
  • -l, --max-lines[=MAX_LINES]: Same as -L. Defaults to 1 line. Use -L for POSIX compliance.
  • -n, --max-args=MAX_ARGS: Specifies the maximum number of arguments to pass to the command at once.
  • -o, --open-tty: Reopens stdin to /dev/TTY before running the command in a subprocess, useful for interactive applications.
  • -P, --max-procs=MAX_PROCS: Sets the maximum number of parallel processes. Default is 1. Use with -n or -L for batch processing.
  • -p, --interactive: Prompts the user for confirmation before executing each command.
  • --process-slot-var=NAME: Sets an environment variable with a unique value for each running subprocess. Once a process finishes, the value is reused.
  • -r, --no-run-if-empty: Stops xargs from running if there is no input. This is the default behavior.
  • -s, --max-chars=MAX_CHARS: Limits the maximum number of characters (including command, spaces, and newlines) in the command.
  • --show-limits: Displays the system’s command-line length limitations.
  • -t, --verbose: Prints the command to stderr before executing it.
  • -x, --exit: Exits if the command line exceeds the specified character limit (-s).
  • --help: Displays help information.
  • --version: Displays version information.

Parameters:

  • COMMAND: The command string to execute.

Examples:

Example 1
Some commands don’t accept piped arguments directly. Use xargs to pass them:

# Incorrect: `ls` cannot accept piped input directly
find /sbin -perm +700 | ls -l

# Correct: use `xargs` to pass arguments to `ls`
find /sbin -perm +700 | xargs ls -l

Example 2
Show system command-line length limitations:

$ xargs --show-limits

Example 3
Restore shell special characters like backticks:

$ echo '`0123`4 56789' | xargs -t echo

Example 4
Set the delimiter for reading input as a comma:

$ echo 01234 , 56789 | xargs -E ","

Example 5
Solve “argument list too long” errors when working with many files:

# Add a suffix to all files in the current directory
ls | xargs -t -i mv {} {}.bak

Example 6
Set how many lines to pass as arguments at a time:

$ echo -e "01234\n56789\n01234" | xargs -t -L 2 echo

Example 7
Merge multi-line input into a single line:

$ cat test.txt | xargs

Example 8
Kill processes in combination with ps, grep, awk, and kill:

$ ps -ef | grep spp | awk '{printf "%s ",$2}' | xargs kill -9

Linux命令xargs给其他命令传递参数

xargs给其他命令传递参数

功能说明:给其他命令传递参数,是构建单行命令的重要组件之一。

语  法:xargs [OPTIONS] [COMMAND]

补充说明:xargs可以将stdin中以空格或换行符进行分隔的数据,形成以空格分隔的参数(arguments),传递给其他命令。注意,因为以空格作为分隔符,所以有一些文件名或者其他意义的字符串内含有空格的时,xargs可能会误判。

    项:

-0, –null       默认选项。如果输入的stdin含有特殊字符,例如反引号 `、反斜杠 \、空格等字符时,xargs将它还原成一般字符。

-a, –arg-file=FILE    从指定的文件FILE中读取输入内容而不是从stdin

-d, –delimiter=DEL  指定xargs处理输入内容时的分隔符。xargs处理输入内容时默认使用空格和换行符作为分隔符,输出arguments时按空格分隔

-E EOF_STR      EOF_STR的意思是end of file string,表示输入结束的字符串。如果没有EOF_STR则表示输入没有结束符。注意,结束标识符必须要是单独的字段,即以空格或者换行符分隔开来的字段。

-e, –eof[=EOF_STR]       作用等同于-E选项。该选项不符合POSIX标准且EOF_STR是可选的。与-E选项不同时,以-E选项为准。

-I REPLACE_STR    将xargs输出的每一项参数单独赋值给后面的命令,参数需要用指定的替代字符串REPLACE_STR代替。REPLACE_STR可以使用{}、$、@ 等符号,其主要作用是当xargs命令后有多个参数时,用于调整参数位置。例如备份以 txt 为后缀的文件:find . -name “*.txt” | xargs -I {}  cp {} /tmp/{}.bak

-i, –replace[=REPLACE_STR]     作用同 -I 选项,REPLACE_STR是可选的,缺省为 {}。建议使用 -I 选项,因为其符合POSIX标准,而该选项不符合POSIX标准。

-L MAX_LINES        限定最大输入行数。隐含了 -x 选项。

-l, –max-lines[=MAX_LINES]     作用同 -L 选项,MAX_LINES 是可选的,缺省为1。建议使用 -L 选项,因为其符合 POSIX 标准,而该选项不符合POSIX标准。

-n, –max-args=MAX_ARGS         表示命令在执行的时候一次使用参数的最大个数。

-o, –open-tty       在执行命令之前,在子进程中重新打开stdin作为/dev/TTY。如果你希望xargs运行交互式命令行应用程序,这是非常有用的。

-P, –max-procs=MAX_PROCS     每次运行的最大进程数,默认值为1。如果MAX_PROCS为 0,xargs将一次运行尽可能多的进程。一般和-n或-L选项一起使用。

-p, –interactive   每次执行一个argument的时候询问一次用户。

–process-slot-var=NAME       将指定的环境变量设置为每个正在运行的子进程中的唯一值。一旦子进程退出,将重用该值。例如,这可以用于初始负荷分配方案。

-r, –no-run-if-empty         默认选项。当 xargs 的输入为空的时候则停止xargs,不用再去执行后面的命令了。

-s, –max-chars=MAX_CHARS     命令行的最大字符数,指的是xargs后面那个命令的最大字符个数,包括命令字符串本身、空格符和换行符。每个参数单独传入xargs后面的命令。

–show-limits      显示操作系统对命令行长度的限制。

-t, –verbose     先打印要执行的命令到标准错误输出,然后再执行。

-x, –exit              配合 -s 使用,当命令行字符数大于 -s 指定的数值时,退出 xargs。

–help           显示帮助信息并退出。

–version       显示版本信息并退出

    数:

COMMAND       命令字符串

    例:

实例1
很多命令不支持使用管道|来传递参数,此时可以使用xargs来传递参数,例如常用的ls命令:
 # 错误示例,因为标准输入不能作为ls的参数
find /sbin -perm +700 | ls -l
# 正确示例,使用xargs来传递参数
find /sbin -perm +700 | xargs ls -l

实例2
显示操作系统对命令行长度的限制信息:
$ xargs --show-limits
您的环境变量占有 2226 个字节
此系统的参数长度 POSIX 上限: 2092878
所有系统中所允许的最小参数长度 POSIX 上限: 4096
我们实际能用的最大命令长度: 2090652
我们实际能用的命令缓冲区的大小: 131072
最大并行数(--max-procs 不得大于该值):2147483647

设置命令行的最大字符数:
$ echo "01234 56789" | xargs -t -s 11
echo 01234
01234
echo 56789
56789

实例3
将 Shell 的反引号特殊字符还原为一般字符:
$ echo '`0123`4 56789' | xargs -t echo
echo '`0123`4' 56789
`0123`4 56789
其中-t选项的作用是,让xargs先打印要执行的命令到标准错误输出,然后再执行。因为反引号在 Shell 中会将 01234 作为一个命令来执行,但是 01234 不是一个命令。如果直接执行如下命令会报错:
$ echo `0123`4 56789
0123:未找到命令
4 56789

实例4
设置 xargs 读入参数时的结束标识为逗号",":
$ echo 01234 , 56789 | xargs -E ","
01234
注意,结束标识符必须要是单独的字段,即以空格或者换行符分隔开来的字段。

实例5
使用 rm、mv 等命令同时操作多个文件时,有时会报 “argument list too long” 参数列表过长的错误,此时可以使用 xargs 来解决这个错误。xargs 将标准输入的字符串分隔后,作为参数传递给后面的命令。例如:
# 给当前目录的所有文件添加后缀名
ls | xargs -t -i mv {} {}.bak
# 选择符合条件的文件
ls | grep -E "201701|201702|201703" | xargs -I {} mv {} {}.bak

实例6
设置标准输入中每次多少行作为xargs后面的命令的参数:
$ echo -e "01234\n56789\n01234" | xargs -t -L 2 echo
echo 01234 56789 
01234 56789
echo 01234 
01234
默认情况下-L选项的值是1,也就是将标准输入中所有行的归并到一行一次性传给xargs后面的命令执行:
$ echo -e "01234\n56789\n01234" | xargs -t echo
echo 01234 56789 01234
01234 56789 01234

实例7
将文件内容以空格分隔合并为一行输出:
# 列出文件内容
$ cat test.txt
a b c d e
f g h i j 
k l m n o
# 多行输入合并为一行输出
$ cat test.txt | xargs
a b c d e f g h i j k l m n o
# 相当于
$ cat test.txt | xargs echo
a b c d e f g h i j k l m n o

实例8
与ps、grep、awk和kill结合,强制终止指定进程:
$ ps -ef | grep spp | awk '{printf "%s ",$2}' | xargs kill -9
1
其中
ps -ef|grep spp用于查找进程名字或描述信息中包含 spp 子字符串的进程
awk '{printf "%s ",$2}将目标进程 ID 打印输出
xargs kill -9则将目标进程 ID 作为参数传递给kill -9用于杀死进程

Ubuntu22安装PHP8.2的方法

首先更新系统:

sudo apt update && sudo apt upgrade -y

Ondrej sury PPA仓库是目前维护PHP最新版本的仓库,我们添加这个仓库:

sudo add-apt-repository ppa:ondrej/php

再次更新系统以使添加的Ondrej sury PPA仓库生效:

sudo apt update && sudo apt upgrade -y

安装php8.2:

sudo apt install php8.2 -y

安装完成后,检查php的版本:

php --version

使用sudo apt-get install php8.2-PACKAGE_NAME命令安装php常用扩展,把PACKAGE_NAME替换为具体的扩展名:

sudo apt-get install -y php8.2-cli php8.2-common php8.2-fpm php8.2-mysql php8.2-zip php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath

查看已经安装了哪些php扩展:

php -m

参考

https://techvblogs.com/blog/install-php-8-2-ubuntu-22-04

运行yum update更新系统时提示This system is not registered with an entitlement server. You can use subscription-manager to register

这一提示产生原因是什么?当系统安装了RHEL(RedHat)软件仓库时,可能会产生此提示。

如何禁止这一提示?有以下两种方法。

方法一,使用你喜欢的文本编辑器(nano、vi或vim)打开subscription-manager.conf配置文件:

sudo vim /etc/yum/pluginconf.d/subscription-manager.conf

设置enabled配置项的值为0:

enabled=0

保存文件并退出文本编辑器。

方法二,使用Red Hat Subscription Manager工具将RHEL系统注册并订阅到Red Hat客户的门户网站,怎么注册参考https://access.redhat.com/solutions/253273

参考

https://serverfault.com/questions/764900/how-to-remove-this-warning-this-system-is-not-registered-to-red-hat-subscriptio

Linux系统执行sudo node和sudo npm报错找不到命令的解决方法

从官网下载Node.js二进制包,在Linux操作系统里解压安装后,在用户(非root用户)的家目录下的.bashrc文件里,把可执行文件node所在目录(也是npm所在目录)的路径加入PATH环境变量,例如:

export PATH=$PATH:/opt/nodejs/latest/bin

保存后source一下.bashrc文件,让里面的配置生效:

$ source ~/.bashrc

然后即可直接执行node和npm程序,例如:

$ node -v
v16.20.0
$ npm -v
8.19.4

但是执行sudo node xxx和sudo npm xxx还是报错找不到命令:

$ sudo node -v
sudo: node: command not found

解决办法是为node和npm创建符号链接到/usr/bin/目录:

# 先分别打印输出node和npm的绝对路径看看
$ which node
/opt/nodejs/latest/bin/node
$ which npm
/opt/nodejs/latest/bin/npm
# 创建符号链接
$ sudo ln -s /opt/nodejs/latest/bin/node /usr/bin/node
$ sudo ln -s /opt/nodejs/latest/bin/npm /usr/bin/npm

然后执行sudo node xxx和sudo npm xxx就不会报错找不到命令了:

$ sudo node -v
v16.20.0
$ sudo npm -v
8.19.4

Kernel Panic – not syncing VFS Unable to mount root fs on unknown-block(0,0)问题的解决方法

VirtualBox启动CentOS 7虚拟系统时,遇到Kernel Panic – not syncing: VFS: Unable to mount root fs on unknown-block(0,0)问题,无法启动系统。

引起该问题的原因是缺少该内核的初始化文件。

解决方法是从启动界面的GRUB菜单中选择另一个内核来启动系统。进入系统后运行sudo update-initramfs -u -k version为version生成初始化文件(将version替换为内核版本字符串,例如4.15.0-36-generic),然后运行sudo update-grub更新GRUB。

参考

https://askubuntu.com/questions/41930/kernel-panic-not-syncing-vfs-unable-to-mount-root-fs-on-unknown-block0-0