操作命令

补充说明: linux 是多用户系统 windows是多用户的系统(收费)
系统运行相关命令
系统关机:

  1. shutdown # 关机命令 1分钟后关机
  2. shutdown -c # 取消关机命令
  3. [root@localhost ~]# shutdown
  4. Shutdown scheduled for 2021-04-22 16:30:08 CST, use 'shutdown -c' to cancel.
  5. # 定义一个关机方案 = 定义什么时间进行关机, 可以使用 shutdown -c 取消关机计划
  6. [root@localhost ~]#
  7. Broadcast message from root@localhost.localdomain (Thu 2021-04-22 16:29:08 CST):
  8. # 会将关机信息广播给所有关机主机的用户
  9. The system is going down for power-off at Thu 2021-04-22 16:30:08 CST!
  10. # 准备什么时间真正进行关机
  11. shutdown -h 5 # 指定5分钟后关机
  12. -h --> -halt 简写
  13. 5 --> 这个参数位置是以分钟为单位
  1. **系统重启:**
  1. shutdown -r 5 # 指定5分钟后以重启的形式关机
  2. [root@localhost ~]# shutdown -r 5
  3. Shutdown scheduled for 2021-04-22 17:19:22 CST, use 'shutdown -c' to cancel.
  4. # 定义一个关机方案 = 定义什么时间进行关机, 可以使用 shutdown -c 取消关机计划
  5. [root@localhost ~]#
  6. Broadcast message from root@localhost.localdomain (Thu 2021-04-22 17:14:22 CST):
  7. The system is going down for reboot at Thu 2021-04-22 17:19:22 CST!
  8. reboot # 直接重启

目录或文件相关命令

目录相关命令

  1. # 检查文件或目录是否存在命令
  2. ls == list(列表 列表显示相应信息)
  3. # 检查文件是否存在
  4. [root@localhost ~]# ls /etc/hosts
  5. /etc/hosts
  6. [root@localhost ~]# ls /etc/hosts1
  7. ls: 无法访问/etc/hosts1: 没有那个文件或目录
  8. # 检查目录是否存在
  9. [root@localhost ~]# ls /etc/
  10. abrt csh.cshrc groff libaudit.conf opt rc.local subversion
  11. adjtime csh.login group libnl os-release rdma sudo.conf
  12. aliases dbus-1 group- libreport pam.d redhat-release sudoers
  13. aliases.db default grub2.cfg libuser.conf passwd resolv.conf sudoers.d
  14. alternatives depmod.d grub.d locale.conf passwd- rpc sudo-ldap.conf
  15. # 如何针对的查看目录是否存在
  16. ls -d /injury # 针对性的查看目录是否存在 -d 全屏为 : -directory
  17. # 创建新的目录
  18. make directory(制造目录 mkdir的全拼) == mkdir (创建目录命令)
  19. # 在 根目录下创建一个目录
  20. mkdir /injury # 在根目录下创建一个叫做injury的目录 刚创键好的目录是空的
  21. mkdir -p /injury/injury01/injury02 # 创建多级目录
  22. # 如何切换目录
  23. change directory (改变目录) == cd
  24. cd 绝对路径/相对路径 # 切换至指定目录下
  25. cd .. # 返回上一级目录 [ 相对路径的方式 ]
  26. cd ../../ # 返回上两级目录 [ 相对路径的方式 ]
  27. # 查看当前所在路径
  28. print work directory (显示当前路径) == pwd
  29. pwd # 显示当前的绝对路径

