Linux常用ls, alias基础命令详解

2019-09-23 08:57:49于海丽

过滤出文件

ghostwu@dev:~$ ls -alF | grep -v /
total 260
-rw------- 1 ghostwu ghostwu 18095 5月 1 14:48 .bash_history
-rw-r--r-- 1 ghostwu ghostwu 220 2月 10 16:16 .bash_logout
-rw-r--r-- 1 ghostwu ghostwu 3771 2月 10 16:16 .bashrc
-rw-r--r-- 1 ghostwu ghostwu 25 2月 11 00:32 .dmrc
-rw-r--r-- 1 ghostwu ghostwu 8980 2月 10 16:16 examples.desktop
-rw-rw-r-- 1 ghostwu ghostwu 65 2月 9 19:51 .gitconfig
-rw------- 1 ghostwu ghostwu 7356 5月 1 14:48 .ICEauthority
-rw------- 1 ghostwu ghostwu 58 5月 1 17:47 .lesshst
-rw------- 1 ghostwu ghostwu 358 5月 1 14:48 .mysql_history
-rw-r--r-- 1 ghostwu ghostwu 655 2月 10 16:16 .profile
-rw-r--r-- 1 ghostwu ghostwu  0 2月 9 16:39 .sudo_as_admin_successful
-rw------- 1 ghostwu ghostwu 31867 5月 1 17:29 .viminfo
-rw-rw-r-- 1 ghostwu ghostwu 110 2月 9 19:35 .vimrc
-rw-r--r-- 1 root root  170 2月 9 16:49 .wget-hsts
-rw------- 1 ghostwu ghostwu 48 5月 1 14:48 .Xauthority
-rw-rw-r-- 1 ghostwu ghostwu 132 2月 9 17:15 .xinputrc
-rw------- 1 ghostwu ghostwu 82 5月 1 14:48 .xsession-errors
-rw------- 1 ghostwu ghostwu 783 5月 1 14:48 .xsession-errors.old

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

ghostwu@dev:~$ ls -d /
/
ghostwu@dev:~$ ls -ld /
drwxr-xr-x 24 root root 4096 2月 10 16:17 /
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 33 ghostwu ghostwu 4096 5月 1 17:47 /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*[0-9]+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 17 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 72
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 Desktop
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 Documents
drwxr-xr-x 7 ghostwu ghostwu 4096 2018-05-01 11:40 Downloads
-rw-r--r-- 1 ghostwu ghostwu 8980 2018-02-10 16:16 examples.desktop
drwxrwxr-x 3 ghostwu ghostwu 4096 2018-02-09 19:50 git_test
drwxrwxr-x 3 ghostwu ghostwu 4096 2018-02-09 16:37 info
drwxrwxr-x 3 ghostwu ghostwu 4096 2018-05-01 17:04 linux
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 Music
drwxrwxr-x 4 ghostwu ghostwu 4096 2018-05-01 14:30 php
drwxr-xr-x 3 ghostwu ghostwu 4096 2018-02-10 14:45 Pictures
drwxrwxr-x 4 ghostwu ghostwu 4096 2018-02-10 14:34 project
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 Public
drwxrwxr-x 2 ghostwu ghostwu 4096 2018-03-18 21:55 python
drwxrwxr-x 3 ghostwu ghostwu 4096 2018-02-09 17:28 software
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 Templates
drwxr-xr-x 2 ghostwu ghostwu 4096 2018-02-11 00:32 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'