shell递归遍历所有文件|linux shell 命令怎么遍历目录

|

Ⅰ xshell里面怎么遍历文件夹里面所有数据

grep "you want" *附加点说明,*就是匹配当前目录下的所有文件,如果下一级目录就是*/*

Ⅱ 在linux shell(bash)编程中,如何通过递归方式遍历文件

写一个函数,函数的参数是目录路径字符串函数内使用 ls -s dir_path , 然后for 遍历循环如果是目录则继续调用自身如果是文件则答应文件名从执行优化的角度来讲,可以把判断目录还是文件的代码放在循环外层. 好久没写shell了 ,我这也没环境测试 , 只能给个思路,函数的具体写法自己找一下资料吧.另外,find命令可以直接完成你要做的事.

Ⅲ 如何用shell脚本遍历指定目录下的文件,并按后缀名分类

脚本1:#!/bin/bash##cd /tmp/scriptcfile=` find -name '*.c' `hfile=` find -name '*.h' `for fc in $cfiledocfname=`basename -s .c $fc`cat $fc >/tmp/scripttest/$cfname.txtdonefor fh in $hfiledocp $fh /tmp/scripttestdone

Ⅳ 如何用shell遍历一个目录下的所有子目录

1、find . -type d2、ls -l |grep ^d3、find . -type d -exec echo {} \;4、find . -type d |xargs ls -l

Ⅳ 在windows中用shell遍历一个文件夹下得所有文件并对文件执行同一个指令

你的for循环中循环的是$PATH ,他只是代表这个路径,并不表示里面的文件名。

Ⅵ shell怎么遍历一个文件夹下所有文件

# find . -type f./a./normal/log-1./normal/log-2./normal/log-3通过find找到文件那么遍历就用循专环for i in `属find . -type f`do echo $idone

Ⅶ shell 遍历目录中所有文件 改名

#!来/bin/bashbase_dir=$(dirname$0)fordirin$(ls$base_dir);docurrent_dir="$base_dir/$dir"if[!-d$current_dir];thencontinuefiforold_file_namein$(ls$current_dir);doold_file="$current_dir/$old_file_name"if[!-f$old_file];thencontinuefinew_file_name="$current_dir/${old_file_name}_${dir}"mv$old_file$new_file_namedonedone

改名的部分帮你写了,放源到把脚本放到你说的有好多目录的那个目录里执行就可以了

数据库的部分自己想吧

Ⅷ 用shell层级遍历dir目录,统计文件总数量、总大小,并按扩展名分类统计各种文件的数目、总大小。

#!/bin/bashfunctiondirectory(){forfilein$(ls$1)dobasepath="$1/$file"if[-d"$basepath"];thenecho"|-directory:$file"$(-h$basepath|cut-f1)directory$basepathelif[-f"$basepath"];thenecho"|–file:$file"$(-h$basepath|cut-f1)fidone}directory$1调用方法:./testfind.sh你要遍历的路径我只是简单的写了一个,大致功能的思想如此,你也可以在此基础上进行扩展,不过好像应该有现成的,你网上搜一搜吧。。

Ⅸ linux shell 命令怎么遍历目录

先设定实验环境:# 造 5 个 目录,每个目录下,造 3 个 文件和两个子目录如下:cd $HOME/tmpfor i in d1 d2 d3 d4 d5do mkdir -p $i touch $i/1.txt $i/2.txt $i/3.txt mkdir -p $i/tmp1 $i/tmp2done# 检验测试环境:$ ls -lR d1total 0-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 1.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 2.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 3.txtdrwxr-sr-x 2 wenlee comm 256 Dec 22 10:35 tmp1/drwxr-sr-x 2 wenlee comm 256 Dec 22 10:35 tmp2/# 利用下列脚本来实现你要做的:cd $HOME/tmpfor i in */1.txtdo echo "Found $i, save $i and remove everything else under $(dirname $i)/" save_this_file=$(basename $i) curr_dir=$(dirname $i) # 把这个1.txt暂时存到/tmp里面去,为了避免已经有同样的档案名称在/tmp,加上$$ (i.e. PID) mv $i /tmp/${save_this_file}.$$ rm -rf $curr_dir mkdir -p $curr_dir mv /tmp/${save_this_file}.$$ $curr_dirdone# 屏幕执行输出如下:Found d1/1.txt, save d1/1.txt and remove everything else under d1/Found d2/1.txt, save d2/1.txt and remove everything else under d2/Found d3/1.txt, save d3/1.txt and remove everything else under d3/Found d4/1.txt, save d4/1.txt and remove everything else under d4/Found d5/1.txt, save d5/1.txt and remove everything else under d5/# 复验实验环境:$ ls -l d?/*-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 d1/1.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 d2/1.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 d3/1.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 d4/1.txt-rw-r–r– 1 wenlee comm 0 Dec 22 10:35 d5/1.txtOK?thanks!

Ⅹ 解决shell脚本遍历带空格的文件/文件夹名

在做iOS Flutter依赖引入的时候,需要去遍历Pods 工程中的文件,而这个工程下刚好有一个名称带空格的文件夹。如下:

如下的脚本会出问题:

原因是,执行 ls 命令的时候,文件夹名称带了空格,被当成了分隔符。

网上查了一下相关资料,都是说把分隔符修改掉,使用时再改回来。于是脚本变成了这样:

但是这样还会有问题,我们知道 $1 是获取第一个参数,那么在名称带空格的文件夹递归入参时,又会因为空格的问题变成两个参数。那问题就变成:把过个参数变成一个参数。答案就是: $* 。 此外还需要特别注意的是,每一个引用带空格的文件或者文件夹名称时必须带上引号,才能成为一个整体。 最终脚本如下:

如果解决了你的问题,玛法点个赞或者留言,让我知道你来过。


赞 (0)