LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: liuzz

如何只查看当前目录下的隐藏文件?

[复制链接]
发表于 2005-4-7 10:30:50 | 显示全部楼层
使用grep也行哦,
不过楼上的用法:
1,显示包括了. 和 ..
2,只使用/$无效

隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p'  或  ls -AF|grep -ve "/$"
隐藏文件
ls -Ap|sed '/\/$/d'              或   ls -AF|grep -e "^\..*/$"
回复 支持 反对

使用道具 举报

发表于 2005-4-7 12:23:41 | 显示全部楼层
首先
  1. zhyfly@zhyfly:~$ ls -Ap
  2. bash/           .gnome/            .nautilus/
  3. .bash_history   .gnome2/           orderwiz.ami
  4. .bash_profile   .gnome2_private/   .recently-used
  5. .bashrc         .gstreamer-0.8/    .thumbnails/
  6. Desktop/        .gtkrc-1.2-gnome2  ttf-fireflysung_1.0.0-1_i386.deb
  7. .dmrc           .ICEauthority      .viminfo
  8. .fcitx/         Linux命令大全.chm  .Xauthority
  9. .fonts.cache-1  mbox               .xsession-errors
  10. .gconf/         .metacity/
  11. .gconfd/        .mozilla/
  12. zhyfly@zhyfly:~$
复制代码

根据版主
隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p' 或 ls -AF|grep -ve "/$"

第一个满足要求:
  1. zhyfly@zhyfly:~$ ls -Ap|sed -ne '/^\..*\/$/p'
  2. .fcitx/
  3. .gconf/
  4. .gconfd/
  5. .gnome/
  6. .gnome2/
  7. .gnome2_private/
  8. .gstreamer-0.8/
  9. .metacity/
  10. .mozilla/
  11. .nautilus/
  12. .thumbnails/
  13. zhyfly@zhyfly:~$
复制代码

第二个命令不满足要求:
  1. zhyfly@zhyfly:~$ ls -AF|grep -ve "/$"
  2. .bash_history
  3. .bash_profile
  4. .bashrc
  5. .dmrc
  6. .fonts.cache-1
  7. .gtkrc-1.2-gnome2
  8. .ICEauthority
  9. Linux命令大全.chm
  10. mbox
  11. orderwiz.ami
  12. .recently-used
  13. ttf-fireflysung_1.0.0-1_i386.deb
  14. .viminfo
  15. .Xauthority
  16. .xsession-errors
  17. zhyfly@zhyfly:~$
复制代码

然后
隐藏文件
ls -Ap|sed '/\/$/d' 或 ls -AF|grep -e "^\..*/$"

第一个命令不满足要求:
  1. zhyfly@zhyfly:~$ ls -Ap|sed '/\/$/d'
  2. .bash_history
  3. .bash_profile
  4. .bashrc
  5. .dmrc
  6. .fonts.cache-1
  7. .gtkrc-1.2-gnome2
  8. .ICEauthority
  9. Linux命令大全.chm
  10. mbox
  11. orderwiz.ami
  12. .recently-used
  13. ttf-fireflysung_1.0.0-1_i386.deb
  14. .viminfo
  15. .Xauthority
  16. .xsession-errors
  17. zhyfly@zhyfly:~$
复制代码

第二个命令满足要求:
  1. zhyfly@zhyfly:~$ ls -AF|grep -e "^\..*/$"
  2. .fcitx/
  3. .gconf/
  4. .gconfd/
  5. .gnome/
  6. .gnome2/
  7. .gnome2_private/
  8. .gstreamer-0.8/
  9. .metacity/
  10. .mozilla/
  11. .nautilus/
  12. .thumbnails/
  13. zhyfly@zhyfly:~$
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-4-7 12:31:24 | 显示全部楼层
隐藏目录:
  1. zhyfly@zhyfly:~$ ls -Ap
  2. bash/           .gnome/            .nautilus/
  3. .bash_history   .gnome2/           orderwiz.ami
  4. .bash_profile   .gnome2_private/   .recently-used
  5. .bashrc         .gstreamer-0.8/    .thumbnails/
  6. Desktop/        .gtkrc-1.2-gnome2  ttf-fireflysung_1.0.0-1_i386.deb
  7. .dmrc           .ICEauthority      .viminfo
  8. .fcitx/         Linux命令大全.chm  .Xauthority
  9. .fonts.cache-1  mbox               .xsession-errors
  10. .gconf/         .metacity/
  11. .gconfd/        .mozilla/
  12. zhyfly@zhyfly:~$ ls -Ap|awk '/^\..*\/$/'
  13. .fcitx/
  14. .gconf/
  15. .gconfd/
  16. .gnome/
  17. .gnome2/
  18. .gnome2_private/
  19. .gstreamer-0.8/
  20. .metacity/
  21. .mozilla/
  22. .nautilus/
  23. .thumbnails/
  24. zhyfly@zhyfly:~$
复制代码