文件相关命令

  1. # 查看文件信息命令
  2. ls -l # 查看文件详细信息
  3. [root@localhost ~]# ls /etc/services
  4. /etc/services
  5. [root@localhost ~]# ls -l /etc/services
  6. -rw-r--r--. 1 root root 670293 6 7 2013 /etc/services
  7. # 如何创建一个空文件
  8. touch 对象 # 在这个路径下创建一个文件
  9. [root@localhost ~]# touch /root/a.txt
  10. [root@localhost ~]# ll
  11. 总用量 4
  12. -rw-------. 1 root root 1274 4 22 17:48 anaconda-ks.cfg
  13. -rw-r--r--. 1 root root 0 4 26 08:58 a.txt
  14. # 如何对空文件进行编辑
  15. # 1.将文件打开进行直接编辑
  16. vi --> 用于编辑文件的命令
  17. vi /root/a.txt
  18. # 第一个步骤: 进入到编辑状态(插入模式) 按住小写字母 i
  19. # 第二个步骤: 编写文件内容
  20. # 第三个步骤: 进行保存关闭文档
  21. # 按esc键(退出编辑状态)--> :wq (write 写/保存 quit 退出)
  22. # :q (不保存直接退出)
  23. # :w (只保存但不退出)
  24. # 2.将文件不用打开进行直接编辑
  25. # 第一步 屏幕有信息显示
  26. [root@localhost ~]# echo "hello word"
  27. hello word
  28. # 第二步 将屏幕上的显示的信息
  29. [root@localhost ~]# echo "hello word" > /root/a.txt
  30. [root@localhost ~]# vi a.txt
  31. hello word
  32. [root@localhost ~]# echo "test one" >> /root/a.txt
  33. [root@localhost ~]# vi a.txt
  34. hello word
  35. test one
  36. # > 执行原理: 将原来文件内容先进行清空 添加新的信息
  37. # >> 执行原理: 不会覆盖原文件内容,而是在源文件最后一行末尾追加一行新的信息
  38. # 查看文件内容的命令
  39. cat # 查看文件内容
  40. [root@localhost ~]# cat a.txt
  41. hello word
  42. test one

备份数据信息

  1. # 如何复制保存数据
  2. cp # copy复制
  3. # 用法: cp 要复制的数据信息(文件/目录) 复制到什么位置(目录中)
  4. # 文件备份方法:
  5. [root@localhost ~]# cp /root/a.txt /tmp
  6. [root@localhost ~]# ls -l /tmp/a.txt
  7. -rw-r--r--. 1 root root 20 4 26 09:41 /tmp/a.txt
  8. # 目录备份方法:
  9. [root@localhost ~]# cp -r /root/ /tmp
  10. [root@localhost ~]# ls -d /tmp/root/
  11. /tmp/root/
  12. [root@localhost ~]# ls -l /tmp/root/a.txt
  13. -rw-r--r--. 1 root root 20 4 26 09:47 /tmp/root/a.txt
  14. # 目录备份的时候有时需要进行多次确认
  15. \cp -r 目录 要复制的位置 # 强行复制,直接确认

删除数据信息

  1. # 删除数据命令
  2. delete == remove (移除) == rm # 删除命令
  3. # 删除文件
  4. [root@localhost ~]# rm /tmp/a.txt
  5. rm:是否删除普通文件 "/tmp/a.txt"n
  6. [root@localhost ~]# \rm /tmp/a.txt
  7. [root@localhost ~]# ls -l /tmp/a.txt
  8. ls: 无法访问/tmp/a.txt: 没有那个文件或目录
  9. [root@localhost ~]# touch /tmp/a.txt
  10. [root@localhost ~]# rm /tmp/a.txt
  11. rm:是否删除普通空文件 "/tmp/a.txt"n
  12. [root@localhost ~]# rm -f /tmp/a.txt
  13. [root@localhost ~]# ls -l /tmp/a.txt
  14. ls: 无法访问/tmp/a.txt: 没有那个文件或目录
  15. # 删除目录
  16. [root@localhost ~]# ls
  17. a anaconda-ks.cfg a.txt c d
  18. [root@localhost ~]# rm c
  19. rm: 无法删除"c": 是一个目录
  20. [root@localhost ~]# rm -r c
  21. rm:是否删除目录 "c"
  22. [root@localhost ~]# rm -rf c
  23. [root@localhost ~]# ls
  24. a anaconda-ks.cfg a.txt d
  25. [root@localhost ~]# \rm -r d
  26. [root@localhost ~]# ls
  27. a anaconda-ks.cfg a.txt
  28. [root@localhost ~]# rm -rf a

