在 Linux 中使用 ls 命令列出文件的完整路径 [英] List file using ls command in Linux with full path
问题描述
许多人会发现这是重复的问题,但在问到这个主题之前我已经完成了所有问题,但没有一个对我有用.
Many will found that this is repeating questions but i have gone through all the questions before asked about this topic but none worked for me.
我想使用 ls 命令打印特定文件格式的完整路径名,到目前为止我发现了一段代码,可以打印目录中的所有文件,但不是完整路径.
I want to print full path name of the certain file format using ls command so far i found chunk of code that will print all the files in the directory but not full path.
for i in io.popen("ls /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7"):lines() do
if string.find(i,"%.*$") then
print(i)
end
end
这将打印出根目录和子目录中的所有文件.
this will print out all the file in root diractory and subdiratory.
输出:
0020111118223425.lvf
2012
2012 (2009).mp4
3 Idiots
Aashiqui 2
Agneepath.mkv
Avatar (2009)
Captain Phillips (2013)
Cocktail
我想要输出如下:
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/0020111118223425.lvf [File in Root Directory]
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/2012/2012.mkv
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/2012 (2009).mp4 [File in Root Directory]
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/3 Idiots/3 Idiots.mkv
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Aashiqui 2/Aashiqui 2.mkv
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Avatar (2009)/Avatar (2009).mkv
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Captain Phillips (2013).mkv
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Cocktail/Cocktail.mkv
我已经使用了这一切,但它不适用于我在 LUA 中的代码.
I have used this all but its not working with my code in LUA.
当我使用我的代码时,它显示错误的目录
when I used with my code it displays wrong directory
for i in io.popen("ls -d $PWD/* /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7"):lines() do
if string.find(i,"%.*$") then
print("/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/"..i)
end
end
在/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7"中没有找到文件,插入了机器根目录文件.
is not finding files in "/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7" insted its prints the machines root directory files.
推荐答案
您可以使用
ls -lrt -d -1 "$PWD"/{*,.*}
它还可以捕获隐藏文件.
It will also catch hidden files.
这篇关于在 Linux 中使用 ls 命令列出文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!