AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[io-redirection](unix)

Martin Hope
Ben
Asked: 2025-01-09 00:37:30 +0800 CST

为什么这个显示输出:ls 1>/dev/null | less

  • 5

如果我这样做:ls 1>/dev/null那么正如预期的那样,屏幕上没有输出,因为它已被重定向到 /dev/null 但是,如果我这样做,ls 1>/dev/null | less我会看到当前目录的文件列表。 怎么做?!?

io-redirection
  • 1 个回答
  • 31 Views
Martin Hope
ron
Asked: 2024-07-19 03:53:41 +0800 CST

tcsh 仅将 stderr 管道化为 null,而将 stdout 保留原样

  • 5

tcsh在 RHEL-8.10 中运行。

做了之后grep -l <something> *我得到了很多Is a directory回应。

在 bash 中我会 grep -l <something> * 2>/dev/null抑制这一点。

tcsh 中的等效语法是什么?

io-redirection
  • 1 个回答
  • 10 Views
Martin Hope
lylklb
Asked: 2024-06-26 20:58:06 +0800 CST

对部分标准输出在过渡期内重新定向的质疑

  • 3

如何保留过渡期间的完整 stdout 输出?
如下面典型的例子,你可以看到 yum 元数据刷新状态不会重定向到其 yr.log。
所以我的问题是如何在过渡期间保留这些输出。

# 
# yum  -v repolist
Not loading "rhnplugin" plugin, as it is disabled
Not loading "product-id" plugin, as it is disabled
Loading "refresh-packagekit" plugin
Loading "security" plugin
Not loading "subscription-manager" plugin, as it is disabled
Config time: 0.015
Yum Version: 3.2.29
RHEL_6.4_x86-64                                    | 3.9 kB     00:00 ... 
RHEL_6.4_zlocal                                    | 2.9 kB     00:00 ... 
Setting up Package Sacks
pkgsack time: 0.012
Repo-id      : RHEL_6.4_x86-64
Repo-name    : RHEL_6.4_x86-64_dvd_all
Repo-revision: 1359576928
Repo-updated : Thu Jan 31 04:22:56 2013
Repo-pkgs    : 3,648
Repo-size    : 3.2 G
Repo-baseurl : file:///mnt/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 08:26:11 2024)

Repo-id      : RHEL_6.4_zlocal
Repo-name    : RHEL_6.4_x86-64_dvd_zlocal
Repo-revision: 1715738735
Repo-updated : Wed Mar 31 17:26:56 2021
Repo-pkgs    : 3,720
Repo-size    : 3.2 G
Repo-baseurl : file:///install/rhel_6.4_x86_64/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 08:26:11 2024)

repolist: 7,368
# 
# 
# 
# yum -v repolist 1> /tmp/yr.log 2> /tmp/yr.err
# 
# 
# cat /tmp/yr.log
Not loading "rhnplugin" plugin, as it is disabled
Not loading "product-id" plugin, as it is disabled
Loading "refresh-packagekit" plugin
Loading "security" plugin
Not loading "subscription-manager" plugin, as it is disabled
Config time: 0.069
Yum Version: 3.2.29
Setting up Package Sacks
pkgsack time: 0.712
Repo-id      : RHEL_6.4_x86-64
Repo-name    : RHEL_6.4_x86-64_dvd_all
Repo-revision: 1359576928
Repo-updated : Thu Jan 31 04:22:56 2013
Repo-pkgs    : 3,648
Repo-size    : 3.2 G
Repo-baseurl : file:///mnt/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 15:24:26 2024)

Repo-id      : RHEL_6.4_zlocal
Repo-name    : RHEL_6.4_x86-64_dvd_zlocal
Repo-revision: 1715738735
Repo-updated : Wed May 15 10:06:56 2024
Repo-pkgs    : 3,720
Repo-size    : 3.2 G
Repo-baseurl : file:///install/rhel_6.4_x86_64/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 15:24:27 2024)

repolist: 7,368
# 
io-redirection
  • 1 个回答
  • 54 Views
Martin Hope
Alex Alex
Asked: 2024-06-19 01:44:56 +0800 CST

运行几个相同的进程,然后杀死其中一个

  • 5

问题:需要运行多个进程,尤其是“tail -f log.log >> wrile_log.log”进程来收集日志。可以针对同一日志文件在不同时间运行命令。这不是问题,但是……我如何终止其中一个进程而不中断另一个进程?

io-redirection
  • 1 个回答
  • 24 Views
Martin Hope
Carter
Asked: 2023-12-11 14:20:07 +0800 CST

如何将输出重定向到名称为当前日期和时间以及当前目录名称的文件?

  • 5

我正在尝试使用 xterm 中的当前工作目录进行重定向。

xterm -ls -geometry 80x30 -e 'cd /home/work/test1/; pwd; make | tee test1.log;'
xterm -ls -geometry 80x30 -e 'cd /home/work/temp/test2/; pwd; make | tee test2.log;'
xterm -ls -geometry 80x30 -e 'cd /home/work/tmp/test3/; pwd; make | tee test3.log;'
xterm -ls -geometry 80x30 -e 'cd /home/work/my_test4/; pwd; make | tee my_test4.log;'
xterm -ls -geometry 80x30 -e 'cd /home/work/append/my_test5/; pwd; make | tee my_test5.log;'
...

