您的位置:首页 > 运维架构 > Linux

Linux系统目录结构

2017-12-15 00:00 267 查看
摘要: 系统目录结构
ls命令
文件类型
alias命令

系统目录结构

/bin:bin是Binary的缩写,该目录下存放的是最常用的命令。

/boot:该目录下存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件。

/dev:dev是Device(设备)的缩写。该目录下存放的是Linux的外部设备。在Linux中,访问设备的方式和访问文件的方式是相同的。

/etc:该目录下存放的是所有系统管理所需要的配置文件和子目录。

/home:这是用户的主目录。在Linux中,每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。

/lib和/lib64:这两个目录下存放的是系统最基本的动态连接共享库,其作用类似于Windows里的DLL文件,几乎所有的应用程序都需要用到这些共享库。其中/lib64为64位的软件包的库文件所在目录。

/media:系统会自动识别一些设备(如U盘、光驱等),当识别后,Linux会把识别的设备挂载到该目录下。

/mnt:系统提供该目录是为了让用户临时挂载别的文件系统。我们可以将光驱挂载到/mnt/上,然后进入该目录查看光驱里的内容。

/opt:这是给主机额外安装软件所设置的目录,该目录默认为空。比如你要安装一个ORACLE数据库,可以放到该目录下。

/proc:该目录是一个虚拟的目录,是系统内存的映射,我们可以通过直接访问来获取系统信息。该目录的内容在内存里,我们可以直接修改里面的某些文件。比如可以通过下面的命令来屏蔽主机的ping命令,使其他人无法ping你的机器。后续,在日常工作中,你会经常用到类似的用法。

/root:该目录是系统管理员的用户主目录。

/run:这个目录其实和/var/run是同一个目录,这里面存放的是一些服务的pid,一个服务启动完后,是有一个pid文件的。至于为什么说是同一个目录,Linux是如何做到的,后续我们再介绍。

/sbin:s就是Super User的意思,该目录存放的是系统管理员使用的系统管理程序。

/srv:该目录存放的是一些服务启动之后需要提取的数据。

/sys:该目录存放的是与硬件驱动程序相关的信息。

/tmp:该目录是用来存放一些临时文件的。

/usr:这是一个非常重要的目录,类似于Windows下的Program Files目录,用户的很多应用程序和文件都存放在该目录下。后面的章节中,我们会多次用到这个目录。

/usr/bin:该目录存放的是系统用户使用的应用程序。

/usr/sbin: 该目录存放的是超级用户使用的比较高级的管理程序和系统守护程序。

/usr/src :该目录是内核源代码默认的放置目录。

/var:该目录存放的是在不断扩充且经常被修改的目录,包括各种日志文件或者pid文件,刚刚提到的/var/run就是在/var目录下面

在Linux系统中,有几个重要的目录需要注意,不要误删除或者随意更改其内部文件。下面是Linux系统中几个重要的目录。

/etc目录下是系统的配置文件,如果更改了该目录下的某个文件可能会导致系统无法正常启动。

/bin、/sbin、/usr/bin和/usr/sbin目录是系统预设的执行文件的放置目录,其中/bin和/usr/bin目录下是供系统用户使用的指令(除root外的通用账户),而/sbin和/usr/sbin目录下则是供root使用的指令。比如ls指令就存放在/bin/目录下。

/var也是一个非常重要的目录,系统上运行各个程序时所产生的日志都被记录在该目录下(即/var/log目录中),另外mail指令的预设也放置在这里。

ls 命令

ls 显示要查看目录下的非隐藏的文件或目

[root@lynn-05 ~]# ls
anaconda-ks.cfg

ls -l 显示要查看目录下的非隐藏的文件或目录的详细信息

[root@lynn-05 ~]# ls -l
总用量 4
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg

ls -a 显示要查看目录下的所有文件或目录(包含隐藏的)【.】开头的为隐藏文件

