1.如何关闭 linux 服务器?
方法一:halt
方法二:shutdown -h now
2.如何重启 linux 服务器?
方法一:reboot
方法二:shutdown -r now
3.请查看当前登录用户,如果是 root 用户,则切换到其他用户以下所有普通用户为 tianliang.。
查看当前登录用户:whoami
切换到 tianliang 用户:su tianliang
4.现在 root 用户登录,请修改 root 用户密码,并修改某普通用户的密码。
passwd [username]
如果不指定用户名则默认修改 root 用户的密码。注意:普通用户只能修改自己的密码。
5.切换到 tianliang 用户的 家目录下。
切换目录:cd /home/tianliang 6.在 tianliang 家目录中创建一个文件夹 study
创建目录:mkdir /home/tianliang/study
7.查看 tianliang 家目录下的文件或子目录
查看目录下的内容:ls /home/tianliang
8.切换到 tianliang 家目录的 study 目录下,查看当前路径
切换目录:cd /home/tianliang/study
查看当前路径:pwd
9.在该路径下创建一个文件 hello.txt
方法一:touch hello.txt
方法二[vi 编辑器的模式转换]:vi /vim hello.txt
:wq
10.编辑 hello.txt,写入”hello world”
方法一:vim hello.txt
按[aio]进入编辑模式
写入” hello world”
方法二:echo ”hello world” >>hello.txt
如果要追加的文件不存在,会自动创建
11.查看 hello.txt 文件内容
cat hello.txt
12.向 hello.txt 文件中追加”yes,we are family! ”
echo ”yes,we are family! ” >> hello.txt
13.拷贝 tianliang 家目录的 study 目录到 root 用户家目录
cp -r /home/tianliang/study /root/
14.移动绝对路径下的/root/test/my.txt 到 tianliang 的家目录中
mv /root/test/my.txt /home/tianliang/
15.删除/root/test/my.txt 文件
rm /root/test/my.txt
16.在/root/test 中新建一个文件 you.txt,然后删除/root/test 目录。
touch /root/test/you.txt
rm -r /root/test 递归删除
17.找一篇文章写入/root/article.txt 中,查看前 10 行或后 10 行。
head -10 /root/article.txt
tail -10 /root/article.txt
18.查找一下 my.txt 文件所在的位置
find / -name my.txt
19.过滤出/root/article.txt 中带‘中国’的行。
方法一:grep ‘中国’ /root/article.txt
方法二:sed -n ‘/中国/p’ /root/article.txt
方法三:awk ‘/中国/ {print }’ /root/article.txt 20.查看 article.txt 中的内容,使用管道命令过滤出带‘中国’的行。
方法一:cat /root/article.txt |grep ‘中国’
方法二: cat /root/article.txt |sed -n ‘/中国/p’
方法三: cat /root/article.txt |awk ‘/中国/ {print }’
21.查看 root 家目录下的内容,过滤出 my.txt 文件并查看该文件中的内容。
错误:ls /root|grep my.txt|cat
正确: ls /root|grep my.txt|xargs cat
Linux中常用的基础命令
最新推荐文章于 2022-10-27 01:33:57 发布