在Linux中,使用循环获取文件名可以通过以下几种方式实现:
for file in /path/to/directory/*; do if [[ -f "$file" ]]; then # 只处理文件,排除目录 echo "$file" fi done find /path/to/directory -type f -exec basename {} \; ls -p /path/to/directory | grep -v /$ 在上述示例中,/path/to/directory 是要遍历的目录路径,可以根据自己的需要进行替换。这些命令将打印出目录中的所有文件名。你可以根据自己的需求在循环中对文件名进行进一步的处理。