ls命令

作用:列举目录文件信息( list directory content )

格式:ls [option] [file]

1,命令不跟任何选项与目录,表示列举当前目录的文件信息 

ghostwu@dev:~$ ls
Desktop examples.desktop linux Pictures python Videos
Documents git_test Music project software
Downloads info php Public Templates

2,ls -l 使用长格式列举文件和目录信息

ghostwu@dev:~$ ls -l
total
drwxr-xr-x ghostwu ghostwu 2月 : Desktop
drwxr-xr-x ghostwu ghostwu 2月 : Documents
drwxr-xr-x ghostwu ghostwu 5月 : Downloads
-rw-r--r-- ghostwu ghostwu 2月 : examples.desktop
drwxrwxr-x ghostwu ghostwu 2月 : git_test
drwxrwxr-x ghostwu ghostwu 2月 : info
drwxrwxr-x ghostwu ghostwu 5月 : linux
drwxr-xr-x ghostwu ghostwu 2月 : Music
drwxrwxr-x ghostwu ghostwu 5月 : php
drwxr-xr-x ghostwu ghostwu 2月 : Pictures
drwxrwxr-x ghostwu ghostwu 2月 : project
drwxr-xr-x ghostwu ghostwu 2月 : Public
drwxrwxr-x ghostwu ghostwu 3月 : python
drwxrwxr-x ghostwu ghostwu 2月 : software
drwxr-xr-x ghostwu ghostwu 2月 : Templates
drwxr-xr-x ghostwu ghostwu 2月 : Videos

3,-a 列出所有文件,包括隐藏文件,在linux下,用'.'开头的表示隐藏文件:

ghostwu@dev:~$ ls -a
. Downloads .mozilla .ssh
.. examples.desktop Music .sudo_as_admin_successful
.bash_history .gconf .mysql_history Templates
.bash_logout .gitconfig php Videos
.bashrc git_test Pictures .vim
.byteexec .gnome .pki .viminfo
.cache .gnupg .presage .vimrc
.compiz .ICEauthority .profile .wget-hsts
.config info project .Xauthority
.dbus .lantern Public .xinputrc
Desktop .lesshst python .xsession-errors
.dmrc linux software .xsession-errors.old
Documents .local .sogouinput

4,ls -A 跟ls -a结果差不多,只不过-A不包括 . 和 ..

5,ls -l --time-style=long-iso,显示完整时间属性

ghostwu@dev:~$ ls -l --time-style=long-iso
total
drwxr-xr-x ghostwu ghostwu -- : Desktop
drwxr-xr-x ghostwu ghostwu -- : Documents
drwxr-xr-x ghostwu ghostwu -- : Downloads
-rw-r--r-- ghostwu ghostwu -- : examples.desktop
drwxrwxr-x ghostwu ghostwu -- : git_test
drwxrwxr-x ghostwu ghostwu -- : info
drwxrwxr-x ghostwu ghostwu -- : linux
drwxr-xr-x ghostwu ghostwu -- : Music
drwxrwxr-x ghostwu ghostwu -- : php
drwxr-xr-x ghostwu ghostwu -- : Pictures
drwxrwxr-x ghostwu ghostwu -- : project
drwxr-xr-x ghostwu ghostwu -- : Public
drwxrwxr-x ghostwu ghostwu -- : python
drwxrwxr-x ghostwu ghostwu -- : software
drwxr-xr-x ghostwu ghostwu -- : Templates
drwxr-xr-x ghostwu ghostwu -- : Videos

6,ls -F 如果是目录,会加上反斜线

