一、Linux文件系统
1、文件名名称严格区分字符大小写;
2、文件可以使用除/以外的任意字符;
3、文件名长度不能超过255个字符;
4、以.开头的文件为隐藏文件;
. : 当前目录
.. : 当前目录的上级目录
二、基础命令
pwd cd ls cat tac file echo
shutdown clock hwclock date cal
pwd : printing working directory
显示工作目录
cd : change directory
cd [/PATH/TO/DIRECTORY]
cd : 不带任何参数,则切换回用户主目录
cd ~ : 切换回自己的主目录
cd ~USERNAME : 切换至指定用户的主目录
cd - : 在上一次所在目录与当前目录之间来回切换
echo $PWD : 显示当前工作目录
echo $OLDPWD : 显示上一次的工作目录
ls : list, 列出指定目录下的内容
ls [OPTION]... [FILE]...
-a : 显示指定目录内的所有文件,包括隐藏文件;
-A : 显示除.和..以外的所有文件
-l : --long , 长格式列表,显示文件的详细属性信息;
-rw-r--r--. 1 root root 970 Aug 6 2017 yum.conf
- : 文件类型,[- , d , b , c , l , s , p]
rw- : 文件属主权限
r-- : 文件属组权限
r-- : 其他用户的权限
1 : 数字表示文件被硬链接的次数
root : 文件属主
root : 文件属组
970 : 数字表示文件大小,单位是字节,Byte
Aug 6 2017 : 文件最近一次被修改的时间
yum.conf : 文件名
-h : --human-readable 对文件大小单位换算,换算后的结果可能是非精确值
-rw-r--r--. 1 root root 2.0K Aug 2 2017 vimrc
-d : 查看目录自身而非其内部的文件列表
[root@localhost etc]# ls -ld /etc
drwxr-xr-x. 82 root root 8192 Mar 10 11:21 /etc
-r : reverse , 逆序显示;默认是按文件名开头字母或数字的排列做顺序显示;
-R : recursive , 子目录里面的内容递归显示;
cat : concatenate , 文件文本查看工具
cat [OPTION]... [FILE]... -n : 给显示的文本编号 -E : 显示行结束符
tac : 逆序显示(与 cat 显示的文件的内容顺序刚好相反)
tac [OPTION]... [FILE]...
eg.
[root@localhost etc]# cat -n /etc/fstab
1
2 #
3 # /etc/fstab
4 # Created by anaconda on Wed Dec 27 05:37:20 2017
5 #
6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
8 #
9 /dev/mapper/centos-root / xfs defaults 0 0
10 UUID=88f65953-7d6a-4149-b009-17e4d233477e /boot xfs defaults 0 0
11 /dev/mapper/centos-swap swap swap defaults 0 0
[root@localhost etc]# cat -E /etc/fstab
$
#$
# /etc/fstab$
# Created by anaconda on Wed Dec 27 05:37:20 2017$
#$
# Accessible filesystems, by reference, are maintained under '/dev/disk'$
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info$
#$
/dev/mapper/centos-root / xfs defaults 0 0$
UUID=88f65953-7d6a-4149-b009-17e4d233477e /boot xfs defaults 0 0$
/dev/mapper/centos-swap swap swap defaults 0 0$
[root@localhost etc]#
[root@localhost etc]# tac /etc/fstab
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=88f65953-7d6a-4149-b009-17e4d233477e /boot xfs defaults 0 0
/dev/mapper/centos-root / xfs defaults 0 0
#
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
# Accessible filesystems, by reference, are maintained under '/dev/disk'
#
# Created by anaconda on Wed Dec 27 05:37:20 2017
# /etc/fstab
#
file : 查看文件类型
file FILENAME ...
eg.
[root@localhost etc]# file /etc/fstab
/etc/fstab: ASCII text
[root@localhost etc]#
[root@localhost etc]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=3d705971a4c4544545cb78fd890d27bf792af6d4, stripped
[root@localhost etc]#
echo : 回显
echo [SHORT-OPTION]... [STRING]...
-n : 不进行换行
-e : 让转义符生效
\n : 换行
\t : 制表符
eg.
[root@localhost etc]# echo "hello word"
hello word
[root@localhost etc]#
[root@localhost etc]# echo -n "hello word"
hello word[root@localhost etc]#
[root@localhost etc]#
[root@localhost etc]# echo -e "hello \nword"
hello
word
[root@localhost etc]#
[root@localhost etc]# echo -e "hello \vword"
hello
word
[root@localhost etc]#
[root@localhost etc]# echo -e "hello \tword"
hello word
[root@localhost etc]#
STRING 可以使用引号,单引号和双引号均可使用;
单引号:强引用,变量引用不执行替换;
双引号:弱引用,变量引用会被替换;
PS : 变量引用的正规符号 $(name)
eg.
[root@localhost etc]#
[root@localhost etc]# echo '$SHELL'
$SHELL
[root@localhost etc]# echo "$SHELL"
/bin/bash
[root@localhost etc]#
shutdown : 关机或重启命令
shutdown [OPTIONS...] [TIME] [WALL...]
OPTIONS :
-h : halt 关机
-r : reboot
-c : cancel 取消关机或重启动作
TIME :
now : 立刻,马上
hh:mm : 几小时几分钟执行关机或重启动作
+m : 几分钟后执行关机或重启动作
WALL : 用双引号,双引号里面的内容可以传至登录系统的其他终端
eg.
[root@localhost etc]# shutdown -h 17:30
Shutdown scheduled for Sun 2018-03-11 17:30:00 CST, use 'shutdown -c' to cancel.
[root@localhost etc]#
[root@localhost etc]# shutdown -c
[root@localhost etc]#
Broadcast message from root@localhost.localdomain (Sun 2018-03-11 16:56:23 CST):
The system shutdown has been cancelled at Sun 2018-03-11 16:57:23 CST!
[root@localhost etc]# shutdown -h +15
Shutdown scheduled for Sun 2018-03-11 17:11:42 CST, use 'shutdown -c' to cancel.
[root@localhost etc]#
Broadcast message from root@localhost.localdomain (Sun 2018-03-11 16:56:42 CST):
The system is going down for power-off at Sun 2018-03-11 17:11:42 CST!
[root@localhost etc]# shutdown -c
Broadcast message from root@localhost.localdomain (Sun 2018-03-11 16:56:54 CST):
The system shutdown has been cancelled at Sun 2018-03-11 16:57:54 CST!
[root@localhost etc]#
[root@localhost etc]# shutdown -r +15 "hello word"
Shutdown scheduled for Sun 2018-03-11 17:13:53 CST, use 'shutdown -c' to cancel.
[root@localhost etc]#
Broadcast message from root@localhost.localdomain (Sun 2018-03-11 16:58:53 CST):
hello word
The system is going down for reboot at Sun 2018-03-11 17:13:53 CST!
[root@localhost etc]# shutdown -c
Broadcast message from root@localhost.localdomain (Sun 2018-03-11 16:59:16 CST):
The system shutdown has been cancelled at Sun 2018-03-11 17:00:16 CST!
[root@localhost etc]#
日期相关的命令:date , clock , hwclock , cal
linux : 系统启动时从硬件读取日期和时间信息;读取完后就不再与硬件相关联,系统内部以软件方式维护日期和时间信息.
date : 显示或修改系统日期和时间(系统时钟)
显示日期时间 : date [OPTION]… [+FORMAT]
设定日期时间 : date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]
eg. [root@localhost ~]# date +%F 2018-03-11 [root@localhost ~]# date +%A Sunday [root@localhost ~]# date +"%F %A" 2018-03-11 Sunday [root@localhost ~]# [root@localhost ~]# date +"%F %A %T" 2018-03-11 Sunday 17:17:48 [root@localhost ~]# [root@localhost ~]# [MMDDhhmm[[CC]YY][.ss]] 月日小时分钟年(年:2位数或4位数).秒钟 eg. ~]# date 0912352018.02 ~]# date 08114218.03 ~]# date 0710542018 clock / hwclock : 查询或设定硬件时钟(硬件时钟) [root@localhost ~]# which clock /usr/sbin/clock [root@localhost ~]# file /usr/sbin/clock /usr/sbin/clock: symbolic link to `hwclock' [root@localhost ~]# -s, --hctosys 以硬件时钟为准 -w, --systohc 以系统时钟为准 eg. [root@localhost ~]# date 显示系统时钟 Sun Mar 11 17:45:28 CST 2018 [root@localhost ~]# [root@localhost ~]# hwclock 显示硬件时钟 Mon 12 Mar 2018 01:44:33 AM CST -0.678370 seconds [root@localhost ~]# [root@localhost ~]# hwclock -w [root@localhost ~]# [root@localhost ~]# date Sun Mar 11 17:52:02 CST 2018 [root@localhost ~]# hwclock Sun 11 Mar 2018 05:52:07 PM CST -0.115748 seconds [root@localhost ~]#
cal : 显示日历
cal [[month] year]
eg.
[root@localhost ~]#
[root@localhost ~]# cal
March 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
[root@localhost ~]# cal 03 2018
March 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
[root@localhost ~]# cal 2018
2018
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 1
8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8
15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15
22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22
29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29
30
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 1
7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31