码迷,mamicode.com
首页 > 其他好文 > 详细

重要命令知识

时间:2019-01-19 13:11:43      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:方法   一个   结果   位置   --   size   ext   定义   语法   

ls命令

例题 查找过滤出目录     

方法1 命令  ls -l|grep "^d"     方法2  ls -F |grep "/$"  方法3  find ./ -type d -maxdepth 1       -maxdepth  查深度查当前目录不带子目录

方法4  ls -l|awk ‘{if ($2>1) print $0}‘            $2是指第2列 默认以空格为分割符   $0是指输出整行

ls -l  显示该目录下的文件和目录   输出结果以d开头的就是目录,还可以根据颜色区分目录和文件

ls -F 给目录后面加标识 -pg给目录结尾加斜线 通过以斜线结尾的来过滤出目录 

还可以使用find -tpye d 查找目录 

root@luo-X550WE:/oldboy# ls -F |grep "\$"
1.txt
a
alex
b
c.txt
ext/
jinjiao
test/
text/
xiaodong/
xiaofan/
xiaojiayu
xingfujie/
root@luo-X550WE:/oldboy# ls -F |grep "/$"
ext/
test/
text/
xiaodong/
xiaofan/
xingfujie/
root@luo-X550WE:/oldboy# find -type d
.
./text
./test
./test/dir3
./test/dir2
./test/dir1
./xiaofan
./xingfujie
./ext
./ext/oldboy
./xiaodong
root@luo-X550WE:/oldboy# find ./ -type d
./
./text
./test
./test/dir3
./test/dir2
./test/dir1
./xiaofan
./xingfujie
./ext
./ext/oldboy
./xiaodong
root@luo-X550WE:/oldboy# find ./ -type d --maxdeph 1
find: 未知的断言“--maxdeph”
root@luo-X550WE:/oldboy# find ./ -type d --maxdepth 1
find: 未知的断言“--maxdepth”
root@luo-X550WE:/oldboy# find ./ -type d --maxdepth l
find: 未知的断言“--maxdepth”
root@luo-X550WE:/oldboy# find ./ -type d -maxdepth l
find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

find: 本应对 -maxdepth 使用一个十进制的正整数作为参数,但却使用了 ‘l’
root@luo-X550WE:/oldboy# find ./ -type d -maxdepth 1
find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

./
./text
./test
./xiaofan
./xingfujie
./ext
./xiaodong
root@luo-X550WE:/oldboy# ls -l|awk {if ($2>1) print $0}
bash: 未预期的符号 `(‘ 附近有语法错误
root@luo-X550WE:/oldboy# ls -l|awk ‘{if ($2>1) print $0}‘
总用量 28
drwxr-xr-x 3 root root 4096 1月  19 11:17 ext
drwxr-xr-x 5 root root 4096 1月  10 18:47 test
drwxr-xr-x 2 root root 4096 1月   6 20:45 text
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaodong
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaofan
drwxr-xr-x 2 root root 4096 1月  19 11:17 xingfujie
root@luo-X550WE:/oldboy# ls -l|grep "^d"
drwxr-xr-x 3 root root 4096 1月  19 11:17 ext
drwxr-xr-x 5 root root 4096 1月  10 18:47 test
drwxr-xr-x 2 root root 4096 1月   6 20:45 text
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaodong
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaofan
drwxr-xr-x 2 root root 4096 1月  19 11:17 xingfujie
root@luo-X550WE:/oldboy# ls -F |grep "/$"
ext/
test/
text/
xiaodong/
xiaofan/
xingfujie/
root@luo-X550WE:/oldboy# find ./ -type d -maxdepth 1
find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

./
./text
./test
./xiaofan
./xingfujie
./ext
./xiaodong
root@luo-X550WE:/oldboy# ls -l|awk ‘{if ($2>1) print $0}‘
总用量 28
drwxr-xr-x 3 root root 4096 1月  19 11:17 ext
drwxr-xr-x 5 root root 4096 1月  10 18:47 test
drwxr-xr-x 2 root root 4096 1月   6 20:45 text
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaodong
drwxr-xr-x 2 root root 4096 1月  19 11:17 xiaofan
drwxr-xr-x 2 root root 4096 1月  19 11:17 xingfujie

  

重要命令知识

标签:方法   一个   结果   位置   --   size   ext   定义   语法   

原文地址:https://www.cnblogs.com/ls-king/p/10291347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!