ghostwu@dev:~$ ls -alF
total
drwxr-xr-x ghostwu ghostwu 5月 : ./
drwxr-xr-x root root 2月 : ../
-rw------- ghostwu ghostwu 5月 : .bash_history
-rw-r--r-- ghostwu ghostwu 2月 : .bash_logout
-rw-r--r-- ghostwu ghostwu 2月 : .bashrc
drwxr--r-- ghostwu ghostwu 2月 : .byteexec/
drwx------ ghostwu ghostwu 4月 : .cache/
drwx------ ghostwu ghostwu 2月 : .compiz/
drwx------ ghostwu ghostwu 4月 : .config/
drwx------ ghostwu ghostwu 2月 : .dbus/
drwxr-xr-x ghostwu ghostwu 2月 : Desktop/
-rw-r--r-- ghostwu ghostwu 2月 : .dmrc
drwxr-xr-x ghostwu ghostwu 2月 : Documents/
drwxr-xr-x ghostwu ghostwu 5月 : Downloads/
-rw-r--r-- ghostwu ghostwu 2月 : examples.desktop
drwx------ ghostwu ghostwu 5月 : .gconf/
-rw-rw-r-- ghostwu ghostwu 2月 : .gitconfig
drwxrwxr-x ghostwu ghostwu 2月 : git_test/
drwx------ ghostwu ghostwu 2月 : .gnome/
drwx------ ghostwu ghostwu 5月 : .gnupg/
-rw------- ghostwu ghostwu 5月 : .ICEauthority
drwxrwxr-x ghostwu ghostwu 2月 : info/
drwxrwxr-x ghostwu ghostwu 2月 : .lantern/
-rw------- ghostwu ghostwu 5月 : .lesshst
drwxrwxr-x ghostwu ghostwu 5月 : linux/
drwx------ ghostwu ghostwu 2月 : .local/
drwx------ ghostwu ghostwu 2月 : .mozilla/
drwxr-xr-x ghostwu ghostwu 2月 : Music/
-rw------- ghostwu ghostwu 5月 : .mysql_history
drwxrwxr-x ghostwu ghostwu 5月 : php/
drwxr-xr-x ghostwu ghostwu 2月 : Pictures/
drwx------ ghostwu ghostwu 2月 : .pki/
drwx------ ghostwu ghostwu 2月 : .presage/
-rw-r--r-- ghostwu ghostwu 2月 : .profile
drwxrwxr-x ghostwu ghostwu 2月 : project/
drwxr-xr-x ghostwu ghostwu 2月 : Public/
drwxrwxr-x ghostwu ghostwu 3月 : python/
drwxrwxr-x ghostwu ghostwu 2月 : software/
drwxrwxr-x ghostwu ghostwu 5月 : .sogouinput/
drwx------ ghostwu ghostwu 3月 : .ssh/
-rw-r--r-- ghostwu ghostwu 2月 : .sudo_as_admin_successful
drwxr-xr-x ghostwu ghostwu 2月 : Templates/
drwxr-xr-x ghostwu ghostwu 2月 : Videos/
drwxrwxr-x ghostwu ghostwu 2月 : .vim/
-rw------- ghostwu ghostwu 5月 : .viminfo
-rw-rw-r-- ghostwu ghostwu 2月 : .vimrc
-rw-r--r-- root root 2月 : .wget-hsts
-rw------- ghostwu ghostwu 5月 : .Xauthority
-rw-rw-r-- ghostwu ghostwu 2月 : .xinputrc
-rw------- ghostwu ghostwu 5月 : .xsession-errors
-rw------- ghostwu ghostwu 5月 : .xsession-errors.old

过滤出目录:

ghostwu@dev:~$ ls -alF | grep /
drwxr-xr-x ghostwu ghostwu 5月 : ./
drwxr-xr-x root root 2月 : ../
drwxr--r-- ghostwu ghostwu 2月 : .byteexec/
drwx------ ghostwu ghostwu 4月 : .cache/
drwx------ ghostwu ghostwu 2月 : .compiz/
drwx------ ghostwu ghostwu 4月 : .config/
drwx------ ghostwu ghostwu 2月 : .dbus/
drwxr-xr-x ghostwu ghostwu 2月 : Desktop/
drwxr-xr-x ghostwu ghostwu 2月 : Documents/
drwxr-xr-x ghostwu ghostwu 5月 : Downloads/
drwx------ ghostwu ghostwu 5月 : .gconf/
drwxrwxr-x ghostwu ghostwu 2月 : git_test/
drwx------ ghostwu ghostwu 2月 : .gnome/
drwx------ ghostwu ghostwu 5月 : .gnupg/
drwxrwxr-x ghostwu ghostwu 2月 : info/
drwxrwxr-x ghostwu ghostwu 2月 : .lantern/
drwxrwxr-x ghostwu ghostwu 5月 : linux/
drwx------ ghostwu ghostwu 2月 : .local/
drwx------ ghostwu ghostwu 2月 : .mozilla/
drwxr-xr-x ghostwu ghostwu 2月 : Music/
drwxrwxr-x ghostwu ghostwu 5月 : php/
drwxr-xr-x ghostwu ghostwu 2月 : Pictures/
drwx------ ghostwu ghostwu 2月 : .pki/
drwx------ ghostwu ghostwu 2月 : .presage/
drwxrwxr-x ghostwu ghostwu 2月 : project/
drwxr-xr-x ghostwu ghostwu 2月 : Public/
drwxrwxr-x ghostwu ghostwu 3月 : python/
drwxrwxr-x ghostwu ghostwu 2月 : software/
drwxrwxr-x ghostwu ghostwu 5月 : .sogouinput/
drwx------ ghostwu ghostwu 3月 : .ssh/
drwxr-xr-x ghostwu ghostwu 2月 : Templates/
drwxr-xr-x ghostwu ghostwu 2月 : Videos/
drwxrwxr-x ghostwu ghostwu 2月 : .vim/