移动数据信息

  1. move(移动) == mv # mv命令用法和cp命令用法相似
  2. # 移动剪切文件数据
  3. [root@localhost ~]# cp a.txt /tmp/
  4. [root@localhost ~]# ls -l /tmp
  5. 总用量 8
  6. -rw-r--r--. 1 root root 20 4 26 10:35 a.txt
  7. -rwx------. 1 root root 813 4 22 17:48 ks-script-LFfccP
  8. -rw-------. 1 root root 0 4 22 17:44 yum.log
  9. [root@localhost ~]# mv a.txt /tmp
  10. mv:是否覆盖"/tmp/a.txt" ^C
  11. [root@localhost ~]# mv -f a.txt /tmp/
  12. [root@localhost ~]# ls -l /tmp
  13. 总用量 8
  14. -rw-r--r--. 1 root root 20 4 26 09:27 a.txt
  15. -rwx------. 1 root root 813 4 22 17:48 ks-script-LFfccP
  16. -rw-------. 1 root root 0 4 22 17:44 yum.log
  17. [root@localhost ~]# ls
  18. anaconda-ks.cfg
  19. # 移动剪切目录数据
  20. [root@localhost ~]# mkdir a
  21. [root@localhost ~]# mv /root/a /tmp/
  22. [root@localhost ~]# ls -ld /tmp/a
  23. drwxr-xr-x. 2 root root 6 4 26 10:36 /tmp/a
  24. [root@localhost ~]# ls -ld /root/a
  25. ls: 无法访问/root/a: 没有那个文件或目录
  26. # 对文件进行重命名操作
  27. [root@localhost ~]# mkdir hurt
  28. [root@localhost ~]# cd hurt
  29. [root@localhost hurt]# ls
  30. [root@localhost hurt]# touch a.txt
  31. [root@localhost hurt]#
  32. [root@localhost hurt]# ls
  33. a.txt
  34. [root@localhost hurt]# mv a.txt b.txt
  35. [root@localhost hurt]# ls
  36. b.txt

系统目录结构

linux 目录结构: 一切从根开始 [ 一个倒挂的树 ]
windows目录结构: 按照盘符进行划分
linux系统中挂载技术
让用户可以将一个目录作为一个存储设备的挂载点,通过挂载点可以看到挂载设备中的数据

实际操作演示Linux系统挂载操作

第一步 拥有一个存储设备 光驱 使光驱加载光盘

第二步 在Linux系统中找到光驱设备
[root@localhost ~]# ls -l /dev/cdrom
lrwxrwxrwx. 1 root root 3 4月 26 08:25 /dev/cdrom -> sr0

第三步 将存储设备进行挂载
挂载命令语法: mount 挂载设备文件信息 挂载点(目录信息)
mount /dev/cdrom /mnt [ 挂载点目录必须存在 ]
卸载挂载点的命令语法: umount 挂载点(目录信息)

  1. [root@localhost ~]# ls -l /dev/cdrom
  2. lrwxrwxrwx. 1 root root 3 4 26 08:25 /dev/cdrom -> sr0
  3. [root@localhost ~]# ls -d /mnt
  4. /mnt
  5. [root@localhost ~]# mount /dev/cdrom /mnt
  6. mount: /dev/sr0 写保护,将以只读方式挂载
  7. [root@localhost ~]# cd /mnt
  8. [root@localhost mnt]# ls
  9. CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
  10. [root@localhost mnt]# cd ../
  11. [root@localhost /]# umount /mnt
  12. [root@localhost /]# cd mnt
  13. [root@localhost mnt]# ls

Linux挂载.png

系统基础目录结构

