【问题标题】:How to make wc work recursively WITHOUT FIND如何使 wc 在没有 FIND 的情况下递归工作
【发布时间】:2018-11-07 14:05:02
【问题描述】:

我想计算文件中的字母。他们处于不同的层次。 我用过

wc -m `ls -R`

但是,它仅适用于当前目录中的文件。我需要列出完整路径或扩展 wc 范围。

我尝试过使用

ls -d -1 $PWD/*

正如其他几个答案所暗示的那样,但它绝不是递归的。它打印的级别与使用 /* /* /* 键入的级别一样多。它不是通用的。

【问题讨论】:

  • find 有什么问题?
  • 还有哪些路径和文件名中带有空格以及下游命令中的所有other really good reasons to never use the output of ls
  • 我不知道这里是否允许,但这是我在课堂上收到的作业。我一个月前做了所有事情,除了这个。我不反对 find 但我的老师说“我们不在这里使用 find。尝试实验”。这就是我不能向他展示我的作品的唯一原因。

标签: linux recursion ls wc


【解决方案1】:

我不知道你为什么不想使用find,但是使用zsh你可以这样做:

 wc -l prometheus/**/*.{yml,json}                                                                                                                                                 
     9 prometheus/prometheus/alertmanager/config.yml
   104 prometheus/prometheus/docker-compose.yml
   103 prometheus/prometheus/docker-prometheus.dockerapp/docker-compose.yml
    99 prometheus/prometheus/docker-stack.yml
    11 prometheus/prometheus/grafana/provisioning/dashboards/dashboard.yml
    50 prometheus/prometheus/grafana/provisioning/datasources/datasource.yml
    66 prometheus/prometheus/prometheus/prometheus.yml
   114 prometheus/prometheus/pwd-stack.yml
    30 prometheus/prometheus.yml
   614 prometheus/prometheus/dashboards/Grafana_Dashboard.json
  1237 prometheus/prometheus/dashboards/Grafana_Dashboard_prom_2.json
   749 prometheus/prometheus/dashboards/System_Monitoring.json
   689 prometheus/prometheus/Grafana_Dashboard.json
   712 prometheus/prometheus/Grafana Dashboard With Service.json
  1581 prometheus/prometheus/grafana/provisioning/dashboards/Docker Prometheus Monitoring-1533038455876.json
   258 prometheus/prometheus/HighLoadDashboard.json

【讨论】:

  • 抱歉,我的工作环境是 bash。我绝对想使用 find。但是我的老师完全反对。当我向他询问提示时,他让我离开并说“尝试试验”。
  • 我刚刚发现腻子支持你所说的。谢谢你治好了我的头痛。
猜你喜欢
  • 2018-01-10
  • 2020-05-04
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 2022-12-06
  • 1970-01-01
  • 2017-05-28
  • 1970-01-01
相关资源
最近更新 更多