我不想像标准 awk 配方那样将表格数据转换为漂亮的列。我希望将一些很长的文本格式化为像报纸专栏这样的专栏。
例如转
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempus orci ut odio tincidunt, vel hendrerit ante viverra. Aenean mollis ex erat, ac commodo lectus scelerisque eget. Aenean sit amet purus felis. Aenean sit amet erat eget velit lobortis fermentum eget eget odio. Donec tincidunt rutrum varius. Nunc viverra ac erat id bibendum. Aenean sit amet venenatis arcu. Morbi enim enim, pulvinar sed velit in, sollicitudin tristique urna. In auctor ex vel diam sagittis, at placerat …
Run Code Online (Sandbox Code Playgroud) 是否可以使用 输出完整的命令名称lsof -nP -i4UDP
?
我一直在手册中寻找合适的选项,例如-V
(见下文),但它不会产生全COMMAND
名,即systemd-resolve
显示为systemd-r
:
$ sudo lsof -V -nP -i4UDP
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
avahi-dae 437 avahi 12u IPv4 12982 0t0 UDP *:5353
avahi-dae 437 avahi 14u IPv4 12984 0t0 UDP *:45006
cups-brow 449 root 7u IPv4 12149 0t0 UDP *:631
systemd-r 485 systemd-resolve 12u IPv4 14694 0t0 UDP 127.0.0.53:53
systemd-r 485 systemd-resolve 13u IPv4 14695 0t0 UDP *:5355
dhclient 629 root 6u IPv4 …
Run Code Online (Sandbox Code Playgroud) 我在编写期望脚本时遇到困难。我想做一些相当于以下 bash 指令的事情:
iplist=$(cat iplist.txt)
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用set
我所知道的所有方法,但仍然不起作用。还有其他方法还是只是我没有以正确的方式使用它?
set iplist=$(cat iplist.txt)
Run Code Online (Sandbox Code Playgroud) 我正在编写一个程序来将一个命令传递给另一个命令。输入将来自命令行:
$ ./a.out ls '|' wc
c2 PID 6804
c1 PID 6803
PARENT PID 6802
$ 2 2 17
Run Code Online (Sandbox Code Playgroud)
为什么在提示返回后输出打印。有什么办法可以防止吗?
这是我写的代码:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char * argv[])
{
if(argc <= 1 )
{
printf("ERROR: No arguments passed\n");
printf("USAGE: ./pipe <command 1> | <command 2>\n");
return 1;
}
char * cmd1[50];
char * cmd2[50];
int cmd1_arg = 0;
int cmd2_arg = 0;
int pipe_num = 0;
for(int cla = 1; cla<argc; …
Run Code Online (Sandbox Code Playgroud) 我在 linux (ubuntu) 中使用 Microsoft 的 dotnet,它具有拨号家庭遥测功能。我想禁用它,说明说:
.NET Core 工具收集使用数据以帮助我们改善您的体验。数据是匿名的,不包括命令行参数。数据由 Microsoft 收集并与社区共享。您可以通过使用您喜欢的 shell 将 DOTNET_CLI_TELEMETRY_OPTOUT 环境变量设置为“1”或“true”来选择退出遥测。
我读过.profile
,.bashrc
,.bash_profile
,/etc/environment
,等,在被读取后,他们的差异,如果在所有。
所以我不知道该放在DOTNET_CLI_TELEMETRY_OPTOUT=1
哪里?我希望它始终被加载,无论我是否在没有桌面的情况下登录、使用桌面登录、远程 ssh 登录、启动终端、从父终端启动终端等。
我应该把它放在哪个文件(或多个文件)中?我将如何为所有用户执行此操作?
是否有命令或系统调用用于列出当前打开的所有抽象 unix 套接字?
更新:有人建议我使用netstat -x
,理论上可行,但不会列出抽象套接字的名称,仅列出那些带有路径的名称。
bash-5.0$ netstat -xeW
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] STREAM CONNECTED 3959158
unix 2 [ ] STREAM CONNECTED 3961068
unix 3 [ ] STREAM CONNECTED 3965008
unix 3 [ ] STREAM CONNECTED 3967192 /run/spire/writable/agent.sock
Run Code Online (Sandbox Code Playgroud) 我有带日期的文件:
Mar 16
Mar 12
Mar 13
Mar 19
Mar 14
Mar 17
Run Code Online (Sandbox Code Playgroud)
我需要计算到现在为止已经过去的天数。我来了这个功能:
datediff() {
d1=$(date -d "$1" +%s);
d2=$(date -d "$2" +%s);
echo $(( (d1 - d2) / 86400 )) days;
}
$ datediff 'now' '13 Mar'
114 days
Run Code Online (Sandbox Code Playgroud)
但我需要一些循环来计算每一行
我使用以下命令为 IPC 编写了以下代码pipe()
:
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
int main(void) {
char message_buffer[15] = "Hello World \n";
char read_buffer[15];
int fd[2];
int return_value = pipe(fd);
if (return_value < 0) {
printf("Error creating the pipe");
}
int rc = fork();
if (rc < 0) {
printf("Error forking a child");
}
if (rc > 0) {
close(fd[0]);
write(fd[1], message_buffer, 15);
close(fd[1]);
wait(NULL);
} else {
close(fd[1]);
read(fd[0], read_buffer, 15);
close(fd[0]);
printf("The Message: %s", read_buffer);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我是管道新手,我有以下问题: …
这是我写的代码。我需要一个简单的代码,使用 if elif 来检查读取的字符是大写、小写还是特殊符号。
echo "enter a char"
read c
if [[ $c == [A-Z] ]];
then
echo "upper"
elif [[ $c == [a-z] ]];
then
echo "lower"
else
echo "Digit or special symbols!"
fi
Run Code Online (Sandbox Code Playgroud)
以下是我输入字符后收到的输出
enter a char
A
upper
enter a char
a
Digit or special symbols!
aravind@bionic-beaver:~/Desktop$ ./1.sh
enter a char
1
Digit or special symbols!
Run Code Online (Sandbox Code Playgroud) linux ×4
bash ×3
shell-script ×3
c ×2
pipe ×2
command-line ×1
exec ×1
expect ×1
files ×1
login ×1
lsof ×1
scripting ×1
shell ×1
ubuntu ×1
unix-sockets ×1