过滤出文件

ghostwu@dev:~$ ls -alF | grep -v /
total
-rw------- ghostwu ghostwu 5月 : .bash_history
-rw-r--r-- ghostwu ghostwu 2月 : .bash_logout
-rw-r--r-- ghostwu ghostwu 2月 : .bashrc
-rw-r--r-- ghostwu ghostwu 2月 : .dmrc
-rw-r--r-- ghostwu ghostwu 2月 : examples.desktop
-rw-rw-r-- ghostwu ghostwu 2月 : .gitconfig
-rw------- ghostwu ghostwu 5月 : .ICEauthority
-rw------- ghostwu ghostwu 5月 : .lesshst
-rw------- ghostwu ghostwu 5月 : .mysql_history
-rw-r--r-- ghostwu ghostwu 2月 : .profile
-rw-r--r-- ghostwu ghostwu 2月 : .sudo_as_admin_successful
-rw------- ghostwu ghostwu 5月 : .viminfo
-rw-rw-r-- ghostwu ghostwu 2月 : .vimrc
-rw-r--r-- root root 2月 : .wget-hsts
-rw------- ghostwu ghostwu 5月 : .Xauthority
-rw-rw-r-- ghostwu ghostwu 2月 : .xinputrc
-rw------- ghostwu ghostwu 5月 : .xsession-errors
-rw------- ghostwu ghostwu 5月 : .xsession-errors.old

7,ls -d 列举目录本身信息,而不是查看目录下的文件信息

ghostwu@dev:~$ ls -d /
/
ghostwu@dev:~$ ls -ld /
drwxr-xr-x root root 2月 : /
ghostwu@dev:~$ ls -ld /home/ghost
ls: cannot access '/home/ghost': No such file or directory
ghostwu@dev:~$ ls -ld /home/ghostwu
drwxr-xr-x ghostwu ghostwu 5月 : /home/ghostwu
ghostwu@dev:~$

8,ls -R 递归查看目录

ghostwu@dev:~$ ls -R linux/
linux/:
mkdir linux/mkdir:

9,alias:查看定义的别名,la 等价于 ls -A:列出所有内容,包括隐藏文件,不包括( . 和 .. )

ghostwu@dev:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[-]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
ghostwu@dev:~$ l
Desktop/ examples.desktop linux/ Pictures/ python/ Videos/
Documents/ git_test/ Music/ project/ software/
Downloads/ info/ php/ Public/ Templates/
ghostwu@dev:~$ la
.bash_history .gnupg python
.bash_logout .ICEauthority software
.bashrc info .sogouinput
.byteexec .lantern .ssh
.cache .lesshst .sudo_as_admin_successful
.compiz linux Templates
.config .local Videos
.dbus .mozilla .vim
Desktop Music .viminfo
.dmrc .mysql_history .vimrc
Documents php .wget-hsts
Downloads Pictures .Xauthority
examples.desktop .pki .xinputrc
.gconf .presage .xsession-errors
.gitconfig .profile .xsession-errors.old
git_test project
.gnome Public

10,定义一个别名( lst 等价与 ls -l --time-style=long-iso )

