如何写这个命令?
-
- 帖子: 8
- 注册时间: 2010-10-21 19:54
Re: 如何写这个命令?
我知道这样的命令可以这样写
find / -name x | xargs file
还有没有其他的方法??
find / -name x | xargs file
还有没有其他的方法??
-
- 帖子: 133
- 注册时间: 2008-12-12 15:35
Re: 如何写这个命令?
find / -name x -exec file {} \;
-
- 帖子: 8
- 注册时间: 2010-10-21 19:54
Re: 如何写这个命令?
这个命令参数也知道,能不能有一种方法,通过变量传递参数
- bzhao
- 帖子: 250
- 注册时间: 2008-07-05 2:15
- 系统: XUbuntu
Re: 如何写这个命令?
你的意思是这个?zhusongd 写了:这个命令参数也知道,能不能有一种方法,通过变量传递参数
#!/bin/sh
find -name xxx > tmpfile
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
-
- 帖子: 5
- 注册时间: 2010-08-31 1:42
Re: 如何写这个命令?
可以这样。zhusongd 写了:这个命令参数也知道,能不能有一种方法,通过变量传递参数
先定义一个变量 a, 再用a传递参数。
a=`find -name x`; file $a
-
- 帖子: 133
- 注册时间: 2008-12-12 15:35
Re: 如何写这个命令?
上面两楼都不能处理有空格的文件吧
高人指点迷津
高人指点迷津
- bzhao
- 帖子: 250
- 注册时间: 2008-07-05 2:15
- 系统: XUbuntu
Re: 如何写这个命令?
你试试这个!daniel.supremacy 写了:上面两楼都不能处理有空格的文件吧
高人指点迷津
代码: 全选
#!/bin/sh
find -name "xxx yyy"> tmpfile
IFS="\n"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
-
- 帖子: 133
- 注册时间: 2008-12-12 15:35
Re: 如何写这个命令?
麻烦先test再发上来,我把处理结果放这里:bzhao 写了: 你试试这个!代码: 全选
#!/bin/sh find -name "xxx yyy"> tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ls -lh test*
-rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test file
-rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test saf
-rwxr-xr-x 1 daniel daniel 102 2010-10-30 10:46 test.sh
代码: 全选
$ cat test.sh
#!/bin/sh
find -name "test*" > tmpfile
IFS="\n"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
代码: 全选
$ ./test.sh
./test saf
./test file
./test.sh: ERROR: cannot open `./test saf
./test file
./test.sh' (No such file or directory)
这个可以运行
代码: 全选
$ cat test.sh
#!/bin/sh
find -name "test*" > tmpfile
IFS="
"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
代码: 全选
$ ./test.sh
./test saf: empty
./test file: empty
./test.sh: POSIX shell script text executable
- bzhao
- 帖子: 250
- 注册时间: 2008-07-05 2:15
- 系统: XUbuntu
Re: 如何写这个命令?
daniel.supremacy 写了:麻烦先test再发上来,我把处理结果放这里:bzhao 写了: 你试试这个!代码: 全选
#!/bin/sh find -name "xxx yyy"> tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ls -lh test* -rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test file -rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test saf -rwxr-xr-x 1 daniel daniel 102 2010-10-30 10:46 test.sh
代码: 全选
$ cat test.sh #!/bin/sh find -name "test*" > tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
============编辑的封个先==============代码: 全选
$ ./test.sh ./test saf ./test file ./test.sh: ERROR: cannot open `./test saf ./test file ./test.sh' (No such file or directory)
这个可以运行代码: 全选
$ cat test.sh #!/bin/sh find -name "test*" > tmpfile IFS=" " for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ./test.sh ./test saf: empty ./test file: empty ./test.sh: POSIX shell script text executable
我的IFS="\n"是work的, 这个可能是sh的版本引起的:
我的系统是 Ubuntu10.04
#ls /bin/sh
lrwxrwxrwx 1 root root 4 2010-10-30 12:12 /bin/sh -> bash
$sh --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
你用的是什么系统? 什么shell?
-
- 帖子: 6548
- 注册时间: 2008-10-31 22:12
- 系统: 践兔
- 联系:
- szl1997
- 帖子: 292
- 注册时间: 2009-11-24 14:12