1、圖形界面直接root 賬號登錄:
cd /etc/gdm/
[root@centos7 gdm]# grep -Ev '^#|^$' custom.conf [daemon] AutomaticLoginEnable=ture AutomaticLogin=root
2、查看管理員編號;uid爲 0是超級用戶
[root@centos7 ~]# id root -u
0
3、查看終端命令tty
4、 [root@centos7 ~]# w 19:55:27 up 54 min, 1 user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.30.1 19:25 7.00s 0.23s 0.04s w
5、init 3 進入字符界面; init 5 ,init 0,init 6;
runlevel 查看運行級別
chvt 代替快捷鍵
6、查看bash
echo $SHELL ; echo ${SHELL}
cat /etc/shells
7、切換shell程序 /bin/csh
8、命令提示符:
echo $PS1
man bash
文檔搜索PROMPTING 查看ps1配置
[root@centos7 network-scripts]#vim /etc/profile.d/env.sh PS1="\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]" [root@centos7 ~]#PS1="\[\e[1;31m\][\u@\h \W]\\[\e[0m\]"
9、內部/外部命令
查看內部命令:
enable .
enable :
enable [
enable alias
enable bg
enable bind
enable break
enable builtin
enable caller
enable cd
enable command
enable compgen
enable complete
enable compopt
enable continue
enable declare
enable dirs
enable disown
enable echo
enable enable
enable eval
enable exec
enable exit
enable export
enable false
enable fc
enable fg
enable getopts
enable hash
enable help
enable history
enable jobs
enable kill
enable let
enable local
enable logout
enable mapfile
enable popd
enable printf
enable pushd
enable pwd
enable read
enable readarray
enable readonly
enable return
enable set
enable shift
enable shopt
enable source
enable suspend
enable test
enable times
enable trap
enable true
enable type
enable typeset
enable ulimit
enable umask
enable unalias
enable unset
enable wait
確認內部命令:type
[root@centos7 ~]#type enable enable is a shell builtin
路徑變量
echo $PATH
[root@centos7 ~]#echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
清空緩存:hash -d ; hash -r
[root@centos7 ~]#hash hits command 1 /usr/bin/w [root@centos7 ~]#hash -d w [root@centos7 ~]#hash hash: hash table empty
10、別名:alias
which who
whereis who
[root@centos7 ~]#which ls alias ls='ls --color=auto' /usr/bin/ls
修改家目錄別名 [root@centos7 network-scripts]#grep -Ev "^#|^$" /root/.bashrc alias cdnet='cd /etc/sysconfig/network-scripts/' alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' if [ -f /etc/bashrc ]; then . /etc/bashrc fi
. /root/.bashrc
使用原始命令:\ls
取消所有別名,相對當前終端;unalias
查看路徑
[root@centos7 ~]#which ls alias ls='ls --color=auto' /usr/bin/ls [root@centos7 ~]#which --skip-alias ls /usr/bin/ls
11 命令格式:
iptables -nvL (有前後關係
ctrl +c 強制退出
ctrl +d logout 正常退出
命令長格式換行
[root@centos7 ~]#host\ > name centos7.magedu.com
12、date
date -R 查看時區
centos7:
timedatectl list-timezones
timedatectl status
tiemdatectl set-timezone Asia/Shanghai
hwclock -s 硬件時間同步軟件時間
hwclock -w 軟件時間同步硬件時間
date +%s
date -d @1580137760
date "+%F %T"
date -d "-2 day" +%A
date -d "-1day" +%F
date -s "-1day"
日曆:
cal -y
cal 8 2010 查看某年的日誌表
13、關機重啓;
shutdown 指定時間關機
[root@centos7 network-scripts]#shutdown 15:41 Shutdown scheduled for Tue 2020-01-28 15:41:00 CST, use 'shutdown -c' to cancel.
修改中文:
[root@centos7 network-scripts]#echo $LANG en_US.UTF-8 vim /etc/sysconfig/i18n LANG="zh_CN.UTF-8" . /etc/sysconfig/i18n
廣播:
wall "hello 你們好"
14、
15、screen
安裝screen
192.168.30.101
192.168.30.102 ;ssh 192.168.30.101
[root@centos7 Packages]#rpm -ivh ./screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm warning: ./screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] installing package screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 needs 4KB on the /run filesystem
1、共享會話
[root@centos7 Packages]#mkdir -pv /run/media/root/Centos\ 7\ x86_64
[root@centos7 Packages]#mount /dev/sr0 /run/media/root/Centos\ 7\ x86_64
cd
cd /run/media/root/Centos\ 7\ x86_64/Packages
[root@centos7 Packages]#rpm -ivh ./screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm
2、開啓screen
screen -S help 創建會話
screen -x help 加入會話
ctrl +a,d 剝離會話
screen -ls 查看會話
screen -r 恢復會話
exit 退出
3、拷貝文件需要30分鐘,開啓會話screen ;異常時,可以通過screen -r 恢復會話
[root@centos7 ~]#screen -r
16、echo
echo -e "\a"
hexdump f1 查看二進制
[root@centos7 ~]#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
61
97
quit
[root@centos7 ~]#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'.
obase=16
97
61
[root@centos7 ~]#echo -e "\033[1;31mmagedu\033[0m"
magedu
修改登錄提示界面motd:
[root@centos7 ~]#cat /etc/motd
拷貝信息文件:
cp `which --skip-alias ls ` /data
`` 變量命令
"" 變量
'' 字符串
echo {1..10}
echo {10..20..2}
echo {a..z}
echo f{1..3}
17 歷史 命令:
history
[root@centos7 ~]#echo $HISTSIZE
1000
cat /etc/profile 配置文件修改HISTSIZE
[root@centos7 ~]#vim ~/.bash_history 記錄了內存命令歷史;
ctrl +r搜索
ecs . 調用最後一個參數
history 清空 歷史:
[root@centos7 ~]#rm -f ~/.bash_history
histroy -c 清空歷史
history -a 保存歷史到文件中 ~/.bash_history
man bash 查看歷史幫助
history 歷史變量
vim /etc/profile # /etc/profile.d/env.sh HISTTIMEFORMAT="%F %T " HISTSIZE=1000 [root@centos7 ~]#echo $HISTFILE /root/.bash_history
18獲取幫助:
whatis 顯示命令的簡短描述
whatis rm
makewhatis censots6 製作數據庫
mandb centos7 製作數據庫
內部命令
help command
man command
man 章節:
/usr/share/man
whereis ls
[root@centos7 Packages]#whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
man 1 ls
man 查看文件所在的章節
[root@centos7 Packages]#whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
[root@centos7 Packages]#whatis passwd
passwd (1) - update user's authentication tokens
sslpasswd (1ssl) - compute password hashes
passwd (5) - password file
man 搜索:
/keyword 向文件尾部
n:
N:
?KEYWORD 向文件首部
n:
N:
/usr/share/doc
[root@centos7 ~]#sosreport 蒐集系統日誌信息
19 cat /etc/issue
[root@centos7 ~]#cat /etc/issue \S Kernel \r on an \m tty is \l hostname is \n
[root@centos7 ~]#man 8 agetty
l Insert the name of the current tty line. m Insert the architecture identifier of the machine. Same as `uname -m'. n Insert the nodename of the machine, also known as the hostname. Same as `uname -n'. o Insert the NIS domainname of the machine. Same as `hostname -d'. O Insert the DNS domainname of the machine. r Insert the release number of the OS. Same as `uname -r'. t Insert the current time. u Insert the number of current users logged in. U Insert the string "1 user" or "<n> users" where <n> is the number of current users logged in.
20 bash快捷鍵:
ctrl +l
ctrl +d/c
ctrl +a
ctrl +e
ctrl +u
ctrl +k