隐藏文件:
  1. zhyfly@zhyfly:~$ ls -Ap
  2. bash/           .gnome/            .nautilus/
  3. .bash_history   .gnome2/           orderwiz.ami
  4. .bash_profile   .gnome2_private/   .recently-used
  5. .bashrc         .gstreamer-0.8/    .thumbnails/
  6. Desktop/        .gtkrc-1.2-gnome2  ttf-fireflysung_1.0.0-1_i386.deb
  7. .dmrc           .ICEauthority      .viminfo
  8. .fcitx/         Linux命令大全.chm  .Xauthority
  9. .fonts.cache-1  mbox               .xsession-errors
  10. .gconf/         .metacity/
  11. .gconfd/        .mozilla/
  12. zhyfly@zhyfly:~$ ls -Ap|awk '$1~/^\./&&$1!~/\/$/'
  13. .bash_history
  14. .bash_profile
  15. .bashrc
  16. .dmrc
  17. .fonts.cache-1
  18. .gtkrc-1.2-gnome2
  19. .ICEauthority
  20. .recently-used
  21. .viminfo
  22. .Xauthority
  23. .xsession-errors
  24. zhyfly@zhyfly:~$
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-4-7 16:06:10 | 显示全部楼层
呵呵,兄弟细心,我上面的位置颠倒了:p

隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p' 或 ls -AF|grep -ve "/$"
隐藏文件
ls -Ap|sed '/\/$/d' 或 ls -AF|grep -e "^\..*/$"

隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p' 或  ls -AF|grep -e "^\..*/$"

但是隐藏文件 ls -AF|grep -ve "/$" 是有问题的
这个好像可以
ls -Ap|grep -e "^\..*[^/]$"
回复 支持 反对

使用道具 举报

发表于 2005-4-8 00:19:11 | 显示全部楼层
Post by aaccdd

隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p' 或  ls -AF|grep -e "^\..*/$"

但是隐藏文件 ls -AF|grep -ve "/$" 是有问题的
这个好像可以
ls -Ap|grep -e "^\..*[^/]$"

这次都对了
  1. zhyfly@zhyfly:~$ ls -Ap
  2. bash/           .gnome/            .nautilus/
  3. .bash_history   .gnome2/           orderwiz.ami
  4. .bash_profile   .gnome2_private/   .recently-used
  5. .bashrc         .gstreamer-0.8/    .thumbnails/
  6. Desktop/        .gtkrc-1.2-gnome2  ttf-fireflysung_1.0.0-1_i386.deb
  7. .dmrc           .ICEauthority      .viminfo
  8. .fcitx/         Linux命令大全.chm  .Xauthority
  9. .fonts.cache-1  mbox               .xsession-errors
  10. .gconf/         .metacity/
  11. .gconfd/        .mozilla/
  12. zhyfly@zhyfly:~$ ls -Ap|grep -e '^\..*[^/]$'
  13. .bash_history
  14. .bash_profile
  15. .bashrc
  16. .dmrc
  17. .fonts.cache-1
  18. .gtkrc-1.2-gnome2
  19. .ICEauthority
  20. .recently-used
  21. .viminfo
  22. .Xauthority
  23. .xsession-errors
  24. zhyfly@zhyfly:~$
复制代码
但是隐藏文件 ls -AF|grep -ve "/$" 是有问题的

是的,
  1. zhyfly@zhyfly:~$ ls -Ap|grep -ve "/$"
  2. .bash_history
  3. .bash_profile
  4. .bashrc
  5. .dmrc
  6. .fonts.cache-1
  7. .gtkrc-1.2-gnome2
  8. .ICEauthority
  9. [b]Linux命令大全.chm[/b]
  10. [b]mbox[/b]
  11. [b]orderwiz.ami[/b]
  12. .recently-used
  13. [b]ttf-fireflysung_1.0.0-1_i386.deb[/b]
  14. .viminfo
  15. .Xauthority
  16. .xsession-errors
复制代码

其中
  1. -v, --invert-match
  2.               Invert the sense of matching, to select non-matching lines.
复制代码
可见,-v选项是相反匹配,只要不是以/结尾就满足,而非隐藏文件就也满足这个要求,所以不对,改正以后的对了.
回复 支持 反对

使用道具 举报

发表于 2007-6-25 12:13:42 | 显示全部楼层
Post by aaccdd
呵呵,兄弟细心,我上面的位置颠倒了:p


隐藏目录
ls -Ap|sed -ne '/^\..*\/$/p' 或  ls -AF|grep -e "^\..*/$"

但是隐藏文件 ls -AF|grep -ve "/$" 是有问题的
这个好像可以
ls -Ap|grep -e "^\..*[^/]$"

嗯,这个是正确的。
今天考试红旗Linux用户基础,第一题就是这个题目。、
我当时没有做对。
虽然是老帖,仍然要回复一下。
回复 支持 反对

使用道具 举报

发表于 2007-6-26 00:07:52 | 显示全部楼层
find . -maxdepth 1  -type f  -name '.*'  

偶自己都看着麻烦。。郁闷。

(晕死,才发现是。。2年前的帖子!!!)
回复 支持 反对

使用道具 举报

发表于 2007-6-27 14:45:21 | 显示全部楼层
有点区别:find命令中的-type

  1. -type c
  2.               File is of type c:

  3.               b      block (buffered) special

  4.               c      character (unbuffered) special

  5.               d      directory

  6.               p      named pipe (FIFO)

  7.               f      regular file

  8.               l      symbolic link; this is never true if the -L option or the
  9.                      -follow option is in effect, unless the symbolic link  is
  10.                      broken.  If you want to search for symbolic links when -L
  11.                      is in effect, use -xtype.

  12.               s      socket

  13.               D      door (Solaris)
复制代码

如果如楼主所说“隐藏文件”,并未指明究竟是何种文件,用-type f会忽略掉某些类型文件,如链接文件。
回复 支持 反对

使用道具 举报

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

本版积分规则

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