一个特殊的管理账户,也被称之为超级用户 , 拥有已接近完整的系统控制,对系统的伤害几乎有无线能力.
权限有限,造成损害能力比较有限.
设备终端:键盘,鼠标,显示器
tty命令可以查看当前终端
tty
范例:
[root@localhost ~]# tty
/dev/pts/0
who命令可以查看所有终端设备
who
范例:
[root@localhost ~]# who
root pts/0 2024-08-31 02:45 (192.168.43.1)
free命令可以查看
free
范例:
[root@localhost ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 700M 543M 17M 574M 950M
Swap: 2.0G 0B 2.0G
runlevel命令可以查看
runlevel
范例:
[root@localhost ~]# runlevel
5 3
init 0 3 5 6
ps aux 命令
ps aux
范例:
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 194040 7184 ? Ss 02:44 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 02:44 0:00 [kthreadd]
root 4 0.0 0.0 0 0 ? S< 02:44 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 02:44 0:00 [ksoftirqd/0]
root 7 0.0 0.0 0 0 ? S 02:44 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 02:44 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 02:44 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 02:44 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 02:44 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 02:44 0:00 [watchdog/1]
root 13 0.0 0.0 0 0 ? S 02:44 0:00 [migration/1]
root 14 0.0 0.0 0 0 ? S 02:44 0:00 [ksoftirqd/1]
root 16 0.0 0.0 0 0 ? S< 02:44 0:00 [kworker/1:0H]
echo $SHELL
案例:
[root@localhost ~]# echo $SHELL
/bin/bash
cat /etc/shells
hostname NAME //仅仅修改内存
vim /etc/hostname //修改配置文件
hostnamectl set-hostname NAME // 修改配置文件和内存
whoami
范例:
[root@wtj-wx-zyf ~]# whoami
root
[root@wtj-wx-zyf ~]# who am i
root pts/0 2024-08-31 03:43 (192.168.43.1)
切换位root账户
sudo -i
范例:
[wtj@wtj-wx-zyf ~]$ sudo -i
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.[sudo] password for wtj:
wtj is not in the sudoers file. This incident will be reported.
reboot
echo $PS1
范例:
[wtj@wtj-wx-zyf ~]$ echo $PS1
[\u@\h \W]\$
PS1=NAME //修改内存
echo "PS1=NAME" > etc/profile.d/env.sh //修改配置文件
file
范例:
[root@wtj-wx-zyf ~]# file love.s
love.s: ASCII text
输入命令 -> 查看命令类型(是否为内部命令--集成在/bin/bash下,或外部命令--存储在磁盘上)-> 若不是内部命令则按照$PATH的路径去寻找该命令
([root@wtj-wx-zyf ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
) 并且将该命令的路径记录在内存中--hash
type
type -a
案例:
[root@wtj-wx-zyf ~]# type echo
echo is a shell builtin //内部命令
[root@wtj-wx-zyf ~]# type cat
cat is /usr/bin/cat //外部命令[root@wtj-wx-zyf ~]# type -a echo //搜索所有内部命令何其同名的外部命令
echo is a shell builtin
echo is /usr/bin/echo
[root@wtj-wx-zyf ~]# hash //查看缓存
hits command
1 /usr/bin/lscpu
1 /usr/bin/file
2 /usr/bin/ls
hash -r //清楚缓存
hash -d name //清楚指定缓存
enable
help
案例:
[root@wtj-wx-zyf ~]# help
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.A star (*) next to a name means that the command is disabled.
job_spec [&] history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
(( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x command [args]
: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-> popd [-n] [+N | -N]
[root@wtj-wx-zyf ~]# enable
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 cmd //启用内部命令 --临时为写入etc文件
enable -n cmd //禁用内部命令
enable -n //查看所有被禁用的内部命令
which
whereis
案例:
[root@wtj-wx-zyf ~]# which echo
/usr/bin/echo
[root@wtj-wx-zyf ~]# whereis echo //同时显示man文件路径
echo: /usr/bin/echo /usr/share/man/man1/echo.1.gz /usr/share/man/man1p/echo.1p.gz
alias //别名优先级高于内部命令高于外部命令(别名-> 内部命令 ->外部命令)
unalias //取消别名 -a --所有
案例:
alias cdnet="cd /etc/sysconfig/network-scripts/"
unalias -a //取消所有别名
alias //查看所有别名
若想要使别名永久生效可在家目录下的 .bashrc文件中进行配置.
案例:
[root@wtj-wx-zyf ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc .config love.s mysql80-community-release-el7.rpm nano.save original-ks.cfg .tcshrc .Xauthority
.. .bash_history .bash_profile .cache .cshrc love.s,bak .mysql_history nano.save.1 passwd.sh .viminfo
[root@wtj-wx-zyf ~]# cat .bashrc
# .bashrc# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
可使用 / 来屏蔽别名优先使用原始命令
案例:
[root@wtj-wx-zyf ~]# type ls
ls is aliased to `ls --color=auto'
[root@wtj-wx-zyf ~]# ls
anaconda-ks.cfg love.s love.s,bak mysql80-community-release-el7.rpm nano.save nano.save.1 original-ks.cfg passwd.sh
[root@wtj-wx-zyf ~]# \ls
anaconda-ks.cfg love.s love.s,bak mysql80-community-release-el7.rpm nano.save nano.save.1 original-ks.cfg passwd.sh
COMMAND [ OPTIONS... ] [ ARGUMENS... ]
范例:
[root@wtj-wx-zyf ~]# id -u root //查看root账户的uid
0[root@wtj-wx-zyf ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 742M 453M 17M 623M 895M
Swap: 2.0G 0B 2.0G
[root@wtj-wx-zyf ~]# free --human
total used free shared buff/cache available
Mem: 1.8G 742M 454M 17M 623M 895M[root@wtj-wx-zyf ~]# ps a
PID TTY STAT TIME COMMAND
3432 tty1 Ss+ 0:00 /sbin/agetty --noclear tty1 linux
3671 tty2 Ss+ 0:00 /sbin/agetty --noclear tty2 linux
5241 pts/0 Ss 0:00 -bash
5960 pts/0 R+ 0:00 ps a
1. 多个选项以及多个命令之间可以使用空白字符分隔
2. 取消和结束命令可以使用: ctrl + c 和 ctrl + d
3. 多个命令可以使用 ; 分开
4 一个命令可以使用 \ 分成多行
lsblk
案例:
[root@wtj-wx-zyf ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 17.7G 0 part /
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
uptime
案例:
[root@wtj-wx-zyf ~]# uptime
05:23:34 up 2:38, 2 users, load average: 0.00, 0.01, 0.05
[root@wtj-wx-zyf ~]# 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=2 // 输出的位2进制
12
1100