Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 使用 ls -F 與 grep 快速篩選可執行檔案與目錄

編輯:關於 Linux

需在目錄中快速找出所有可執行檔案或子目錄?ls -F 配合 grep 即可輕鬆實現。

指令語法

# 找可執行檔 (以 * 結尾)
ls -F | grep "\*"

# 找目錄 (以 / 結尾)
ls -F | grep "/$"
# 或
ls -F | grep "/"
# 需轉義時
ls -F | grep "\/"

原理解析

  • ls -F 為各類型檔案加上標識:* 可執行、/ 目錄、@ 符號連結、= socket 等。
  • | 管道將前一命令輸出傳給 grep 過濾。
  • grep "/$" 匹配以 / 結尾的行,即目錄。

實際輸出範例

[root@SOR_SYS ~]# ls -F
1.sh* CC_manual_0701.rar gzpackage/ man.config script/ tr1.txt
2005.03.01 dead.letter index.html ntpd-deploy.sh* start_tomcatServer229-1.sh tr.txt
anaconda-ks.cfg Desktop/ install.log printc.sh start_tomcatServer229-2.sh usr/
apache-tomcat-6.0.30.zip etc/ install.log.syslog rpmpackage/ stop_tomcatServer229-1.sh zy/
camptocamp-tomcat-0.0.1/ get_date.sh lib/ ruby-1.8.7-p248/ stop_tomcatServer229-2.sh zy.bak/

此技巧無需 find 即可快速分類列表,極大提升終端操作效率。

Copyright © Windows教程網 All Rights Reserved