linux - 在 unix 中列出给定目录中的文本文件

标签 linux shell unix ubuntu

编写 shell 脚本以在 ubuntu 中使用 for 循环对给定目录中的文本文件数据进行排序:

   echo "Enter directory Name"
   read dr
   path= ` find /home/user -name $dr `
   for x in ` ls *.txt $path ` 
     do
       sort $x
     done
   echo "------Script finished-------"

但是这个脚本给我错误或类似的消息(即使我有文本文件):

   ls: cannot access *.txt: No Such File or Directoy

我认为 ls 命令有问题,是语法错误还是什么?如何列出给定目录路径中的文本文件?

最佳答案

这是一个修改过的例子。我不知道为什么反引号不起作用所以我使用 ():

echo "Enter directory Name"
   read dr
   path=( $(find /home/user -type d -name $dr))
   for x in `ls $path/*.txt`
     do
       sort $x
     done
   echo "------Script finished-------"

关于linux - 在 unix 中列出给定目录中的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38161929/

相关文章:

c++ - GDB:在转储的整个内存中查找值

linux - 使用 AWK 同一列中的数字之间的差异

file - 在 unix 中重命名文件以包含 $ 符号(即 java 类文件)

c++ - Cyassl-2.4.2 缺少 libcyassl.a 文件

string - 更改索引 X 处的字符串 char

linux - Windows 10 上的 Apache Zeppelin 0.7.0 - 解释器问题

c++ - Boost Filesystem 在 Linux 上创建目录,用 "/"替换 "\"

linux - Ubuntu 在输入密码后无法启动

linux - 使用脚本登录从Windows运行Linux的远程脚本

shell - 在 shell 脚本中使用 makefile 变量