ghostwu@dev:~$ alias | grep ls
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
ghostwu@dev:~$ lst
No command 'lst' found, but there are similar ones
lst: command not found
ghostwu@dev:~$ alias lst = 'ls -l --time-style=long-iso'
bash: alias: lst: not found
bash: alias: =: not found
bash: alias: `ls -l --time-style': invalid alias name
ghostwu@dev:~$ alias lst='ls -l --time-style=long-iso'
ghostwu@dev:~$ lst
total
drwxr-xr-x ghostwu ghostwu -- : Desktop
drwxr-xr-x ghostwu ghostwu -- : Documents
drwxr-xr-x ghostwu ghostwu -- : Downloads
-rw-r--r-- ghostwu ghostwu -- : examples.desktop
drwxrwxr-x ghostwu ghostwu -- : git_test
drwxrwxr-x ghostwu ghostwu -- : info
drwxrwxr-x ghostwu ghostwu -- : linux
drwxr-xr-x ghostwu ghostwu -- : Music
drwxrwxr-x ghostwu ghostwu -- : php
drwxr-xr-x ghostwu ghostwu -- : Pictures
drwxrwxr-x ghostwu ghostwu -- : project
drwxr-xr-x ghostwu ghostwu -- : Public
drwxrwxr-x ghostwu ghostwu -- : python
drwxrwxr-x ghostwu ghostwu -- : software
drwxr-xr-x ghostwu ghostwu -- : Templates
drwxr-xr-x ghostwu ghostwu -- : Videos
ghostwu@dev:~$ alias | grep ls
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias lst='ls -l --time-style=long-iso'

11,取消别名:unalias + 别名

ghostwu@dev:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[-]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias lst='ls -l --time-style=long-iso'
ghostwu@dev:~$ unalias lst
ghostwu@dev:~$ lst
No command 'lst' found, but there are similar ones
lst: command not found
ghostwu@dev:~$ alias | grep ls
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

12,ls -lrt:  r:反序 t: 根据modify time排序,最新的在最前面

ghostwu@dev:~/linux/mkdir$ touch {a..e}.txt
ghostwu@dev:~/linux/mkdir$ ls -lrt
total
-rw-rw-r-- ghostwu ghostwu 5月 : .txt
-rw-rw-r-- ghostwu ghostwu 5月 : .txt
-rw-rw-r-- ghostwu ghostwu 5月 : .txt
-rw-rw-r-- ghostwu ghostwu 5月 : .txt
-rw-rw-r-- ghostwu ghostwu 5月 : .txt
-rw-rw-r-- ghostwu ghostwu 5月 : e.txt
-rw-rw-r-- ghostwu ghostwu 5月 : d.txt
-rw-rw-r-- ghostwu ghostwu 5月 : c.txt
-rw-rw-r-- ghostwu ghostwu 5月 : b.txt
-rw-rw-r-- ghostwu ghostwu 5月 : a.txt
-rwxrwxrwx ghostwu ghostwu 2月 ghostwu2.txt

13 , -h : 人类能读懂的文件大小

ghostwu@dev:~$ ls -l
total
drwxr-xr-x ghostwu ghostwu 2月 : Desktop
drwxr-xr-x ghostwu ghostwu 2月 : Documents
drwxr-xr-x ghostwu ghostwu 5月 : Downloads
-rw-r--r-- ghostwu ghostwu 2月 : examples.desktop
drwxrwxr-x ghostwu ghostwu 2月 : git_test
drwxrwxr-x ghostwu ghostwu 2月 : info
drwxrwxr-x ghostwu ghostwu 5月 : linux
drwxr-xr-x ghostwu ghostwu 2月 : Music
drwxrwxr-x ghostwu ghostwu 5月 : php
drwxr-xr-x ghostwu ghostwu 2月 : Pictures
drwxrwxr-x ghostwu ghostwu 2月 : project
drwxr-xr-x ghostwu ghostwu 2月 : Public
drwxrwxr-x ghostwu ghostwu 3月 : python
drwxrwxr-x ghostwu ghostwu 2月 : software
drwxr-xr-x ghostwu ghostwu 2月 : Templates
drwxr-xr-x ghostwu ghostwu 2月 : Videos
ghostwu@dev:~$ ls -lh
total 72K
drwxr-xr-x ghostwu ghostwu .0K 2月 : Desktop
drwxr-xr-x ghostwu ghostwu .0K 2月 : Documents
drwxr-xr-x ghostwu ghostwu .0K 5月 : Downloads
-rw-r--r-- ghostwu ghostwu .8K 2月 : examples.desktop
drwxrwxr-x ghostwu ghostwu .0K 2月 : git_test
drwxrwxr-x ghostwu ghostwu .0K 2月 : info
drwxrwxr-x ghostwu ghostwu .0K 5月 : linux
drwxr-xr-x ghostwu ghostwu .0K 2月 : Music
drwxrwxr-x ghostwu ghostwu .0K 5月 : php
drwxr-xr-x ghostwu ghostwu .0K 2月 : Pictures
drwxrwxr-x ghostwu ghostwu .0K 2月 : project
drwxr-xr-x ghostwu ghostwu .0K 2月 : Public
drwxrwxr-x ghostwu ghostwu .0K 3月 : python
drwxrwxr-x ghostwu ghostwu .0K 2月 : software
drwxr-xr-x ghostwu ghostwu .0K 2月 : Templates
drwxr-xr-x ghostwu ghostwu .0K 2月 : Videos

14,-i 列出i节点信息

ghostwu@dev:~$ ls -il
total
drwxr-xr-x ghostwu ghostwu 2月 : Desktop
drwxr-xr-x ghostwu ghostwu 2月 : Documents
drwxr-xr-x ghostwu ghostwu 5月 : Downloads
-rw-r--r-- ghostwu ghostwu 2月 : examples.desktop
drwxrwxr-x ghostwu ghostwu 2月 : git_test
drwxrwxr-x ghostwu ghostwu 2月 : info
drwxrwxr-x ghostwu ghostwu 5月 : linux
drwxr-xr-x ghostwu ghostwu 2月 : Music
drwxrwxr-x ghostwu ghostwu 5月 : php
drwxr-xr-x ghostwu ghostwu 2月 : Pictures
drwxrwxr-x ghostwu ghostwu 2月 : project
drwxr-xr-x ghostwu ghostwu 2月 : Public
drwxrwxr-x ghostwu ghostwu 3月 : python
drwxrwxr-x ghostwu ghostwu 2月 : software
drwxr-xr-x ghostwu ghostwu 2月 : Templates
drwxr-xr-x ghostwu ghostwu 2月 : Videos

Linux常用基本命令( ls, alias)的更多相关文章

  1. Linux常用基本命令(less)

    转: Linux常用基本命令(less) LESS:跟more命令的功能类似,都是用于分页显示内容,但是他的性能比more更高,功能比more更丰富,他读取文件是按需加载 格式: less [opti ...

  2. Linux 常用基本命令及应用技巧

    需要pdf 版 联系我 我的文件中有目录一.Linux 的常用基本命令................................................................. ...

  3. Linux常用命令 - ls

    目录 Linux常用命令-ls 简介 ls -F ls -a ls -R ls -l 后记 Linux常用命令-ls 简介 ls主要用于显示文件和目录列表.作为最常见的Linux命令,大家应该都不会陌 ...

  4. Linux常用基本命令(chmod)

    chmod命令用来改变文件或者目录的权限,只有文件的属主和超级用户才能够执行这个命令 格式: chmod [option] [mode] [file] >常用参数选项 -R : 递归修改目录以及 ...

  5. 测试必知必会系列- Linux常用命令 - ls

    21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1672457.html 列出当 ...

  6. Linux 常用命令 :ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  7. 【Linux】linux常用基本命令(转)

    (转自:http://blog.csdn.net/xiaoguaihai/article/details/8705992) Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用 ...

  8. 【Linux】linux常用基本命令

    Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们.   这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日 ...

  9. linux常用基本命令

    Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们.   系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器 ...

随机推荐

  1. Java几种单例模式的实现与利弊

    饿汉式 提前new出来实例了,并不是在第一次调用get方法时才实例化,没有进行延迟加载 public class Singleton1 { private static Singleton1 inst ...

  2. I/O类型

    同步和异步 synchronous  asyncronous 关注的是消息通知机制 同步:调用发出之后不会立即返回,但一旦返回,则返回即是最终结果. 异步:调用发出之后,被调用方立即返回消息,但返回的 ...

  3. POJ 2707

    #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int ...

  4. [LeetCode] 206. Reverse Linked List_Easy tag: Linked List

    Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...

  5. 坑爹的Sun JDK

    Sun的这个java.lang.Throwable 源码 设计非常糟糕,完全没有扩展性, 我在IBM 的Java JDK下,继承java.lang.Throwable重新定义了一个ExceptionW ...

  6. Kafka连接SparkStreaming的两种方式

    第一种方式代码: import org.apache.spark.storage.StorageLevel import org.apache.spark.{HashPartitioner, Spar ...

  7. Windows7下无法打开chm(mk:@MSITStore:路径[cannot open the file mk@MSITstore:路径]),chm索引就关闭的解决办法

    解决方法1是: 1,右键关联chm文件的“打开方式”到\Windows\HH.exe 2,在命令行运行regsvr32 itss.dll 3,在命令行运行regsvr32 hhctrl.ocx 方法2 ...

  8. Numpy 常用矩阵计算函数

    基本属性 在做一些数据分析的时候,我们通常会把数据存为矩阵的形式,然后python本身对于矩阵的操作是不够的,因此出现了numpy这样一个科学开发库来进行python在次上面的不足. Numpy's ...

  9. Jfinal QuartzPlugin 简单使用案例

    之前一直使用spring quartz感觉还挺好用的,就想着jfinal是不是也可以使用quartz插件,于是发现了QuartzPlugin和jfinal-scheduler<参考:https: ...

  10. MyBatis 注解配置

    Employee package com.example.demo.domain; import java.io.Serializable; public class Employee impleme ...