Linux系统用户
两类系统用户:
- 超级用户(root):#
- 普通用户:$
用户登录后可以根据需要切换身份:
root可以任意切换为任何其他用户;普通用户A切换为用户B时要输入用户B的登录密码。
# su - tom #root切换为tom
$ su - tom #切换为tom,需要输入tom的登录密码
$ su - root #切换为root,需要输入root的登录密码
$ su - #同上,省略用户名时默认切换为root
# exit #切换回上一用户身份或注销,快捷键Ctrl-d
关机、重启
# shutdown -h now #立即关机并关闭电源
# shutdown +10 "system will shutdown in 10m."
# shutdown -c "shutdown has been canceled."
# halt #停机但不关闭电源
# shutdown -r now #重启
# reboot
# poweroff
echo命令
$ echo hello,linux! #输出hello,linux!
$ echo "hello,linux!" #输出hello,linux!
$ echo hello! \ #注意连接符\前有空格
> nice to meet you! #输出hello! nice to meet you!
$ echo "to be or not to be, #带有引号回车才能继续输入,否则会直接输出
> that's a question." #输出to be or not to be,
# that;s a question.
$ echo -e "Life was like a box of chocolates, #-e让转义符生效
\nyou never know what you're gonna get." #输出Life was like a box of chocolates,
# you never know what you're gonna get.
查看当前工作目录:pwd
切换目录:cd /usr/share/doc
cd ~
cd -
cd
时间日历
date
$ date #查看日期时间
$ date +%H:%M #几点几分
$ date "+%B %d" #几月几号
$ date --date "2020-10-1" +%A #国庆节星期几
$ date -s "2020-03-10 10:10:10" #设置当前时间
$ timedatectl #查看详细时间
$ timedatectl set-time "2020-03-10 10:10:10" #设置当前时间
cal
$ cal #本月月历
$ cal 2020 #2020年历
$ cal 9 1752 #1752年9月月历
文件系统层次标准
绝对路径与相对路径
$ cd /home/bob #/是根目录,以/开头的是绝对路径
$ cat .bashrc #当前目录下的bashrc文件,是相对路径
$ cat note/linux.txt #相对路径,最左边没有出现根目录
$ cd main.c #相对路径
$ cat ../proj2/proj2.h#相对路径,..表示上一级目录
$ cat /etc/fstab #绝对路径
$ pwd #输出当前目录
$ cd #回到用户主目录
查看文件内容
cat和tac
$ cat tea #顺序打印tea
$ tac tea #倒序打印tea
$ cat -n tea butterfly #带行号打印tea和butterfly
more和less
$ more /etc/services #可以往下翻页查看文件,但不能返回查看前面已经看过的,按q退出
$ less /etc/services #可以上下翻页,按q退出
head和tail
$ head summer-flower #默认显示前十行
$ head -n 20 summer-flower #打印前20行
$ head -n -110 summer-flower #打印最后110行
$ tail summer-flower #默认显示最后十行
$ tail -n 3 summer-flower #显示最后三行
$ tail -n +114 summer-flower #显示从第114行到最后
$ tail -f /var/log/messages #持续显示文件末尾追加的行,按Ctrl-c终止
广而告之和请勿打扰
wall
$ wall 'Pay attention! There comes BIG news!'
mesg
$ mesg n #请勿打扰
$ mesg y #欢迎来访
$ who -w #查看用户是否屏蔽消息