标签: shell

如何使 git show --stat 仅列出更改、插入和删除的文件数?

我使用以下 Git 命令来获取有关特定提交的数据:

  git show <revhash> --stat >> ouput.csv
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出:

  commit 7bc745a289cf68cb2eba647bbfba9e9ec06eb771
  Author: Stefan Bodewig <bodewig@apache.org>
  Date:   Mon Jun 24 15:12:57 2013 +0000

post-process generated javadocs as workaround for CVE-2013-1571 - based on Maven patch by Uwe Schindler - PR 55132

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1496083 13f79535-47bb-0310-9956-ffa450edef68

   CONTRIBUTORS                                       |   1 +
   WHATSNEW                                           |   9 ++
   contributors.xml                                   |   4 +
   manual/Tasks/javadoc.html                          |  12 +++
   .../org/apache/tools/ant/taskdefs/Javadoc.java     | 111 ++++++++++++++++++++-
   .../ant/taskdefs/javadoc-frame-injections-fix.txt  |  37 +++++++
   6 files changed, 171 insertions(+), 3 deletions(-)
Run Code Online (Sandbox Code Playgroud)

我想通过以下方式在没有其他元数据的情况下更改文件列表:

  1 file changed, 1 …
Run Code Online (Sandbox Code Playgroud)

git bash shell terminal

3
推荐指数
1
解决办法
3543
查看次数

`chmod` 不适用于 Dockerfile (macbook)

我目前正在开发一个Dockerfile,它要求我拥有对两个特定文件夹进行读取、写入和执行的权限。当需要运行命令时chmod,它就会失败。我可以在 docker 容器内手动更改权限,但它似乎没有从命令中获取它。这是目前的样子:

