如何在 txt 文件中只打印没有路径的文件名
How to print only the filenames without their path in a txt file
Directory_Source/file1,file2,file3,file4
Directory_Target/Combined.txt
我试过了:ls Directory_Source/{file1,file3} > Directory_Target/Combined.txt
但是txt里面的结果是Directory_Source/file1
,.....
然后尝试 ls -d */{file1,file3} > Directory_Target/Combined.txt
,结果相同。
是否可以在不更改命令的情况下实现我所寻求的?我必须提交什么更改。
可能的解决方案:
ls Directory_Source/{file1,file3} | sed 's#.*/##' > Directory_Target/Combined.txt
或
basename -a Directory_Source/{file1,file3} > Directory_Target/Combined.txt
另请参阅 https://superuser.com/q/209937/992527 了解更多解决方案。
Directory_Source/file1,file2,file3,file4
Directory_Target/Combined.txt
我试过了:ls Directory_Source/{file1,file3} > Directory_Target/Combined.txt
但是txt里面的结果是Directory_Source/file1
,.....
然后尝试 ls -d */{file1,file3} > Directory_Target/Combined.txt
,结果相同。
是否可以在不更改命令的情况下实现我所寻求的?我必须提交什么更改。
可能的解决方案:
ls Directory_Source/{file1,file3} | sed 's#.*/##' > Directory_Target/Combined.txt
或
basename -a Directory_Source/{file1,file3} > Directory_Target/Combined.txt
另请参阅 https://superuser.com/q/209937/992527 了解更多解决方案。