将某个目录下的 文件(字符窜) 只将数字过滤出来
[root@localhost test]# pwd /data/soft/test [root@localhost test]# ls 10.txt 1.txt 2.tx 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 脚本内容: dir="/data/soft/test/*" for i in $dir;do b=`echo "$i" | tr -cd "[0-9]"` echo "$b" done 运行结果: [root@localhost ~]# sh test.sh 10 1 2 2 3 4 5 6 7 8 9