Linux入门Linux基础命令汇总

简介: Linux入门Linux基础命令汇总

1.如何关闭linux服务器?

方法一:halt

方法二:shutdown -h now

2.如何重启linux服务器?

方法一:reboot

方法二:shutdown -r now

3.请查看当前登录用户,如果是root用户,则切换到其他用户以下所有普通用户为test.。

查看当前登录用户:whoami

切换到test用户:su test

4.现在root用户登录,请修改root用户密码,并修改某普通用户的密码。

passwd [username]

如果不指定用户名则默认修改root用户的密码。注意:普通用户只能修改自己的密码。

5.切换到test用户的 家目录下。

切换目录:cd /home/test

6.在test家目录中创建一个文件夹study

创建目录:mkdir /home/test/study

7.查看test家目录下的文件或子目录

查看目录下的内容:ls /home/test

8.切换到test家目录的study目录下,查看当前路径

切换目录:cd /home/test/study

查看当前路径:pwd

9.在该路径下创建一个文件hello.txt

方法一:touch hello.txt

方法二:vi hello.txt

:wq

10.编辑hello.txt,写入”hello world”

方法一:vim hello.txt

按(a/i/o)进入编辑模式

写入” 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.拷贝test家目录的study目录到root用户家目录

cp -r /home/test/study /root/

14.移动绝对路径下的/root/test/my.txt到test的家目录中

mv /root/test/my.txt /home/test/

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递归删除

rm -rf /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

目录
相关文章
|
8天前
|
NoSQL Linux Shell
常用的 Linux 命令
常用的 Linux 命令
30 9
|
1天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
9 0
|
2天前
|
域名解析 网络协议 Linux
Linux 中的 Nslookup 命令怎么使用?
【4月更文挑战第12天】
22 6
Linux 中的 Nslookup 命令怎么使用?
|
3天前
|
运维 网络协议 Unix
18.系统知识-Linux常用命令
18.系统知识-Linux常用命令
|
4天前
|
网络协议 Ubuntu Linux
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
|
4天前
|
Linux Go
Linux命令Top 100驱动人生! 面试必备
探索Linux命令不再迷茫!本文分10部分详解20个基础命令,带你由浅入深掌握文件、目录管理和文本处理。 [1]: <https://cloud.tencent.com/developer/article/2396114> [2]: <https://pan.quark.cn/s/865a0bbd5720> [3]: <https://yv4kfv1n3j.feishu.cn/docx/MRyxdaqz8ow5RjxyL1ucrvOYnnH>
48 0
|
7天前
|
缓存 运维 监控
Linux系统监控利器:探索常用命令及数据保存技巧
Linux系统监控利器:探索常用命令及数据保存技巧
24 4
Linux系统监控利器:探索常用命令及数据保存技巧
|
9天前
|
Unix 大数据 Linux
linux入门
linux入门
16 1
|
10天前
|
Linux 索引
linux 文件查找 和文件管理常用命令
linux 文件查找 和文件管理常用命令
19 0
|
10天前
|
安全 Unix Linux
一、linux 常用命令之 linux版本信息 系统管理与设置 持续更新******
一、linux 常用命令之 linux版本信息 系统管理与设置 持续更新******
14 0