3. Linux命令
2.1 文件目录管理
2.1.1 目录操作
pwd 显示当前目录
print name of current/working directory
- 示例
[root@CSDN ~]# pwd
/root
ls 列出目录内容
list directory contents
- 语法
ls [参数] [FILE]
- 参数
-a, --all #显示所有文件包含隐藏文件
-l #显示详细信息
-h #可读性增强
-t #按时间排序 #ls -lt按时间倒序
-r #reverse 翻转 #ls -lrt 按时间升序
-R #recursive 递归性,一层层显示所有文件包含子目录的文件
- 示例
[root@CSDN ~]# ls
anaconda-ks.cfg Downloads Music Templates
Desktop install.log Pictures Videos
Documents install.log.syslog Public
[root@CSDN ~]# ls -l
# ls -l的别名是ll
total 100
-rw-------. 1 root root 1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root 4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root 4096 May 14 11:51 Downloads
[root@CSDN ~]# ll -h
total 100K
-rw-------. 1 root root 1.6K Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Desktop
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Documents
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Downloads
[root@CSDN ~]# ll -t
total 100
drwxr-xr-x. 2 root root 4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root 4096 May 14 11:51 Downloads
drwxr-xr-x. 2 root root 4096 May 14 11:51 Music
drwxr-xr-x. 2 root root 4096 May 14 11:51 Pictures
[root@CSDN ~]# ll -R
.:
total 100
-rw-------. 1 root root 1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root 4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root 4096 May 14 11:51 Downloads
-rw-r--r--. 1 root root 46562 Mar 30 23:54 install.log
-rw-r--r--. 1 root root 10031 Mar 30 23:52 install.log.syslog
drwxr-xr-x. 2 root root 4096 May 14 11:51 Music
drwxr-xr-x. 2 root root 4096 May 14 11:51 Pictures
drwxr-xr-x. 2 root root 4096 May 14 11:51 Public
drwxr-xr-x. 2 root root 4096 May 14 11:51 Templates
drwxr-xr-x. 2 root root 4096 May 14 11:51 Videos
./Desktop:
total 0
./Documents:
total 0
./Downloads:
total 0
./Music:
total 0
./Pictures:
total 0
./Public:
total 0
./Templates:
total 0
./Videos:
total 0
[root@CSDN ~]# ll -rt
total 100
-rw-r--r--. 1 root root 10031 Mar 30 23:52 install.log.syslog
-rw-r--r--. 1 root root 46562 Mar 30 23:54 install.log
-rw-------. 1 root root 1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root 4096 May 14 11:51 Videos
drwxr-xr-x. 2 root root 4096 May 14 11:51 Templates
drwxr-xr-x. 2 root root 4096 May 14 11:51 Public
drwxr-xr-x. 2 root root 4096 May 14 11:51 Pictures
drwxr-xr-x. 2 root root 4096 May 14 11:51 Music
drwxr-xr-x. 2 root root 4096 May 14 11:51 Downloads
drwxr-xr-x. 2 root root 4096 May 14 11:51 Documents
- 第一列
- 第一位:文件类型
- -:普通文件
- d:directory :目录(文件夹)
- c:character 字符设备(如屏幕输入文字)
- b:block 块设备(如硬盘或者分区)
- l:快捷方式 link
- 第二-第十位:权限位
- 第十一位:ACL(访问控制列表,高级权限位)
- 第一位:文件类型
- 第二列:
- 文件:硬链接数+1
- 目录:第一级子目录数
- 第三列:所属用户
- 第四列:所属组
- 第五列
- 文件:大小
- 文件夹:目录本身大小,不含内容
- 第六列:访问或修改时间
- 第七列:文件名(文件夹名)
cd 切换目录
Change the shell working directory.
- 语法
cd [DIR]
cd 绝对路径 #如 cd /boot
cd 相对路径 #如 cd boot #前提你在/下
cd - #从哪里来回哪里去
cd #回家
cd ~ #回家
cd ~用户名 #切换到指定用户的家目录下
- 绝对路径:以/开头,/代表根目录
- 相对路径:不以/开头,相对于当前目录位置
- 点(.):代表当前目录
- 点点(…):代表上级目录(父目录)
- 只有/没有父目录
- 所有的命令中都可以对文件或目录用相对路径或绝对路径来表示,跟cd命令无关
- 示例
- 切换到/boot,显示当前目录,显示当前目录下的所有内容的详细信息
- 不进行切换,显示/var/log目录下的所有内容的详细信息
[root@CSDN ~]# cd /boot
[root@CSDN boot]# pwd
/boot
[root@CSDN boot]# ll -a
total 33126
dr-xr-xr-x. 5 root root 1024 Mar 30 23:53 .
dr-xr-xr-x. 25 root root 4096 May 14 11:50 ..
-rw-r--r--. 1 root root 108164 Mar 22 2017 config-2.6.32-696.el6.x86_64
drwxr-xr-x. 3 root root 1024 Mar 30 23:52 efi
drwxr-xr-x. 2 root root 1024 Mar 30 23:54 grub
-rw-------. 1 root root 26667930 Mar 30 23:54 initramfs-2.6.32-696.el6.x86_64.img
drwx------. 2 root root 12288 Mar 30 23:46 lost+found
-rw-r--r--. 1 root root 215634 Mar 22 2017 symvers-2.6.32-696.el6.x86_64.gz
-rw-r--r--. 1 root root 2622364 Mar 22 2017 System.map-2.6.32-696.el6.x86_64
-rwxr-xr-x. 1 root root 4274992 Mar 22 2017 vmlinuz-2.6.32-696.el6.x86_64
-rw-r--r--. 1 root root 166 Mar 22 2017 .vmlinuz-2.6.32-696.el6.x86_64.hmac
[root@CSDN boot]# ll /var/log/
total 1408
-rw-------. 1 root root 2368 Mar 30 23:54 anaconda.ifcfg.log
-rw-------. 1 root root 22563 Mar 30 23:54 anaconda.log
-rw-------. 1 root root 35814 Mar 30 23:54 anaconda.program.log
-rw-------. 1 root root 109997 Mar 30 23:54 anaconda.storage.log
-rw-------. 1 root root 118704 Mar 30 23:54 anaconda.syslog
-rw-------. 1 root root 28879 Mar 30 23:54 anaconda.xlog
-rw-------. 1 root root 121828 Mar 30 23:54 anaconda.yum.log
drwxr-x---. 2 root root 4096 Mar 30 23:56 audit
-rw-r--r--. 1 root root 2362 May 14 11:50 boot.log
-rw-------. 1 root utmp 0 Mar 30 23:49 btmp
drwxr-xr-x. 2 root root 4096 Mar 30 23:56 ConsoleKit
-rw-------. 1 root root 1423 May 14 11:50 cron
drwxr-xr-x. 2 lp sys 4096 Mar 22 2017 cups
-rw-r--r--. 1 root root 69331 May 14 11:50 dmesg
-rw-r--r--. 1 root root 69331 May 14 11:32 dmesg.old
-rw-r--r--. 1 root root 240142 Mar 30 23:54 dracut.log
drwxrwx--T. 2 root gdm 4096 May 14 11:50 gdm
drwx------. 2 root root 4096 Mar 22 2017 httpd
-rw-r--r--. 1 root root 145708 May 14 11:52 lastlog
-rw-------. 1 root root 1274 May 14 11:50 maillog
-rw-------. 1 root root 322019 May 14 11:52 messages
drwxr-xr-x. 2 ntp ntp 4096 Feb 6 2017 ntpstats
-rw-r--r--. 1 root root 89 May 14 11:50 pm-powersave.log
drwx------. 2 root root 4096 Mar 16 2015 ppp
drwxr-xr-x. 2 root root 4096 Aug 19 2013 prelink
drwxr-xr-x. 2 root root 4096 May 14 11:32 sa
drwx------. 3 root root 4096 Mar 30 23:49 samba
-rw-------. 1 root root 7990 May 14 11:52 secure
-rw-------. 1 root root 0 Mar 30 23:56 spice-vdagent.log
-rw-------. 1 root root 0 Mar 30 23:50 spooler
drwxr-x---. 2 root root 4096 Mar 23 2017 sssd
-rw-------. 1 root root 0 Mar 30 23:48 tallylog
-rw-r--r--. 1 root root 0 Mar 30 23:56 wpa_supplicant.log
-rw-rw-r--. 1 root utmp 29952 May 14 11:52 wtmp
-rw-r--r--. 1 root root 58244 May 14 11:57 Xorg.0.log
-rw-r--r--. 1 root root 59418 May 14