免密码登录(只是为了方便教学,免了图形界面的密码)
1,Linux免密自动以root身份登录图形化界面,修改etc/gdm/custom.conf 在deamon下面添加两行,注意区分大小写
[daemon] AutomaticLoginEnable=true AutomaticLogin=root
2,windows查看地址,除了ipconfig,还可以使用ip a来查看。
3,图形编辑工具,gedit工具可以在图形界面下使用。但是远程登录的界面是没有办法使用的,图形编辑是有保存按钮的
4,文本编辑工具:nano AutomaticLoginEnable = true,AutomaticLogin = root 注意区分大小写,字符界面编辑器,不支持鼠标确定保存,只可以用按键来实现退出保存。
用户登录
1,系统中判断是管理员还是其他用户,看的是唯一编号UID,为0得话就是root
2,查看uid命令,6版本普通用户从500开始,但是7版本从1000开始,id可以默认也可以自由指定
id -u id -u lisa
终端
1,终端有很多很多种,图形终端默认只有一个,字符终端可以打开很多个
2,图形界面切换到字符终端 ctrl+alt+f2
3,alt + f1就又切换回图形界面了
4,图形界面下alt + f*又可以打开新的字符终端了,*号代表按的是F几,tty命令也可以查看
5,如何查看当前有哪些人登录了界面,分别在哪个终端,使用who命令
6,通常来说带tty这种的都是本地登录的,pts这种的就是远程登录的
7,临时切换到字符界面得话,图形界面不会关闭的,init 3 执行这个命令会自动切换到字符界面,并且关闭图形界面,这种切换也叫做模式切换
8,查看当前的运行模式 runlevel,运行结果,刚才的模式,现在的模式
9,init 5代表切换回图形,5代表图形
10,字符界面切换回图形界面,还有另外一种方式,就是startx,startx不认为是模式切换,只不过是开启了一个图形终端,图形界面而已
11,Linux里面的图形,只是一个软件,不是操作系统必须的,但是Windows的图形界面是必须要有的,属于核心的东西
12,startx打开的图形界面,按一下ctrl+z就关闭了,就是相当于把这个程序关闭了而已
13,模式切换只可以用init命令,模式切换不只是开始图形,也会开启一些后台的服务,
14,工作中尽量避免切换,容易切换死机,毕竟是个比较大的动作
15,切换的话ctrl+alt+f2,如果已经在字符界面了可以不用按ctrl了就,就可以切换到一个新的字符终端了
16,如果按键有问题,可以用命令来切换终端,chvt 1/chvt 6 change virtual terminal
17,切换模式的话,必须要root权限,普通用户不可以的 init不可以执行,但是startx是可以的
[root@red-hat-enterprise-linux ~]# id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [root@red-hat-enterprise-linux ~]# id lisa uid=1000(lisa) gid=1000(lisa) groups=1000(lisa),10(wheel) [root@red-hat-enterprise-linux ~]# id -u 0 [root@red-hat-enterprise-linux ~]# id -u root 0 [root@red-hat-enterprise-linux ~]# id -u lisa 1000 [root@red-hat-enterprise-linux ~]# who root :0 Apr 16 21:12 (:0) root pts/0 Apr 16 21:11 (10.211.55.2) root pts/1 Apr 16 21:12 (:0) root tty2 Apr 16 21:10 root tty5 Apr 16 21:10 root tty6 Apr 16 21:16 [root@red-hat-enterprise-linux ~]# tty /dev/pts/0 [root@red-hat-enterprise-linux ~]# who am i root pts/0 Apr 16 21:11 (10.211.55.2) [root@red-hat-enterprise-linux ~]# whoami root
[root@red-hat-enterprise-linux ~]# tty /dev/pts/0 [root@red-hat-enterprise-linux ~]# who am i root pts/0 Apr 16 21:11 (10.211.55.2) [root@red-hat-enterprise-linux ~]# whoami root [root@red-hat-enterprise-linux ~]# who a b root pts/0 Apr 16 21:11 (10.211.55.2) [root@red-hat-enterprise-linux ~]# who i m root pts/0 Apr 16 21:11 (10.211.55.2) [root@red-hat-enterprise-linux ~]# who root :0 Apr 16 21:12 (:0) root pts/0 Apr 16 21:11 (10.211.55.2) root pts/1 Apr 16 21:12 (:0) root tty2 Apr 16 21:10 root tty5 Apr 16 21:10 root tty6 Apr 16 21:16 [root@red-hat-enterprise-linux ~]# w 21:20:36 up 1:02, 6 users, load average: 0.00, 0.04, 0.08 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 :0 21:12 ?xdm? 34.59s 0.07s gdm-session-wor root pts/0 10.211.55.2 21:11 4.00s 0.05s 0.01s w root pts/1 :0 21:12 8:12 0.02s 0.02s /bin/bash root tty2 21:10 10:20 0.01s 0.01s -bash root tty5 21:10 9:40 0.01s 0.01s -bash root tty6 21:16 3:56 0.05s 0.05s -bash [root@red-hat-enterprise-linux ~]#
[root@red-hat-enterprise-linux ~]# init 3 PolicyKit daemon disconnected from the bus. We are no longer a registered authentication agent. [root@red-hat-enterprise-linux ~]# runlevel 5 3
[root@red-hat-enterprise-linux ~]# chvt 4 [root@red-hat-enterprise-linux ~]# chvt 5
Shell介绍
1,翻译官 command interpreter
2,bash是一直在运行的,把我们敲的命令,转化成计算机能识别的,默认的shell类型
3,不同的shell翻译的也有一些差别的,我们掌握最基本的就好
4,shell会捕获我们输入的命令,shell的接口是隐藏的,我们看不见的
5,shell可以翻译,同时shell也是一种编程语言,可以实现一些稍微复杂的逻辑关系
6,bash默认都有的,即使没有,只要装上就可以用了,就是一个软件而已
7,Linux只是显示最后一层,window的console会显示完整的路径
8,波浪符号代表家目录,#代表的是root
9,提示符号可以根据需要修改,从删库到跑路 哈哈哈
10,命令提示符号是可以修改的,但是有个小问题就是,如果修改完,exit,再进来,之前的修改就无效了,如果想要保存得住的话,那么就需要保存在一个文件里面
11,除了修改命令提示符的内容,还可以修改颜色,闪烁,背景色,字体颜色
12,字体颜色总共就7个数 31-37,31红,32绿,34蓝,35紫色
/etc/shell
13,最后的e 0m代表颜色到此结束 Shell Variables
[root@red-hat-enterprise-linux ~]# echo $SHELL /bin/bash [root@red-hat-enterprise-linux ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /bin/tcsh /bin/csh [root@red-hat-enterprise-linux ~]# /bin/csh [root@red-hat-enterprise-linux ~]# echo $SHELL /bin/bash [root@red-hat-enterprise-linux ~]# enable enable bash是内置的 enable: Command not found.
[root@red-hat-enterprise-linux ~]# /bin/csh [root@red-hat-enterprise-linux ~]# exit exit
[root@red-hat-enterprise-linux ~]# ls Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos [root@red-hat-enterprise-linux ~]# > f1 [root@red-hat-enterprise-linux ~]# ls Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1 [root@red-hat-enterprise-linux ~]# /bin/csh [root@red-hat-enterprise-linux ~]# > f1 Invalid null command. [root@red-hat-enterprise-linux ~]# ls
[root@red-hat-enterprise-linux ~]# ll f1 # 大小是0 -rw-r--r--. 1 root root 0 Apr 16 21:31 f1
[root@red-hat-enterprise-linux ~]# echo {$SHELL} /bin/bash
[root@red-hat-enterprise-linux ~]# hostname red-hat-enterprise-linux.shared
[root@red-hat-enterprise-linux ~]# echo $PS1 [u@h W]$ [root@red-hat-enterprise-linux ~]# man bash search PS1 then prompting
[root@red-hat-enterprise-linux ~]# echo $PS1 #自己改的井号没有了 [u@h W]$ [root@red-hat-enterprise-linux ~]# PS1="{u@H }" {root@red-hat-enterprise-linux.shared 21:41:00} {root@red-hat-enterprise-linux.shared 21:41:05}
命令提示符
1,# 管理员 $普通用户
2,PS1 e 33 u前用户 h主机名简称 H主机名 w当前工作目录 W当前工作目录基名 24小时时间格式 T 12小时工作格式 !命令数历史 #开机后命令历史
3,PS1=“[e[1;5;41;33m][u@h W]\$[e[0m]”
4,PS1="[e[31m][u@h W]\$[e[0m]"我最终执行的命令
5,之前的#出不来是因为在$符号的后面多了一个空格,脚本的严谨性,见识了
执行命令
1,命令分为两种,内部命令和外部命令,所谓内部命令指是和shell密切相关的命令
2,系统只要一登陆,账号只要一登陆,bash就会运行,所谓运行就是已经加载到内存中了
3,bash程序对应的文件是/bin/bash,bash除了有翻译功能,另外呢bash里面自身还有一些工具,集成在里面,由于bash,开机就运行,那也就意味着,这些程序也开始运行了就,这一部分程序,就叫做内部命令,例如enable
4,内部命令是集成在shell里面的,也就是bash里面,不同的shell,系统集成的内部命令是不同的
5,内部命令有哪些呢?敲击enable,列出的所有命令列表,就是所有的内部命令列表
6,因为内部命令直接在内存中,所以运行内部命令速度非常快的
7,有很多命令不是在内存中的,他只是在磁盘上的一个文件,就好比/bin/bash,他对应的也是磁盘上的一个物理文件
8,bin目录里面还有很多绿色的可执行文件,这些文件是需要用户人为的操作的时候才会运行,不会自动加载到内存,所以这部分文件又叫做外部命令
例如:who,如何查看一个命令是内部命令还是外部命令,我们可以用type命令来看,如果能给出具体的路径就是外部命令,内部命令会给出,是一个shell buildin命令
[root@red-hat-enterprise-linux ~]$ type who who is /usr/bin/who [root@red-hat-enterprise-linux ~]$ type enable enable is a shell builtin
9,外部命令既然能直接找到命令的可执行文件,如何办到的呢,肯定不是一个文件一个文件的执行的
10,找到外部命令确实用到了搜索,但是不是全部去搜索,而是去几个固定路径里面去搜索的,这几个固定路径保存在$PATH变量里面,按照顺序搜索
[root@red-hat-enterprise-linux ~]$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
11,有个有意思的命令,yes,作用就是不停的敲击y
12,yes hello它就会不停的敲击hello,这个命令就是干这个的
13,禁用内部命令 enable -n type,禁用只有再敲击enable就没有这个命令了
[root@red-hat-enterprise-linux ~]$ enable -n type [root@red-hat-enterprise-linux ~]$ type who bash: type: command not found... [root@red-hat-enterprise-linux ~]$ enable -n # 查看所有禁用的命令 enable -n type
[root@red-hat-enterprise-linux ~]$ enable type [root@red-hat-enterprise-linux ~]$ type who who is /usr/bin/who
14,如果一个命令即是内部命令,也是外部命令,那么他会优先去使用内部命令的
15,help 会列出所有内部命令的基本用法,如果命令前面有星号,就代表该命令已经被禁用了
16,时间不准确是一个很严重的问题,尤其是到了后面大规模的集群环境的时候,时间非常的关键
17,同步时间 ntpdate 同步完如果出现offset之类的字样,说明同步成功了
ntpdate 192,168,X.X 这儿显示的是ntp server 地址
[root@red-hat-enterprise-linux ~]$ date Tue Apr 16 22:11:21 CST 2019 [root@red-hat-enterprise-linux ~]$ type date date is hashed (/usr/bin/date)
18,为何修改了外部命令的路径无效呢?缓存,这个动作叫做hash,下次运行的时候,如果内存中有的话,就直接去内存运行而不再去找了,只有第一次修改路径会生效
19,如何查看已经缓存到内存的命令呢? hash命令 hash -r清除缓存 -l -p -d
[root@red-hat-enterprise-linux ~]$ hash
hash: hash table empty
[root@red-hat-enterprise-linux ~]$ hash - p /usr/bin/yes no
[root@red-hat-enterprise-linux ~]$ date Tue Apr 16 22:11:21 CST 2019 [root@red-hat-enterprise-linux ~]$ type date date is hashed (/usr/bin/date) [root@red-hat-enterprise-linux ~]$ hash hits command 2 /usr/bin/date [root@red-hat-enterprise-linux ~]$ who root pts/0 Apr 16 21:56 (10.211.55.2) root tty2 Apr 16 21:10 root tty5 Apr 16 21:10 root tty1 Apr 16 21:23 root tty6 Apr 16 21:16 [root@red-hat-enterprise-linux ~]$ hash hits command 2 /usr/bin/date 1 /usr/bin/who
[root@red-hat-enterprise-linux ~]$ hash hits command 2 /usr/bin/date 1 /usr/bin/who [root@red-hat-enterprise-linux ~]$ hash -d date 删除 [root@red-hat-enterprise-linux ~]$ hash hits command 1 /usr/bin/who
20,当然hash有效期只限于本次登录,退出再登录就无效了
21,which命令查看外部命令对应的路径 -a所有路径,不加-a也就是默认只搜索一个
[root@red-hat-enterprise-linux ~]$ which who /usr/bin/who [root@red-hat-enterprise-linux ~]$ which -a who /usr/bin/who
[root@red-hat-enterprise-linux ~]$ where is who bash: where: command not found... [root@red-hat-enterprise-linux ~]$ whereis who who: /usr/bin/who /usr/share/man/man1p/who.1p.gz /usr/share/man/man1/who.1.gz
22,要求上课听懂就行,用得多了,自然就记住了
23,命令提示符:prompt。# 管理员 ¥ 普通用户
PS1="{u@H }" #必须有引号 "/etc/profile.d/env.sh" # 环境变量
{root@red-hat-enterprise-linux.shared 21:50:26}PS1='[e[1;5;41;33m][u@h W]\$[e[0m]' [root@red-hat-enterprise-linux ~]$
$PS1='[e[31m][u@h W]\$ [e[0m]'。 最后面一部分不可以少,不然就全部变色了
24,搜索和使用外部命令的时候,注意缓存的影响,再次登陆,缓存清空
命令别名
1,别名也是用的非常多的
[root@red-hat-enterprise-linux network-scripts]$ alias cdnet ="cd /etc/sysconfig/network-scripts/" #等号前面有个空格所以失败 -bash: alias: cdnet: not found -bash: alias: =cd /etc/sysconfig/network-scripts/: not found [root@red-hat-enterprise-linux network-scripts]$ alias cdnet="cd /etc/sysconfig/network-scripts/"
[root@red-hat-enterprise-linux network-scripts]$ alias alias cdnet='cd /etc/sysconfig/network-scripts/'# 新定义的别名出现了 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'
[root@red-hat-enterprise-linux network-scripts]$ cd / [root@red-hat-enterprise-linux /]$ cdnet [root@red-hat-enterprise-linux network-scripts]$
2,自己定义的别名退出之后再次登陆,就又没有了,要想把变量永久生效,就要写到文件里面,写到规定的文件里面,每个用户的家目录里面有一个点bashrc文件
3,.bashrc这个文件里面一般会写别名,但是新加入的那一行别名,不会马上生效,最简单的办法,退出再次登陆,可以生效,还有另外一种,就是用点或者source文件使其生效
[root@red-hat-enterprise-linux ~]$ ls -a . .bash_logout .cshrc .ssh Downloads Videos .. .bash_profile .history .tcshrc Music anaconda-ks.cfg .ICEauthority .bashrc .lesshst .viminfo Pictures f1 .Xauthority .cache .local Desktop Public .bash_history .config .parallels Documents Templates [root@red-hat-enterprise-linux ~]$ vim .bashrc
# .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias cdnet='/etc/sysconfig/network-scripts/' #这儿双引号,单引号都可以 # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
4,点或者source命令,可以简单的理解成去读取这个文件,读取里面的内容,放到内存里面,放到内存了都,肯定也就生效了
[root@red-hat-enterprise-linux ~]$ vim .bashrc [root@red-hat-enterprise-linux ~]$ . .bashrc [root@red-hat-enterprise-linux ~]$ type . . is a shell builtin [root@red-hat-enterprise-linux ~]$ enable enable . enable : enable [ enable alias enable bg enable bind enable break enable builtin enable caller
[root@red-hat-enterprise-linux ~]$ source .bashrc
5,点本身是命令吗?是的,是一个内部命令的,查看enable可以看到的
6,优先级:别名》内部〉外部,尽可能不要让他冲突
[root@red-hat-enterprise-linux ~]$ alias enable=who [root@red-hat-enterprise-linux ~]$ who root :0 Apr 17 14:38 (:0) root pts/0 Apr 17 15:09 (10.211.55.2) [root@red-hat-enterprise-linux ~]$ enable root :0 Apr 17 14:38 (:0) root pts/0 Apr 17 15:09 (10.211.55.2)
[root@red-hat-enterprise-linux ~]$ enable -n who who: invalid option -- 'n' Try 'who --help' for more information. [root@red-hat-enterprise-linux ~]$ unalias enable [root@red-hat-enterprise-linux ~]$ enable -n who -bash: enable: who: not a shell builtin
7,echo不是所有的shell都内置,只是保证无论何时都能正常运行echo,所以外部也准备好了
[root@red-hat-enterprise-linux ~]$ unalias enable [root@red-hat-enterprise-linux ~]$ enable -n who -bash: enable: who: not a shell builtin [root@red-hat-enterprise-linux ~]$ type echo echo is a shell builtin [root@red-hat-enterprise-linux ~]$ enable -n echo [root@red-hat-enterprise-linux ~]$ type echo echo is /usr/bin/echo [root@red-hat-enterprise-linux ~]$ echo 'hello' hello
/etc/bashrc和及目录的.bashrc
8,.bashrc默认是放在root的家目录下的,所以只对root账号生效,如果想对所有用户都生效,需要放在/etc/bashrc里面,但是一般不建议更改这个文件,因为这个文件是全局性的文件,影响太大,一般修改影响自己就可以了
9,别名有时候和原来的命令名称是一样的,输入命令默认是调用别名的,那如何使用原来的命令呢?敲入命令全路径就可以了,但是这种方法只适合外部命令,因为内部命令根本就没有路径可言
[root@red-hat-enterprise-linux ~]$ alias ls alias ls='ls --color=auto' [root@red-hat-enterprise-linux ~]$ which ls 别名和原来命令一样 alias ls='ls --color=auto' /usr/bin/ls [root@red-hat-enterprise-linux ~]$ /usr/bin/ls #使用原始的命令,而不是别名 Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1 [root@red-hat-enterprise-linux ~]$ /usr/bin/ls --color=auto Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1
10,内部如何使用原始内部命令呢?可以用两个单引号引起原来的命令也可以,或者用斜线也可以的
[root@red-hat-enterprise-linux ~]$ 'ls' Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1 [root@red-hat-enterprise-linux ~]$ ls Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1
[root@red-hat-enterprise-linux ~]$ "ls" Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1 [root@red-hat-enterprise-linux ~]$ command ls Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1
11,取消别名 unalias ,取消所有别名 unalias -a 当然不要担心,取消只是针对当前这一个terminal的,关掉再次打开,就全都回来了
[root@red-hat-enterprise-linux ~]$ unalias -a [root@red-hat-enterprise-linux ~]$ alias [root@red-hat-enterprise-linux ~]$
12,which 命令默认会显示别名和命令,如果不想显示别名,可以用一个参数 --skip-alias,这些方法在特定的场景都会用到的
[root@red-hat-enterprise-linux ~]$ which ls alias ls='ls --color=auto' /usr/bin/ls [root@red-hat-enterprise-linux ~]$ which ls --skip-alias /usr/bin/ls
[root@red-hat-enterprise-linux ~]$ which --skip-alias ls # 不关心别名,只关心路径 /usr/bin/ls
命令格式
1,命令 选项 参数 ,长格式,短格式
[root@red-hat-enterprise-linux ~]$ ls --all . .bash_logout .cshrc .ssh Downloads Videos .. .bash_profile .history .tcshrc Music anaconda-ks.cfg .ICEauthority .bashrc .lesshst .viminfo Pictures f1 .Xauthority .cache .local Desktop Public .bash_history .config .parallels Documents Templates [root@red-hat-enterprise-linux ~]$ ls -a . .bash_logout .cshrc .ssh Downloads Videos .. .bash_profile .history .tcshrc Music anaconda-ks.cfg .ICEauthority .bashrc .lesshst .viminfo Pictures f1 .Xauthority .cache .local Desktop Public .bash_history .config .parallels Documents Templates
2,命令参数有的时候前后顺序是限制的,有的时候无所谓的
3,命令一直执行不停止,可以按ctrl c 或者ctrl z可以停止,老师说ctrl d有一些命令也可以,例如cat
4, 不敲击任何命令,按ctrl d相当于退出当前终端,相当于logout,exit
5,ctrl c是比较强硬的退出,有可能会丢失数据,如果能ctrl d最好ctrl d退出
6,多个命令可以写在一行,分号隔开就可以了
[root@red-hat-enterprise-linux ~]$ ls;hostname;id Desktop Downloads Pictures Templates anaconda-ks.cfg Documents Music Public Videos f1 red-hat-enterprise-linux.shared uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
7,一条命令写在多行里面,加 斜线就可以了,命令比较长的话,可以这么干
[root@red-hat-enterprise-linux ~]$ hos > tname red-hat-enterprise-linux.shared
8,换行别忘了加空格
日期和时间
1,Linux里面的时间有两个地方会记录下来,一个是系统时钟,Linux内核通过CPU频率记录,一个是硬件时钟,这个大家了解的是,即使不启动Windows,但是开机的时候进入到bios里,时间也是对的,这个就是硬件时钟,这两个时间有可能是不一致的
2,date命令看到的是当前的系统时间,内核的,说白了也就是软件时间
3,看主板的硬件时间,需要使用clock命令
[root@red-hat-enterprise-linux ~]$ date Fri Apr 19 10:34:41 CST 2019 [root@red-hat-enterprise-linux ~]$ clock Fri Apr 19 10:34:45 2019 -0.611484 seconds
4,date是可以改时间的,月日时钟年
[root@red-hat-enterprise-linux ~]$ date 041910362019.29 Fri Apr 19 10:36:29 CST 2019
5,clock -s硬件时间为准,同步系统时间 --hctosys 长格式
[root@red-hat-enterprise-linux ~]$ date 031003052018.15 Sat Mar 10 03:05:15 CST 2018 [root@red-hat-enterprise-linux ~]$ date Sat Mar 10 03:05:20 CST 2018 [root@red-hat-enterprise-linux ~]$ clock Fri Apr 19 10:39:22 2019 -0.627667 seconds [root@red-hat-enterprise-linux ~]$ clock -s [root@red-hat-enterprise-linux ~]$ date Fri Apr 19 10:39:32 CST 2019 [root@red-hat-enterprise-linux ~]$ clock Fri Apr 19 10:39:35 2019 -0.252533 seconds
6,clock -w系统时间为准,硬件时间来进行同步
7,date +%s当前时间距离1970年1月1日过了多少秒,因为69年unix诞生,所以把70年1月1号作为标准
[root@red-hat-enterprise-linux ~]$ date +%s 1555641671
8,也可以反过来转换
[root@red-hat-enterprise-linux ~]$ date -d @1555641671 Fri Apr 19 10:41:11 CST 2019
时区/etc/localtime
1,/etc/localtime这个文件里面定义的就是时区,这个文件不是一个文本文件,他不可以直接看的cat无效
[root@red-hat-enterprise-linux ~]$ ll /etc/localtime -rw-r--r--. 1 root root 388 Oct 2 2015 /etc/localtime [root@red-hat-enterprise-linux ~]$ cat /etc/localtime TZif����'p�����Z��6ip ~h�!Iap"^J�#)Cp$Gg%_�&'I&�A�(+(�#�~�p�CDTCSTTZif2 ����~6C)������������'p�������������Z��6ip ~h�!Iap"^J�#)Cp$Gg%_�&'I&�A�(+(�#�q�~�pLMTCDTCST CST-8
2,CentOS7上面有一个查 看所有时区命令,叫做timedatectl
[root@red-hat-enterprise-linux ~]$ timedatectl list-timezones
3,timedatectl status 查看当前的时区
[root@red-hat-enterprise-linux ~]$ timedatectl status Local time: Fri 2019-04-19 10:46:30 CST Universal time: Fri 2019-04-19 02:46:30 UTC RTC time: Fri 2019-04-19 02:46:30 Time zone: n/a (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
4,timedatectl set-timezone 可以设置时区,大小写敏感
[root@red-hat-enterprise-linux ~]$ timedatectl set-timezone Africa/Juba [root@red-hat-enterprise-linux ~]$ timedatectl status Local time: Fri 2019-04-19 10:48:10 CST Universal time: Fri 2019-04-19 02:48:10 UTC RTC time: Fri 2019-04-19 02:48:10 Time zone: Africa/Juba (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
5,这个命令指示7上面才有的,6上面是没有的
6,6上面命令是tzselect,先选洲,再选城市,去挑就可以了,其实他和7是一样的,最终修改的都是etc/localtime这个文件
7,其实时区他对应的真正的文件是/usr/share/zoneinfo/Asia
[root@red-hat-enterprise-linux share]$ cd zoneinfo [root@red-hat-enterprise-linux zoneinfo]$ ls Africa Canada GB Indian Mexico ROK iso3166.tab America Chile GB-Eire Iran NZ Singapore posix Antarctica Cuba GMT Israel NZ-CHAT Turkey posixrules Arctic EET GMT+0 Jamaica Navajo UCT right Asia EST GMT-0 Japan PRC US zone.tab Atlantic EST5EDT GMT0 Kwajalein PST8PDT UTC Australia Egypt Greenwich Libya Pacific Universal Brazil Eire HST MET Poland W-SU CET Etc Hongkong MST Portugal WET CST6CDT Europe Iceland MST7MDT ROC Zulu [root@red-hat-enterprise-linux zoneinfo]$ pwd /usr/share/zoneinfo
8,发现后面这两个文件时一样大的,其实就是设时区的时候,把文件指向需要的那个时区文件而已,实际上就是软连接或者硬连接实现的,后面会讲
[root@red-hat-enterprise-linux zoneinfo]$ ll /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -rw-r--r--. 1 root root 388 Oct 2 2015 /etc/localtime -rw-r--r--. 5 root root 388 Oct 2 2015 /usr/share/zoneinfo/Asia/Shanghai [root@red-
日历
1,这个月的日历cal
[root@red-hat-enterprise-linux zoneinfo]$ cal April 2019 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
2,查看某一年的日历cal 2019
3,过去某一年某一月的日历cal 8 2018
[root@red-hat-enterprise-linux zoneinfo]$ cal 8 2013 August 2013 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
4,cal 9 1752这个月是有误差的,因为他要靠这个月来调整误差的中间一下子少了好多天,我们现在可能也有误差,累积很多年就要调整了
[root@red-hat-enterprise-linux zoneinfo]$ cal 9 1752 September 1752 Su Mo Tu We Th Fr Sa 1 2 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
简单命令
1,之前讲过关机就是halt,shutdown,
2,重启reboot,其实reboot也可以用来关机,加一个参数 reboot -p 强制关机时 reboot -f
3,比较专业的关机命令:shutdown 可以关机-h,重启-r,取消关机-c
4,window也有shutdown命令,如果在下载一个大文件,很久才可以下载完,可以执行一个命令,两个小时后关机
5,设定了5分钟后关机,终端一直执行这个命令不退出得话,可以执行ctrl c退出 shutdown -r +5,不加默认为+1,立刻的话是now,
[root@red-hat-enterprise-linux zoneinfo]$ shutdown -r +5 Shutdown scheduled for Fri 2019-04-19 11:00:55 CST, use 'shutdown -c' to cancel. [root@red-hat-enterprise-linux zoneinfo]$ Broadcast message from root@red-hat-enterprise-linux.shared (Fri 2019-04-19 10:55:55 CST): The system is going down for reboot at Fri 2019-04-19 11:00:55 CST!
[root@red-hat-enterprise-linux ~]$ shutdown -r 18:30 'reboot at time 18:30' Shutdown scheduled for Sat 2019-04-20 18:30:00 CST, use 'shutdown -c' to cancel. [root@red-hat-enterprise-linux ~]$
6,设定了关机,所有打开的终端都能看到的
System is going down. Last login: Fri Apr 19 10:23:08 2019 from 10.211.55.2 -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory [root@red-hat-enterprise-linux ~]$ Broadcast message from root@red-hat-enterprise-linux.shared (Fri 2019-04-19 10:56:55 CST): The system is going down for reboot at Fri 2019-04-19 11:00:55 CST! shutdown -c Broadcast message from root@red-hat-enterprise-linux.shared (Fri 2019-04-19 10:57:12 CST): The system shutdown has been cancelled at Fri 2019-04-19 10:58:12 CST! [root@red-hat-enterprise-linux ~]$
7,可以通过命令 shutdown -c 来取消关机
8,也可以明确指定几点几分关机
9,关机时可以➕提示消息,比方说,机器在几点几分要关机了,请大家及时保存手头的工作内容
[root@red-hat-enterprise-linux ~]$ shutdown -r +5 'system is going to poweroff in 5mins' Shutdown scheduled for Fri 2019-04-19 11:04:06 CST, use 'shutdown -c' to cancel. [root@red-hat-enterprise-linux ~]$ Broadcast message from root@red-hat-enterprise-linux.shared (Fri 2019-04-19 10:59:06 CST): system is going to poweroff in 5mins The system is going down for reboot at Fri 2019-04-19 11:04:06 CST!
10,一般维护工作得话,还是加上提示消息比较好
11,如果提示消息为中文,那么可能secureCRT显示正常,但是原来系统终端不可以,那是因为,原系统不支持中文,但是SecureCRT是支持中文的
12,打印现在系统语言 echo $LANG
[root@red-hat-enterprise-linux zoneinfo]$ echo $LANG en_US.UTF-8
/etc/sysconfig/i18n
13,有个文件记录了系统的语言/etc/sysconfig/i18n
14,修改为zh_CN.UTF-8
15,让刚修改的变量生效 点运行一下
16,wall命令是用来发广播的,发通知的,只要登陆到这台机器的人,都可以收到
[root@red-hat-enterprise-linux zoneinfo]$ wall '你好' Broadcast message from root@red-hat-enterprise-linux.shared (pts/2) (Fri Apr 19 11:00:45 2019): 你好
17,如果没有安装中文包得话显示还是有问题的,即使设置字体是中文的
screen
1,一个有意思的命令,screen,以后工作中可能会用到
2,远程协助,Windows可以用QQ,Windows还可以用VNC,这个Linux也支持的,VNC只可以支持图形界面,字符界面就不可以了
3,字符界面远程协助
4,screen软件需要单独进行安装的,图形方式老师就不介绍了,先说命令形式安装
5,所有的安装包都在光盘里面呢,sr0 找到他的挂载目录,也就是挂载点,df或者lsblk,里面的packages
6, df -- display free disk space 查看此盘列表
[root@red-hat-enterprise-linux zoneinfo]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 50G 3.7G 43G 8% / devtmpfs 480M 0 480M 0% /dev tmpfs 495M 8.0K 495M 1% /dev/shm tmpfs 495M 6.8M 488M 2% /run tmpfs 495M 0 495M 0% /sys/fs/cgroup /dev/sda1 477M 133M 315M 30% /boot /dev/mapper/VolGroup-lv_home 12G 41M 11G 1% /home Home 466G 72G 395G 16% /media/psf/Home iCloud 466G 72G 395G 16% /media/psf/iCloud tmpfs 99M 28K 99M 1% /run/user/0 /dev/sr0 152M 152M 0 100% /run/media/root/CDROM [root@red-hat-enterprise-linux zoneinfo]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 64G 0 disk |-sda1 8:1 0 500M 0 part /boot `-sda2 8:2 0 63.5G 0 part |-VolGroup-lv_root 253:0 0 50G 0 lvm / |-VolGroup-lv_swap 253:1 0 2G 0 lvm [SWAP] `-VolGroup-lv_home 253:2 0 11.5G 0 lvm /home sr0 11:0 1 152M 0 rom /run/media/root/CDROM sr1 11:1 1 1024M 0 rom
7,package里面有很多红色的rpm后缀的安装包文件
8,直接敲击这个命令 rpm -ivh screen 后面的敲击TAB键补全就行,也可以敲击全路径安装
9,图形界面必须登陆才会自动挂载的,不登陆不会自动挂载的,登陆Lisa,路径里面就不会显示root了
10,如果上来登陆的不是图形界面,不会自动挂载的,除非是图形界面才可以
11,另外6和7的自动挂载路径是不一致的
12,screen -S 会话名称,创建一个新回话,注意S必须是大写,加入会话screen -ls ,screen -x 加入到某个会话名称
[root@redhat7 ~]#screen -ls There are screens on: 17868.lisa (Attached) 17626.l (Attached) 2 Sockets in /var/run/screen/S-root.
13,退出全部会话,exit,如果只是想退出自己的会话,这时候screen就不存在了,ctrl a然后同时按d,那么当前的终端就临时detach了其他的这个终端还在,如果所有的终端都临时退出,就是显示detach状态,只要有一个终端还连着就不是 detach的
[root@redhat7 ~]#screen -S lisa [detached from 20258.lisa]
[root@redhat7 ~]#screen -ls There is a screen on: 20258.lisa (Attached) 1 Socket in /var/run/screen/S-root. [root@redhat7 ~]#screen -ls There is a screen on: 20258.lisa (Detached) 1 Socket in /var/run/screen/S-root.
14,临时退出的话,会话其实还保留着的,只不过没有人在里面了
15,这时候查看screen -ls 回现实detach的状态,这时候想要再加进来,screen r就又回来了
[root@redhat7 ~]#screen -r lisa
16,screen的另外一个好处,比方说我想要一个备份,需要一小时或者半小时,不希望中间断网,怎么办呢?开个回话就好了
[root@redhat7 ~]#screen -ls There is a screen on: 17868.lisa (Dead ???) Remove dead screens with 'screen -wipe'. 1 Socket in /var/run/screen/S-root.
17,避免连接中断无法执行
18,彻底退出screen 用exit命令,临时退出一会还想要进去的是ctrl a 同时按下d
echo
1,echo最基本的功能就是显示字符串
2,这个字符串也可以显示一些扩展功能,需要加一个e选项开启扩展功能
[root@red-hat-enterprise-linux zoneinfo]$ echo 'hello' hello [root@red-hat-enterprise-linux zoneinfo]$ echo 'hello ' hello [root@red-hat-enterprise-linux zoneinfo]$ echo -e 'hello ' hello [root@red-hat-enterprise-linux zoneinfo]$
3,回显,就是把后面跟的字符串重新显示一遍,类似雷达
4,echo v c(取消换行)
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'helloc' hello[root@red-hat-enterprise-linux zoneinfo]$
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'hel lo' hel lo
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'helvlovmam' hel lo mam
5,还可以发出声音 a,可以加在一个长时间任务的后面,用来提醒任务已经完成了,前提声卡要打开的,
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'a'
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'aaa bb' bba
[root@red-hat-enterprise-linux zoneinfo]$ echo -e 'aaa bb' aaa bb
6,bc是一个linux里面的计算器,可以指定ibash obash输入输出运算,可以做简单运算,也可以做指数运算,quit可以退出
7,hexdump这儿的0a其实AscII码是10,10代表的是换行
[root@red-hat-enterprise-linux zoneinfo]$ whatis hexdump whatis: can't set the locale; make sure $LC_* and $LANG are correct hexdump (1) - display file contents in ascii, decimal, hexadecimal, ... [root@red-hat-enterprise-linux zoneinfo]$ hexdump -c f1 0000000 a b c d 0000009 [root@red-hat-enterprise-linux zoneinfo]$ hexdump -C f1 00000000 61 0a 62 0a 63 0a 64 0a 0a |a.b.c.d..| 00000009 [root@red-hat-enterprise-linux zoneinfo]$ man hexdump man: can't set the locale; make sure $LC_* and $LANG are correct
8, nnn八进制,xhh十六进制
[root@red-hat-enterprise-linux ~]$ whatis bc whatis: can't set the locale; make sure $LC_* and $LANG are correct bc (1p) - arbitrary-precision arithmetic language bc (1) - An arbitrary precision calculator language [root@red-hat-enterprise-linux ~]$ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. ibase=16 97 151
[root@red-hat-enterprise-linux ~]$ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 2+3 5 2^4 16
[root@red-hat-enterprise-linux ~]$ echo -e '