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 / 问题

问题[head](unix)

Martin Hope
John Smith
Asked: 2021-09-28 06:21:52 +0800 CST

我手动移除了“head” - 如何重新安装它?[复制]

  • 0
这个问题在这里已经有了答案:
删除了 /usr/bin/touch 和 /bin/touch。现在似乎无法安装任何东西,也无法创建任何文件? (3 个回答)
去年关闭。

似乎 几个月前我已经手动从我的头部移除了。/usr/bin/现在我有机会需要它,我没有它。如何在不重新安装整个发行版的情况下重新安装它?我的环境:Ubuntu 20.04 LTS 桌面。

ubuntu head
  • 1 个回答
  • 231 Views
Martin Hope
Rick T
Asked: 2019-12-12 10:22:09 +0800 CST

使用存储在变量中的文件名的头部的语法[重复]

  • 0
这个问题在这里已经有了答案:
如何将命令的输出分配给 shell 变量? (3 个回答)
2年前关闭。

我正在尝试将文件中的前 5 行存储在变量中url。但我得到一个错误

-n5: command not found

fn_all_urls存储文件的路径/home/urls.txt

我的线路是:

url=head -n5 ${fn_all_urls} #get first 5 lines in file
echo "$url"

我在 Ubuntu 18.04 64 位上使用 bash

bash head
  • 1 个回答
  • 1926 Views
Martin Hope
Felix Dombek
Asked: 2019-08-22 06:08:35 +0800 CST

如何查看文件夹文件中的第 17 行(或最后一行,如果更少)?

  • 8

我目前正在使用

watch head -n 17 *

这有效,但也显示所有行到第 17 行。基本上,我只想显示以我当前的方法显示的每个文件的最后一行。我怎样才能做到这一点?

例子

为了举例,让我们减少行 nr。到 7. 所以:

示例文件:

1
2
3
4
5
6
7
8

这一行:

watch head -n 7 *

输出

1
2
3
4
5
6
7

我想要的地方:

7
bash head
  • 3 个回答
  • 1344 Views
Martin Hope
Stucksnet
Asked: 2019-01-19 22:57:34 +0800 CST

是否可以运行 head 并使用 nl 对行进行编号?

  • 1

当我运行head file.txt && nl file.txt它时,它按出现的顺序执行每个命令(这是有道理的)。是否可以让头部显示带有编号的行,以便:

word
word
word

会变成这样:

1 word
2 word
3 word
head nl
  • 1 个回答
  • 193 Views
Martin Hope
user306023
Asked: 2018-09-06 14:21:01 +0800 CST

为什么“head -1”与“head -n -1”不等价,而是与“head -n 1”相同?

  • 3

head -numhead -n num与而不是相同head -n -num(其中num是任何数字)

例子:

$ echo -e 'a\nb\nc\nd'|head -1
a

$ echo -e 'a\nb\nc\nd'|head -n 1
a

$ echo -e 'a\nb\nc\nd'|head -n -1
a
b
c

这head -1似乎没有记录在任何地方。

$ head --help

Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]NUM       print the first NUM bytes of each file;
                             with the leading '-', print all but the last
                             NUM bytes of each file
  -n, --lines=[-]NUM       print the first NUM lines instead of the first 10;
                             with the leading '-', print all but the last
                             NUM lines of each file
  -q, --quiet, --silent    never print headers giving file names
  -v, --verbose            always print headers giving file names
  -z, --zero-terminated    line delimiter is NUL, not newline
      --help     display this help and exit
      --version  output version information and exit

NUM may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/head>
or available locally via: info '(coreutils) head invocation'

head(在 Fedora 28 上) 的手册页:

HEAD(1)                          User Commands                         HEAD(1)

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

DESCRIPTION
       Print  the  first  10 lines of each FILE to standard output.  With more
       than one FILE, precede each with a header giving the file name.

       With no FILE, or when FILE is -, read standard input.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -c, --bytes=[-]NUM
              print  the  first  NUM bytes of each file; with the leading '-',
              print all but the last NUM bytes of each file

       -n, --lines=[-]NUM
              print the first NUM lines instead of  the  first  10;  with  the
              leading '-', print all but the last NUM lines of each file

       -q, --quiet, --silent
              never print headers giving file names

       -v, --verbose
              always print headers giving file names

       -z, --zero-terminated
              line delimiter is NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

       NUM may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000,
       M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for  T,  P,
       E, Z, Y.

AUTHOR
       Written by David MacKenzie and Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report head translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2017  Free Software Foundation, Inc.  License GPLv3+: GNU
       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free  to  change  and  redistribute  it.
       There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       tail(1)

       Full documentation at: <https://www.gnu.org/software/coreutils/head>
       or available locally via: info '(coreutils) head invocation'

GNU coreutils 8.29               December 2017                         HEAD(1)
linux head
  • 1 个回答
  • 8537 Views
Martin Hope
Pedro A
Asked: 2018-09-06 07:57:18 +0800 CST

当我没有可用的 `-z` 选项时,如何执行等效的 `head -z`?

  • 2

我需要head -z一个脚本(题外话,但可以在这个问题中找到动机),但在我的 CoreOS 835.13.0 中我得到了head: invalid option -- 'z'.

完整head --help输出:

Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]K         print the first K bytes of each file;
                             with the leading '-', print all but the last
                             K bytes of each file
  -n, --lines=[-]K         print the first K lines instead of the first 10;
                             with the leading '-', print all but the last
                             K lines of each file
  -q, --quiet, --silent    never print headers giving file names
  -v, --verbose            always print headers giving file names
      --help     display this help and exit
      --version  output version information and exit

K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report head translation bugs to <http://translationproject.org/team/>
For complete documentation, run: info coreutils 'head invocation'

有趣的是,最后一行告诉我要运行info coreutils 'head invocation',但我得到了info: command not found.

coreutils head
  • 1 个回答
  • 388 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