LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1020|回复: 2

求一个查找命令

[复制链接]
发表于 2008-11-26 15:09:54 | 显示全部楼层 |阅读模式
想找出linux 目录下目录层次为N的所有文件。

当N为7时,可以看到源码树中对应的文件如下:
(命令:find -mindepth 7 -maxdepth 7)

[root@~/linux-2.6.23.8]#find -mindepth 7 -maxdepth 7
./include/config/x86/acpi/cpufreq/proc/intf.h
./include/config/arch/may/have/pc/fdc.h
./include/config/blk/dev/3w/xxxx/raid.h
./include/config/cpu/freq/default/gov/performance.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_timer_grp_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sw_spu_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_scrc_out_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_fifo_out_extra_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sw_mpu_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_dmc_in_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_fifo_in_extra_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_fifo_in_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sw_cpu_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_mpu_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_reg_space_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_scrc_in_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_dmc_out_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_crc_par_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sap_in_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_version_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_trigger_grp_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sap_out_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_fifo_out_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_spu_defs_asm.h
./include/asm-cris/arch-v32/hwregs/iop/asm/iop_sw_cfg_defs_asm.h

现在可以通过如下方式找出./include/asm-cris/arch-v32/hwregs/iop/asm/目录中的所有文件名:
step1: [root@~/linux-2.6.23.8]#echo "./include/asm-cris/arch-v32/hwregs/iop/asm/" | wc -m
44

step2: 使用cut命令


最终的命令为:
[root@~/linux-2.6.23.8]#find -mindepth 7 -maxdepth 7 | cut -c44-
.h


rmance.h
iop_timer_grp_defs_asm.h
iop_sw_spu_defs_asm.h
iop_scrc_out_defs_asm.h
iop_fifo_out_extra_defs_asm.h
iop_sw_mpu_defs_asm.h
iop_dmc_in_defs_asm.h
iop_fifo_in_extra_defs_asm.h
iop_fifo_in_defs_asm.h
iop_sw_cpu_defs_asm.h
iop_mpu_defs_asm.h
iop_reg_space_asm.h
iop_scrc_in_defs_asm.h
iop_dmc_out_defs_asm.h
iop_crc_par_defs_asm.h
iop_sap_in_defs_asm.h
iop_version_defs_asm.h
iop_trigger_grp_defs_asm.h
iop_sap_out_defs_asm.h
iop_fifo_out_defs_asm.h
iop_spu_defs_asm.h
iop_sw_cfg_defs_asm.h
 楼主| 发表于 2008-11-26 15:11:28 | 显示全部楼层
iop_timer_grp_defs_asm.h
iop_sw_spu_defs_asm.h
iop_scrc_out_defs_asm.h
iop_fifo_out_extra_defs_asm.h
iop_sw_mpu_defs_asm.h
iop_dmc_in_defs_asm.h
iop_fifo_in_extra_defs_asm.h
iop_fifo_in_defs_asm.h
iop_sw_cpu_defs_asm.h
iop_mpu_defs_asm.h
iop_reg_space_asm.h
iop_scrc_in_defs_asm.h
iop_dmc_out_defs_asm.h
iop_crc_par_defs_asm.h
iop_sap_in_defs_asm.h
iop_version_defs_asm.h
iop_trigger_grp_defs_asm.h
iop_sap_out_defs_asm.h
iop_fifo_out_defs_asm.h
iop_spu_defs_asm.h
iop_sw_cfg_defs_asm.h
由上可知./include/asm-cris/arch-v32/hwregs/iop/asm/目录文件打印都是正确的,
但是./include/config/x86/acpi/cpufreq/proc/, ./include/config/x86/acpi/cpufreq/proc/等目录的文件名有些就被cut掉了。。。
(原因是我使用了固定的 cut -c44-, 如何使这个cut 的长度会自动调整呢?)
怎么修改这个命令,可以正确打印出 所有目录的文件呢?
回复 支持 反对

使用道具 举报

发表于 2008-11-26 20:10:43 | 显示全部楼层
试试
  1. find -mindepth 7 -maxdepth 7 -exec basename {} \;
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表