linux文件类型分类及管理命令
在了解了Linux哲学思想一切皆文件后,可以整理下Liunx是如何管理文件的以及涉及文件管理的相关命令,要知道文件管理就要知道文件类型那样才能有效管理那么linux有哪些文件类型呢?
通过ls命令加选项 al 可以查看 当前目录下的文件,以列表的形式展示出来
[root@localhost dev]# ls -al
total 4
drwxr-xr-x 20 root root 3640 Sep 23 08:38 .
dr-xr-xr-x. 27 root root 4096 Sep 23 08:37 ..
drwxr-xr-x 2 root root 40 Sep 23 08:37 .mdadm
drwxr-xr-x 7 root root 160 Sep 23 08:37 .udev
前面这一串drwxr-xr-x 就是描述了文件的类型及权限权限部分暂时不看 我先看文件类型也就是整行的第一个字符这里显示为d 表示目录,directory简写,统计下linux下常见的文件类型吧
文件描述符 | 文件类型 |
d | 目录 |
- | 常规文件,即file |
b | block device 即块设备文件,如硬盘;支持以block为单位进行随机访问 |
c | character device 即字符设备文件,如键盘支持以character为单位进行线性访问 |
l | symbolic link 即符号链接文件,又称软链接文件 |
p | pipe 即命名管道文件 |
s | socket 即套接字文件,用于实现两个进程进行通信 |
对于不同的文件类型则有不同的管理方式下面就列举几个常用的文件类型文件管理命令
- 针对目录类型的管理命令:
pwd 打印当前工作目录
常用选项
-P 打印真实路径dsaasdsadasd
-L 打印逻辑路径 默认即为-L
[root@localhost bin]# pwd /bin [root@localhost bin]# pwd -P /usr/bin [root@localhost bin]# pwd -L /bin [root@localhost bin]#
cd 改变工作目录路径
常用选项
-P 打印真实路径[root@localhost ~]# cd /bin [root@localhost bin]# pwd /bin [root@localhost bin]# cd -P /bin [root@localhost bin]# pwd /usr/bin [root@localhost bin]#
小技巧 回到自己的家目录 cd 回车 / cd ~asdasd 去某用户的家目录 cd ~$SOMEONE
回到上次目录 cd -ls 列出目录内容
常用选项
-l 显示额外信息
-a 显示包含隐藏文件[root@localhost tmp]# ls -a . gnome-system-monitor.maoyanit.2498802068 pulse-Voq7HMaaxrze .. keyring-hFZUU3 test .ICE-unix keyring-wiHnzv test123 [root@localhost tmp]# ls -l total 16 srwxrwxr-x. 1 maoyanit maoyanit 0 Jan 11 2017 gnome-system-monitor.maoyanit.2498802068 drwx------ 2 maoyanit maoyanit 4096 Nov 3 2017 keyring-hFZUU3 drwx------ 2 maoyanit maoyanit 4096 Dec 4 2017 keyring-wiHnzv drwx------ 2 gdm gdm 4096 Jun 11 2018 pulse-Voq7HMaaxrze drwxr-xr-x 2 root root 4096 Oct 11 11:50 test ---------- 1 root root 0 Sep 2 16:09 test123 [root@localhost tmp]#
-R 目录递归通过
[root@localhost tmp]# ls -R .: gnome-system-monitor.maoyanit.2498802068 keyring-wiHnzv test keyring-hFZUU3 pulse-Voq7HMaaxrze test123 ./keyring-hFZUU3: socket socket.pkcs11 socket.ssh ./keyring-wiHnzv: socket socket.pkcs11 socket.ssh ./pulse-Voq7HMaaxrze: native ./test: [root@localhost tmp]#
-lD 目录和符号信息
-1 文件分行显示
-S 按文件从大到小排序
-t 按mtime 排序[root@localhost tmp]# ls -ld /etc drwxr-xr-x. 127 root root 12288 Oct 8 03:39 /etc [root@localhost tmp]# [root@localhost tmp]# ls -1 gnome-system-monitor.maoyanit.2498802068 keyring-hFZUU3 keyring-wiHnzv pulse-Voq7HMaaxrze test test123 [root@localhost tmp]# [root@localhost tmp]# ls -Sl total 16 drwx------ 2 maoyanit maoyanit 4096 Nov 3 2017 keyring-hFZUU3 drwx------ 2 maoyanit maoyanit 4096 Dec 4 2017 keyring-wiHnzv drwx------ 2 gdm gdm 4096 Jun 11 2018 pulse-Voq7HMaaxrze drwxr-xr-x 2 root root 4096 Oct 11 11:50 test srwxrwxr-x. 1 maoyanit maoyanit 0 Jan 11 2017 gnome-system-monitor.maoyanit.2498802068 ---------- 1 root root 0 Sep 2 16:09 test123 [root@localhost tmp]# [root@localhost tmp]# ls -Slr total 16 ---------- 1 root root 0 Sep 2 16:09 test123 srwxrwxr-x. 1 maoyanit maoyanit 0 Jan 11 2017 gnome-system-monitor.maoyanit.2498802068 drwxr-xr-x 2 root root 4096 Oct 11 11:50 test drwx------ 2 gdm gdm 4096 Jun 11 2018 pulse-Voq7HMaaxrze drwx------ 2 maoyanit maoyanit 4096 Dec 4 2017 keyring-wiHnzv drwx------ 2 maoyanit maoyanit 4096 Nov 3 2017 keyring-hFZUU3 [root@localhost tmp]# [root@localhost tmp]# ls -tl total 16 drwxr-xr-x 2 root root 4096 Oct 11 11:50 test ---------- 1 root root 0 Sep 2 16:09 test123 drwx------ 2 gdm gdm 4096 Jun 11 2018 pulse-Voq7HMaaxrze drwx------ 2 maoyanit maoyanit 4096 Dec 4 2017 keyring-wiHnzv drwx------ 2 maoyanit maoyanit 4096 Nov 3 2017 keyring-hFZUU3 srwxrwxr-x. 1 maoyanit maoyanit 0 Jan 11 2017 gnome-system-monitor.maoyanit.2498802068 [root@localhost tmp]#
-u 配合-t选项,显示并按atime从新到旧排序
[root@localhost ~]# ls -ul total 41152 -rw-------. 1 root root 2420 Sep 7 11:21 anaconda-ks.cfg drwxr-xr-x. 2 root root 4096 Sep 12 14:19 dockerKernel -rw-r--r--. 1 root root 68509 Jan 16 2018 install.log -rw-r--r--. 1 root root 11949 Jan 10 2017 install.log.syslog -rw-r--r--. 1 root root 34279307 Aug 16 2017 kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm.gz -rw-r--r--. 1 root root 7734471 Aug 16 2017 kernel-ml-aufs-devel-3.10.5-3.el6.x86_64.rpm.gz drwxr-xr-x 3 root root 4096 Sep 12 14:19 logs -rw------- 1 root root 2160 Jan 16 2018 nohup.out -rwxrwxrwx 1 root root 1278 Jun 20 2018 start.sh -rwxr-xr-x 1 root root 1764 Sep 28 2018 start2.sh drwxr-xr-x 2 root root 4096 Sep 30 10:11 test -rwxrwxrwx 1 root root 3035 Jan 12 2019 update.sh -rw-r--r-- 1 root root 3646 Nov 8 2017 wget-log [root@localhost ~]#
-U 按目录存放顺序显示
[root@localhost ~]# ls -Ul total 41152 drwxr-xr-x 2 root root 4096 Aug 29 10:27 test -rw-------. 1 root root 2420 Jan 10 2017 anaconda-ks.cfg -rwxr-xr-x 1 root root 1764 Apr 11 2018 start2.sh -rw-r--r--. 1 root root 7734471 Aug 16 2017 kernel-ml-aufs-devel-3.10.5-3.el6.x86_64.rpm.gz drwxr-xr-x 3 root root 4096 Sep 10 11:33 logs -rw------- 1 root root 2160 Mar 6 2018 nohup.out -rw-r--r--. 1 root root 34279307 Aug 16 2017 kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm.gz -rwxrwxrwx 1 root root 3035 Apr 11 2018 update.sh -rw-r--r--. 1 root root 11949 Jan 10 2017 install.log.syslog -rw-r--r-- 1 root root 3646 Nov 8 2017 wget-log drwxr-xr-x. 2 root root 4096 Aug 16 2017 dockerKernel -rw-r--r--. 1 root root 68509 Jan 10 2017 install.log -rwxrwxrwx 1 root root 1278 Nov 13 2017 start.sh [root@localhost ~]#
-X 按文件后缀排序
[root@localhost ~]# ls -Xl total 41152 drwxr-xr-x. 2 root root 4096 Aug 16 2017 dockerKernel drwxr-xr-x 3 root root 4096 Sep 10 11:33 logs drwxr-xr-x 2 root root 4096 Aug 29 10:27 test -rw-r--r-- 1 root root 3646 Nov 8 2017 wget-log -rw-------. 1 root root 2420 Jan 10 2017 anaconda-ks.cfg -rw-r--r--. 1 root root 34279307 Aug 16 2017 kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm.gz -rw-r--r--. 1 root root 7734471 Aug 16 2017 kernel-ml-aufs-devel-3.10.5-3.el6.x86_64.rpm.gz -rw-r--r--. 1 root root 68509 Jan 10 2017 install.log -rw------- 1 root root 2160 Mar 6 2018 nohup.out -rwxrwxrwx 1 root root 1278 Nov 13 2017 start.sh -rwxr-xr-x 1 root root 1764 Apr 11 2018 start2.sh -rwxrwxrwx 1 root root 3035 Apr 11 2018 update.sh -rw-r--r--. 1 root root 11949 Jan 10 2017 install.log.syslog [root@localhost ~]#
- 针对普通文件类型的管理命令:
vi 创建文件和编辑文件,全屏幕的编辑器
vim 创建文件 vi加强版编辑器
nago 创建文件 全屏幕的编辑器 简单文本编辑器
touch 创建文件
cat 查看文件
tac 查看文件
tail 查看文件
head 查看文件
nl 查看文件
more 查看文件
less 查看文件
> 是定向输出到文件,如果文件不存在,就创建文件;如果文件存在,就将其清空
>> 追加文件,也就是如果文件里面有内容会把新内容追加到文件尾
cp 复制文件
mv 移动文件
rename 文件重命名
- 针对软链接文件类型的管理命令:
ln -s 创建软连接文件