#!/bin/bash
Files=`(find . -type f)`
for f in $Files
do
if [ "$(dirname $f)" != "." ]
then
# these are files in a subdirectory
x=$(dirname $f) #get the name of the file with the directory
y=${x:2} #remove ./ from the name
echo $(basename $f) \($y\)
else
# these are files in the current directory
echo $(basename $f)
fi
done
我很难理解这条线
Files=1(find . -type f)`
表示?它是否找到目录中的每个文件? "输入f"意味着找到每个"文件"类型? 另外,$ f的功能是什么?
我从shell开始,所以任何帮助都会非常有用!
答案 0 :(得分:3)
抱歉,我还没有足够的声誉来添加评论。 Elliott对你的'f'变量名称有正确的答案。要回答你的后续问题,期间的重要性与文件类型无关。
在linux中,'。'代表您的密码或当前工作目录。你的pwd的父目录用'..'表示。 find命令需要提供路径,无论是相对路径还是绝对路径。 '。'通过有效地说“在当前目录(。)和所有子目录中搜索”来实现这一点。查找是自然递归的IIRC。
快乐的黑客攻击!
答案 1 :(得分:2)
请参阅for f in $Files
... $f
引用该for
循环变量。它也可以写成
Files=`(find . -type f)`
for fred in $Files
do
if [ "$(dirname $fred)" != "." ]
then
# these are files in a subdirectory
x=$(dirname $fred) #get the name of the file with the directory
y=${x:2} #remove ./ from the name
echo $(basename $fred) \($y\)
else
# these are files in the current directory
echo $(basename $fred)
fi
done
是的,-type f
表示“文件”。