[root@lynn-05 ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc .ssh
.. .bash_history .bash_profile .cshrc .tcshrc

ls -d 仅显示要查看目录本身

[root@lynn-05 ~]# ls -d /boot
/boot

ls -lh 显示要查看目录下的非隐藏的文件或目录的详细信息 文件的大小以合适的单位显示

[root@lynn-05 ~]# ls -l
总用量 4
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg
[root@lynn-05 ~]# ls -lh
总用量 4.0K
-rw-------. 1 root root 1.4K 12月 12 19:29 anaconda-ks.cfg

ls -t 以时间排序显示文件或目录

[root@lynn-05 ~]# ls -la
总用量 28
dr-xr-x---. 3 root root 147 12月 13 23:28 .
dr-xr-xr-x. 17 root root 224 12月 12 19:28 ..
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg
-rw-------. 1 root root 1073 12月 15 22:04 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwx------. 2 root root 6 12月 13 23:30 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@lynn-05 ~]# ls -lat
总用量 28
-rw-------. 1 root root 1073 12月 15 22:04 .bash_history
drwx------. 2 root root 6 12月 13 23:30 .ssh
dr-xr-x---. 3 root root 147 12月 13 23:28 .
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg
dr-xr-xr-x. 17 root root 224 12月 12 19:28 ..
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc

ls -i 显示文件的inode信息

[root@lynn-05 ~]# ls -i

33582978 anaconda-ks.cfg

文件类型

d:目录

[root@lynn-05 test]# ls -la
总用量 0
drwxr-xr-x. 3 root root 17 12月 15 23:07 .
dr-xr-x---. 4 root root 159 12月 15 23:07 ..
drwxr-xr-x. 2 root root 6 12月 15 23:07 123

-:普通文件

[root@lynn-05 ~]# ls -l
总用量 4
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg

l:链接(类似Windows的快捷方式)

[root@lynn-05 ~]# ls -la /dev/rtc
lrwxrwxrwx. 1 root root 4 12月 15 21:33 /dev/rtc -> rtc0

b:块设备文件(例如硬盘、光驱等)

[root@lynn-05 ~]# ls -la /dev/sda1
brw-rw----. 1 root disk 8, 1 12月 15 21:33 /dev/sda1

c:字符设备文件(例如猫等串口设备)

[root@lynn-05 ~]# ls -la /dev/tty
crw-rw-rw-. 1 root tty 5, 0 12月 15 21:33 /dev/tty

s:套接口文件/数据接口文件(例如启动一个MySql服务器时会产生一个mysql.sock文件)

[root@lynn-05 ~]# ls -la /dev/log
srw-rw-rw-. 1 root root 0 12月 15 21:33 /dev/log

alias命令

alias 查看系统别名

[root@lynn-05 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

自定义别名 alias 别名= ‘命令’

[root@lynn-05 ~]# alias lynn='ls -la'
[root@lynn-05 ~]# lynn
总用量 28
dr-xr-x---. 3 root root 147 12月 15 23:10 .
dr-xr-xr-x. 17 root root 224 12月 12 19:28 ..
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg
-rw-------. 1 root root 1073 12月 15 22:04 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwx------. 2 root root 6 12月 13 23:30 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshr

取消自定义别名 unalias 别名

[root@lynn-05 ~]# alias lynn='ls -la'
[root@lynn-05 ~]# lynn
总用量 28
dr-xr-x---. 3 root root 147 12月 15 23:10 .
dr-xr-xr-x. 17 root root 224 12月 12 19:28 ..
-rw-------. 1 root root 1418 12月 12 19:29 anaconda-ks.cfg
-rw-------. 1 root root 1073 12月 15 22:04 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwx------. 2 root root 6 12月 13 23:30 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@lynn-05 ~]# unalias lynn
[root@lynn-05 ~]# lynn
-bash: lynn: 未找到命令

友情链接:阿铭Linux
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: