#!/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的功能是什么?
我是从壳牌开始的,所以任何帮助都会很有帮助!
发布于 2015-12-04 05:04:17
见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
的意思是“文件”。
发布于 2015-12-04 06:43:03
对不起,我还没有足够的声誉来发表评论。埃利奥特对你的“f”变量名有正确的答案。不过,要回答您的后续问题,期间的重要性与文件类型无关。
在linux中,“.”表示您的pwd或当前工作目录。pwd的父目录由“..”表示。find命令要求提供路径,无论是相对路径还是绝对路径。“.”实现这一目标的有效方法是:“在当前目录(.)和所有子目录中搜索”。查找是自然递归的IIRC。
黑客行动愉快!
https://stackoverflow.com/questions/34081194
复制相似问题