在 Linux 中,你可以使用多种命令来获取目录下的所有文件名。以下是几种常用的方法:
使用 ls 命令:
ls
ls /path/to/directory
使用 ls 命令配合通配符 *:
.txt 文件:ls *.txt
使用 find 命令:
find /path/to/directory -type f
find /path/to/directory -maxdepth 1 -type f
使用 ls 和 grep 组合:
grep 过滤特定类型的文件:ls | grep '\.txt$'
使用 ls 和 awk 组合:
ls -l | awk 'NR>1 {print $9}'
使用 for 循环遍历:
for 循环来遍历目录下的所有文件:for file in /path/to/directory/*
do
echo $file
done
选择适合你需求的方法即可。如果你需要更复杂的文件筛选或处理,find 命令通常是最强大的工具。