FROM <image-source>
SHELL ["/bin/bash", "-c"]
USER root
WORKDIR /bla/bla
COPY . .
CMD chmod 777 -R /src/main/*
CMD chmod 777 -R /app/main/*
Run Code Online (Sandbox Code Playgroud)

shell docker dockerfile devops

3
推荐指数
1
解决办法
2411
查看次数

Bash 通过多字符分隔符将多行字符串拆分为数组

我在这里搜索了类似的主题,但大多数问题都包含单字符分隔符。

我有这个文本样本:

Some text here,
continuing on next lineDELIMITERSecond chunk of text
which may as well continue on next lineDELIMITERFinal chunk
Run Code Online (Sandbox Code Playgroud)

所需的输出是一个列表 ( extracted=()),其中包含:

  1. Some text here, continuing on next line
  2. Second chunk of text which may as well continue on next line
  3. Final chunk

从示例中可以看出,“DELIMITER”用作分割分隔符。

我在 SO 上尝试了许多示例,包括 awk、替换等。

bash shell awk

3
推荐指数
1
解决办法
2304
查看次数

如何使用空格和逗号连接行

我的文件包含以下内容:

IP
111
22
25
Run Code Online (Sandbox Code Playgroud)

我想以 格式打印输出IP 111,22,25。

我已经尝试过tr ' ' ,,但不起作用

bash shell awk cut tr

3
推荐指数
1
解决办法
2944
查看次数

用于从 CSV 文件中删除列的 Shell 脚本命令

我正在尝试从 csv 文件中删除一列(我从预处理中将其作为变量获取)。

我查看了提供的示例并尝试了以下方法

cut -d ',' -f 2 X.csv > Y.csv
Run Code Online (Sandbox Code Playgroud)

上面的命令没有帮助 - X.csv 中的第二列被复制到 Y.csv

我希望将第二列与分隔符一起删除

例如:

name,place,animal
a,chicago,python
b,new york,squirrel
Run Code Online (Sandbox Code Playgroud)

使用 cut 命令后,文件应如下所示

name,animal
a,python
b,squirrel
Run Code Online (Sandbox Code Playgroud)

bash shell

3
推荐指数
1
解决办法
3863
查看次数

USB 2.0 和 USB 3.0:如何确定 USB 端口的版本并将其与 USB 驱动器匹配

我需要将 USB 端口的版本与 USB 驱动器进行匹配。

例如,我想确保版本为 3.0 的 USB 驱动器通过 USB 3.0 端口连接到计算机。

我有一个想法,但我不知道如何实施。

因此,当我将 USB 驱动器连接到计算机时,我可以使用 lsusb 获取有关该驱动器的信息,但是我可以使用什么命令来查明 USB 驱动器连接到 USB 端口 2.0 还是 USB 端口 3.0?

谁能帮我解决这个问题吗?

外壳编程

shell

3
推荐指数
1
解决办法
7297
查看次数

如何获取 ls 命令的前 n 行

ls命令按行输出结果:

AndroidSandbox/                    kotlin-native-intellij/
arc-theme-macos/                   kotlin-native-sandbox/
BobkoLauncher/                     kotlin-ref-delegation/
...
Run Code Online (Sandbox Code Playgroud)

如何获取n此输出的第一行?ls | head -n 2不起作用,因为它需要两个第一个文件,但我需要两个第一行输出。

bash shell zsh

3
推荐指数
1
解决办法
6745
查看次数

Psycopg2 操作错误:无法连接到服务器:没有这样的文件或目录

尝试在 python shell 中连接到 postgresql 但遇到了一些问题。

我正在使用适用于 Linux 的 Windows 子系统。我尝试将端口更改为 5433 而不是 5432。并尝试设置 host="/tmp/"。这些都不起作用。

我尝试运行这个。

>>> import psycopg2
>>> conn = psycopg2.connect(dbname="postgres", user="postgres")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)

数据库“postgres”出现在数据库列表中:

                              List of databases
   Name    |  Owner   | Encoding | …
Run Code Online (Sandbox Code Playgroud)

python postgresql shell psycopg2

3
推荐指数
1
解决办法
2万
查看次数

linux下用户名太长如何显示完整用户名

在我的项目中,我想在 Linux 服务器的进程中选择用户名或用户 ID

\n\n

我使用的命令如下:

\n\n
ps aux | grep -v root\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到了一些这样的内容:

\n\n
mae-wan+  34325 99.7  0.5 1717096 1056124 ?     Rl   Apr18 1533:33 ./turb\nmae-wan+  34326 99.7  0.5 1717128 1057284 ?     Rl   Apr18 1533:35 ./turb\nmae-wan+  34327 99.7  0.5 1716992 1056860 ?     Rl   Apr18 1533:41 ./turb\nmae-wan+  34328 99.7  0.5 1717244 1056644 ?     Rl   Apr18 1533:43 ./turb\nmae-wan+  34329 99.7  0.5 1717100 1054616 ?     Rl   Apr18 1533:43 ./turb\nmae-wan+  34330 99.5  0.5 1717100 1057640 ?     Rl   Apr18 1530:33 ./turb\n
Run Code Online (Sandbox Code Playgroud)\n\n

第一列是:

\n\n …

shell

3
推荐指数
1
解决办法
6380
查看次数

在 UNIX 时间戳 Shell/Bash 中将日期与时区转换

我需要将日期从格式为“yyyy/mm/dd hh:mm:ss TZ”的字符串转换为 UNIX 时间(TZ = 时区)。

\n\n

到目前为止我所做的是将没有时区的“yyyy/mm/dd hh:mm:ss”格式的日期转换为时间戳

\n\n
dateYMD="2019/2/28 12:23:11.46"\nnewt=$(date -d "${dateYMD}" +"%s")\necho ${newt}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到以下结果。

\n\n
1551349391\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的努力是找到如何将时区和日期/时间转换为时间戳(unix time)。例如,我需要 4 个与 dateYMD 具有相同日期/时间但位于 4 个不同时区的变量,以便它们的时间戳会不同。

\n\n

这是我尝试过的最新版本

\n\n
dateYMD="2017/09/09 08:58:09"\ntimez=$(TZ=Australia/Sydney date -d @$(date +%s -d "${dateYMD}"))\nunixTimez=$( date --date "${timez}" +"%s" )\necho ${unixTimez}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这向我显示了以下错误

\n\n
   date: invalid date \xe2\x80\x98\xd1\x87\xd1\x82 \xd1\x84\xd0\xb5\xd0\xb2 28 21:23:11 AEDT 2019\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

unix linux bash shell

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

shell ×10

bash ×6

awk ×2

cut ×1

devops ×1

docker ×1

dockerfile ×1

git ×1

linux ×1

postgresql ×1

psycopg2 ×1

python ×1

terminal ×1

tr ×1

unix ×1

zsh ×1