我想将输出重定向到一个文件,该文件的名称是当前日期和时间以及 xterm 中当前的最后一个目录名称。

for example).
xterm -ls -geometry 80x30 -e 'cd /home/work/append/my_test5/; pwd; make | tee my_test5_03:19:12-11-2023.log;'

如何将输出重定向到一个文件,该文件的名称是xterm中的当前日期和时间以及当前目录名称?

io-redirection
  • 1 个回答
  • 46 Views
Martin Hope
LWC
Asked: 2023-11-27 18:36:24 +0800 CST

您能否使 nohup.out 仅在出现错误时创建,而不手动指定文件名?

  • 4

您可以使(在后台nohup ./file $1 $2 &运行)仅创建错误而不创建标准输出吗?./filenohup.out

但请不要手动指定nohup.outie

nohup ./file $1 $2 >/dev/null 2>nohup.out &

此外,以下状态nohup: redirecting stderr to stdout和重定向既不输出也不重定向错误。我认为这是因为它告诉它将错误重定向到输出,但输出被重定向到 /dev/null:

nohup ./file $1 $2 >/dev/null &
io-redirection
  • 1 个回答
  • 28 Views
Martin Hope
mifrey
Asked: 2023-11-12 07:22:50 +0800 CST

在标准输出上打印并使用记录器记录

  • 6

我有一个 bash 脚本,其中包含几个“echo STRING”命令。我想用记录器记录 STRING,但仍将其打印在标准输出上。echo STRING | logger显然不这样做。

编辑:echo STRING | tee >(logger)做到了。>(COMMAND) 是一个进程替换,它替换进程的输入。

io-redirection
  • 2 个回答
  • 38 Views
Martin Hope
Thad_The_Man
Asked: 2023-08-13 13:24:42 +0800 CST

将 stderr 重定向到 stdout 到脚本中的文件

  • 6

我有几种不同的算法,我需要对其进行原型设计。

所以我制作了原型程序和脚本。调用的脚本time.sh看起来像这样

echo "Timing algorithm1:"
time algo1 >dev/null

echo "Timing algorithm2:"
time algo2 >dev/null

echo "Timing algorithm3:"
time algo3 >dev/null

...

现在为了简单起见,替换ls为algo1...(我不想为每个算法发布代码,强迫人们编译它...)

echo " Timing ls"
time ls 2>&1 > /dev/null

叫它time_ls.sh

那我就做

sh time_ls.sh > ls_sh.meas

无论我做什么,无论我在脚本或命令行中放置什么重定向,我都会得到两个结果之一。我要么在终端中得到 echo 的输出,即“Timing ls”,要么得到ls_sh.meas相反的定时数据。

这就像 stdout 和 stderr 不想聚集在一起并创建一个婴儿数据文件。

任何人都可以解释这种奇怪的行为,并建议解决方法吗?

PS:这是在 bash 中完成的。

io-redirection
  • 3 个回答
  • 45 Views
Martin Hope
elbarna
Asked: 2023-06-03 03:33:23 +0800 CST

如何删除这个烦人的消息?

  • 9

简单的问题,我运行这个命令

ss -tulpnoea|grep -i water|grep -v 127
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
.....

我试过 2> /dev/null ...

 ss -tulpnoea|grep -i water|grep -v 127 2> /dev/null
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    .....

如何避免有关 cgroup2 mount 的烦人消息?发行版是 Slackware 15.0

io-redirection
  • 1 个回答
  • 563 Views
Martin Hope
markfree
Asked: 2022-11-08 15:55:28 +0800 CST

绑定错误重定向失败 - 挖掘

  • 6

我正在尝试针对域名测试一些名称服务器。为此,我创建了一个脚本来读取名称服务器列表并请求域名。

像这样基本的东西:

#!/bin/bash

domain=$1
[ -z $domain ] && read -p "DOMAIN NAME: " domain

namefile="./nameserver"

echo "RESULT -  NAMESERVER              DOMAIN                  IP"

for host in $(cat "$namefile"); do
        IPADD=$(dig +short "$host" "$domain" A 2> /dev/null)

        [[ ! -z $IPADD ]] && result="OK" || result="FAIL"

        echo "$result   - Nameserver: $host     - Domain: $domain       - IP answer: $IPADD"
done

我遇到的问题是,当Dig失败时,它不会将错误重定向到null. 因此,$IPADD变量接收到错误的值。

# CORRECT nameserver
# dig +short @8.8.8.8 google.com A 2> /dev/null
142.250.218.206

# WRONG nameserver
# dig +short @8.8.8.80 google.com A 2> /dev/null
;; connection timed out; no servers could be reached

如果我使用错误的名称服务器地址对其进行测试,我仍然会收到一条错误消息,如上所示。

据我了解,重定向到 时null,它不应显示该错误消息。

任何想法?

谢谢你。

io-redirection
  • 1 个回答
  • 33 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve