ls命令是Linux系统中最常用的命令之一,相信ls命令一定是你进入Linux系统电脑打开命令提示符后**的第一个命令使用。我们每天都频繁使用ls命令,即使我们可能没有意识到,也从未使用过所有可用选项。在本文中,我们将讨论一些基本的ls命令并尽可能多地介绍相关参数。Linux的ls命令1.不带任何选项的列出文件不带选项的ls命令赤裸裸地列出文件和目录,我们看不到文件类型、大小、修改日期和时间、权限和链接信息等细节。#ls0001.pcapDesktopDownloadsindex.htmlinstall.log.syslogPicturesTemplatesanaconda-ks.cfgDocumentsfbcmd_update.phpinstall.logMusicPublicVideos2用-l选项列出文件列表可以看到,ls-l(-l是字母不是“1”)可以显示是否是文件或目录,其大小、修改日期和时间、文件或目录的名称以及文件的所有者及其权限。#ls-ltotal176-rw-r--r--.1rootroot683Aug1909:590001.pcap-rw------.1rootroot1586Jul3102:17anaconda-ks.cfgdrwxr-xr-x.2rootroot4096Jul3102:48Desktopdrwxr-xr-x.2Jrootulroot40926:48Documentsdrwxr-xr-x.4rootroot4096Aug1602:55Downloads-rw-r--r--.1rootroot21262Aug1212:42fbcmd_update.php-rw-r--r--.1rootroot46701Jul3109:58index.html-rw-r--r--。1rootroot48867Jul3102:17install.log-rw-r--r--.1rootroot11439Jul3102:13install.log.syslogdrwxr-xr-x.2rootroot4096Jul3102:48Musicdrwxr-xr-x.2rootroot4096Jul3102:48Picturesdrwxr-xr-x.2rootroot4096Jul3102:48Publicdrwxr-xr-x.2rootroot4096Jul3102:48Templatesdrwxr-xr-x.2rootroot4096Jul3102:48Videos3.浏览隐藏文件列出所有文件,包括以“.”开头的隐藏文件。#ls-a..bashrcDocuments.gconfdinstall.log.nautilus.pulse-cookie...cacheDownloads.gnome2install.log.syslog.netstat.swp.recently-used.xbel0001.pcap.config.elinks.gnome2_private.kde.opera。spice-vdagentanaconda-ks.cfg.cshrc.esd_auth.gtk-bookmarks.libreofficePictures.tcshrc.bash_history.dbus.fbcmd.gvfs.local.pkiTemplates.bash_logoutDesktopfbcmd_update.php.ICEauthority.mozillaPublicVideos.bash_profile.digrc.htmlgwireshark4。使用-lh选项以人类可读的方式列出文件使用-lh组合选项以人类可读的方式显示大小。#ls-lhtotal176K-rw-r--r--.1rootroot683Aug1909:590001.pcap-rw------.1rootroot1.6KJul3102:17anaconda-ks.cfgdrwxr-xr-x.2rootroot4.0KJul3102:48Desktopdrwxr-xr-x.2rootroot4.0KJul3102:48Documentsdrwxr-xr-x.4rootroot4.0KAug1602:55Downloads-rw-r--r--.1rootroot21KAug1212:42fbcmd_update.php-rw-r--r--.1rootroot46KJul3109:58index.html-rw-r--r--.1rootroot48KJul3102:17install.log-rw-r--r--.1rootroot12KJul3102:13install.log.syslogdrwxr-xr-x.2rootroot4.0KJul3102:48Musicdrwxr-xr-x.2rootroot4.0KJul3102:48Picturesdrwxr-xr-x.2rootroot4.0KJul3102:48Publicdrwxr-xr-x.2rootroot4.0KJul3102:48Templatesdrwxr-xr-x.2rootroot4.0KJul3102:48Videos5。使用ls命令列出带有尾随“/”字符的文件和目录-F选项将在每个目录的末尾添加一个“/”字符。#ls-F0001.pcapDesktop/Downloads/index.htmlinstall.log.syslogPictures/Templates/anaconda-ks.cfgDocuments/fbcmd_update.phpinstall.logMusic/Public/Videos/6。倒序列出文件ls-r选项可以倒序显示文件和目录。#ls-rVideosPublicMusicinstall.logfbcmd_update.phpDocumentsanaconda-ks.cfgTemplatesPicturesinstall.log.syslogindex.htmlDownloadsDesktop0001.pcap7。递归列出子目录ls-R选项可以列出非常长的目录树,请参见示例输出:#ls-Rtotal1384-rw------.1rootroot33408Aug817:25anaconda.log-rw------.1rootroot30508Aug817:25anaconda.program.log./httpd:total132-rw-r--r--1rootroot0Aug1903:14access_log-rw-r--r--.1rootroot61916Aug1017:55access_log-20120812./lighttpd:total68-rw-r--r--1lighttpdlighttpd7858Aug2115:26access.log-rw-r--r--.1lighttpdlighttpd37531Aug1718:21access.log1901208/nginx:total12-rw-r--r--.1rootroot0Aug1203:17access.log-rw-r--r--。1rootroot390Aug1203:17access.log-20120812.gz8。以修改时间的倒序列出与-ltr组合的选项文件或目录可以按其最后修改时间的顺序显示。#ls-ltrtotal176-rw-r--r--.1rootroot11439Jul3102:13install.log.syslog-rw-r--r--.1rootroot48867Jul3102:17install.log-rw------.1rootroot1586Jul3102:17anaconda-ks.cfgdrwxr-xr-x.2rootroot4096Jul3102:48Desktopdrwxr-xr-x.2rootroot4096Jul3102:48Videosdrwxr-xr-x.2rootroot4096Jul3102:48Templatesdrwxr-xr-x.2rootroot4096Jul3102:48Publicdrwxr-xr-x.2rootroot4096Jul3102:48Picturesdrwxr-xr-x.2rootroot4096Jul3102:48Musicdrwxr-xr-x.2rootroot4096Jul3102:48Documents-rw-r--r--.1rootroot46701Jul3109:58index.html-rw-r--r--.1rootroot21262Aug1212:42fbcmd_update.phpdrwxr-xr-x.4rootwroot5loads-rwroot4096Aug-Down--r--.1rootroot683Aug1909:590001.pcap9。按文件大小排序加上-lS组合选项可以按从大到小的顺序显示文件。#ls-lStotal176-rw-r--r--.1rootroot48867Jul3102:17install.log-rw-r--r--.1rootroot46701Jul3109:58index.html-rw-r--r--.1rootroot21262Aug1212:42fbcmd_update.php-rw-r--r--.1rootroot11439Jul3102:13install.log.syslogdrwxr-xr-x.2rootroot4096Jul3102:48Desktopdrwxr-xr-x.2rootroot4096Jul3102:48Documentsdrwxr-xr-x.4rootroot4096Aug1602:55Downloadsdrwxr-xr-x.2rootroot4096Jul3102:48Musicdrwxr-xr-x.2rootroot4096Jul3102:48Picturesdrwxr-xr-x.2rootroot4096Jul3102:48Publicdrwxr-xr-x.2rootroot4096Jul3102:48Templatesdrwxr-xr-x.2rootroot4096Jul3102:48Videos-rw------Video-2w-08:463root15--.1root1586Jul31086Jul3:r--r--.1rootroot683Aug1909:590001.pcap10。显示文件或目录的索引节点号。有时我们会看到在文件或目录名前打印一些数字,可以用-i选项节点号列出文件或目录的索引。#ls-i201120001.pcap23610文件23793index.html23611音乐23597模板23564anaconda-ks.cfg23595下载22安装.log23612图片23613视频23594桌面23585fbcmd_update.php35install.log1.syslog2?1.php35install.log1.syslog2显示ls命令的版本查看ls命令的版本。#ls--versionls(GNUcoreutils)8.4Copyright(C)2010FreeSoftwareFoundation,Inc.LicenseGPLv3+:GNUGPLversion3orlater
