这与这个问题类似,但是我想包含相对于unix中当前目录的路径。如果我这样做:

ls -LR | grep .txt

它不包括完整路径。例如,我有如下的目录结构:

test1/file.txt
test2/file1.txt
test2/file2.txt

上面的代码将返回:

file.txt
file1.txt
file2.txt

如何使用标准Unix命令让它包含相对于当前目录的路径?


当前回答

要使用find命令获得所需文件的实际完整路径文件名,请使用pwd命令:

find $(pwd) -name \*.txt -print

其他回答

在我的情况下,使用树命令

相对路径

tree -ifF ./dir | grep -v '^./dir$' | grep -v '.*/$' | grep '\./.*' | while read file; do
  echo $file
done

绝对路径

tree -ifF ./dir | grep -v '^./dir$' | grep -v '.*/$' | grep '\./.*' | while read file; do
  echo $file | sed -e "s|^.|$PWD|g"
done
DIR=your_path
find $DIR | sed 's:""$DIR""::'

'sed'将从所有'find'结果中删除'your_path'。你接收相对于DIR路径的。

你可以用find代替:

find . -name '*.txt'

您可以像这样实现此功能 首先,使用ls命令指向目标目录。稍后使用find命令过滤它的结果。 从你的情况来看,文件名总是以单词开头 * * * . txt的文件

ls /some/path/here | find . -name 'file*.txt'   (* represents some wild card search)

如果你想保留详细信息,如文件大小等在你的输出,那么这应该工作。

sed "s|<OLDPATH>|<NEWPATH>|g" input_file > output_file