linux根目录

  1. [root@localhost /]# ls -l
  2. 总用量 32
  3. lrwxrwxrwx. 1 root root 7 4 22 17:45 bin -> usr/bin
  4. dr-xr-xr-x. 4 root root 4096 4 22 17:48 boot
  5. drwxr-xr-x. 19 root root 3080 4 26 08:25 dev
  6. drwxr-xr-x. 79 root root 8192 4 26 08:25 etc
  7. drwxr-xr-x. 3 root root 19 4 22 17:48 home
  8. lrwxrwxrwx. 1 root root 7 4 22 17:45 lib -> usr/lib
  9. lrwxrwxrwx. 1 root root 9 4 22 17:45 lib64 -> usr/lib64
  10. drwxr-xr-x. 2 root root 6 6 10 2014 media
  11. drwxr-xr-x. 2 root root 6 6 10 2014 mnt
  12. drwxr-xr-x. 2 root root 6 6 10 2014 opt
  13. dr-xr-xr-x. 349 root root 0 4 26 08:25 proc
  14. dr-xr-x---. 3 root root 4096 4 26 10:40 root
  15. drwxr-xr-x. 22 root root 580 4 26 08:25 run
  16. lrwxrwxrwx. 1 root root 8 4 22 17:45 sbin -> usr/sbin
  17. drwxr-xr-x. 2 root root 6 6 10 2014 srv
  18. dr-xr-xr-x. 13 root root 0 4 26 08:25 sys
  19. drwxrwxrwt. 8 root root 4096 4 26 10:51 tmp
  20. drwxr-xr-x. 13 root root 4096 4 22 17:45 usr
  21. drwxr-xr-x. 20 root root 4096 4 26 08:25 var

linux根目录结构.png

详细了解目录结构中重要文件数据信息

网卡配置文件

  1. [root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth0
  2. /etc/sysconfig/network-scripts/ifcfg-eth0
  3. [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  4. TYPE=Ethernet -- 指定网络类型 以太网
  5. BOOTPROTO=none -- 网络启动协议 如何让主机得到IP地址
  6. 1. 自己手动配置 none static(静态)
  7. 2. 自动获取地址 dhcpd(了解)
  8. NAME=eth0 -- 主机网卡名称 逻辑名称
  9. UUID=7f862c81-79e5-448b-8318-e7e0fda89634 -- 虚拟主机 会给每个硬件做一个标识
  10. DEVICE=eth0 -- 主机网卡名称 设备名称物理名称
  11. ONBOOT=yes -- 设置网卡是否处于开启状态
  12. IPADDR=10.0.0.200 -- 静态配置IP地址 标识主机身份
  13. PREFIX=24 -- 定义网络中可以有多少个主机
  14. GATEWAY=10.0.0.2 -- 一个网络到另一个网络的必经之路
  15. DNS1=223.5.5.5 -- DNS (建立名称和IP地址的对应关系) 180.101.49.11 -- 名称

配置文件修改重启服务

  1. systemctl restart network [ 重启所有网卡 ]
    systemctl status network
  2. ifdown 网卡名称 [ 指定网卡停止—不是重启 ]
    ifup 网卡名称 [ 指定网卡开启 ]
    ifdown 网卡名称 && ifup 网卡名称 [ 停止并启动网卡 ]
  3. 异常问题: 网卡配置文件正确,无法重启网络服务
    systemctl stop NetworkManager 网络管理服务关闭

DNS解析配置文件

临时修改, 一旦重启网卡就会将其恢复至 ifcfg-eth0中的DNS

  1. [root@localhost ~]# cat /etc/resolv.conf
  2. # Generated by NetworkManager
  3. nameserver 223.5.5.5

系统命令帮助方法

manual [ 手册 ] —> man mkdir [ 查看mkdir手册 ]
NAME # 命令作用说明
mkdir - make directories
SYNOPSIS # 命令使用方法
mkdir [OPTION]… DIRECTORY…
DESCRIPTION # 参数说明
-p, —parents
no error if existing, make parent directories as needed