Linux基本操作及基本命令使用

获得命令行

方式一:虚拟控制台切换( Ctrl + Alt + Fn 组合键)
– tty1:图形桌面
– tty2~tty6:字符控制台
方式一:在图形桌面
Linux基本操作及基本命令使用
Linux基本操作及基本命令使用
Linux基本操作及基本命令使用

Linux命令行操作

-命令行提示符
[[email protected] ~]#

  • [当前登录的用户@主机名 当前所在的位置] #
  • 如果以#结尾:表示当前登录的身份为超级管理员root
  • 如果以$结尾:表示当前登录的身份为普通用户

pwd — Print Working Directory

  • 用途:查看当前工作目录(显示当前所在的位置)

cd — Change Directory

  • 用途:切换工作目录
  • 格式:cd [目标文件夹位置]

ls — List

  • 格式:ls [目录或文件名]

[[email protected] ~]# pwd #显示当前所在的位置
[[email protected] ~]# cd / #切换到根目录
[[email protected] /]# pwd
[[email protected] /]# ls #显示当前目录的内容
[[email protected] /]# cd /home
[[email protected] home]# pwd
[[email protected] home]# ls

[[email protected] home]# cd /opt
[[email protected] opt]# pwd
[[email protected] opt]# ls

[[email protected] opt]# cd /root
[[email protected] ~]# pwd
[[email protected] ~]# ls

ls — List:显示指定目录内容

[[email protected] ~]# ls /opt
[[email protected] ~]# ls /home
[[email protected] ~]# ls /
[[email protected] ~]# ls /tmp
[[email protected] ~]# ls /dev
[[email protected] ~]# ls /etc
[[email protected] ~]# ls /boot

cd — Change Directory:切换目录

  • 绝对路径:以根目录开头的路径
  • 相对路径:以当前所在目录,为参照的路径

]# cd /etc/pki/ #绝对路径
]# pwd
]# ls
]# cd /etc/pki/CA #绝对路径,与当前所在位置无关
]# pwd
]# ls
]# cd /etc/pki/ #绝对路径
]# pwd
]# ls
]# cd CA #相对路径,与当前所在位置有关
]# pwd

cd. . :返回上一级目录

[[email protected] CA]# cd /etc/pki/CA
[[email protected] CA]# pwd
/etc/pki/CA
[[email protected] CA]# cd . . #返回上一级目录
[[email protected] pki]# pwd
/etc/pki
[[email protected] pki]# cd . . #返回上一级目录
[[email protected] etc]# pwd
/etc
[[email protected] etc]# cd . . #返回上一级目录
[[email protected] /]#

查看文本文件内容命令:cat 适合查看内容较少的文件

[[email protected] /]# cat /root/anaconda-ks.cfg
[[email protected] /]# cat /etc/redhat-release #显示系统版本
CentOS Linux release 7.5.1804 (Core)
[[email protected] /]# cat /etc/passwd
[[email protected] /]# cat /etc/fstab
[[email protected] /]# cat /etc/hosts
[[email protected] /]# cat /etc/shells

查看文本文件内容命令:less 适合查看内容较多的文件

[[email protected] /]# less /etc/passwd
按上下键进行滚动,按q进行退出

查看文本文件部分内容命令head、tail 命令

– 格式:head -n 数字 文件名 #头几行
– 格式: tail -n 数字 文件名 #尾几行
[[email protected] /]# head -1 /etc/passwd
[[email protected] /]# head -2 /etc/passwd
[[email protected] /]# head -3 /etc/passwd
[[email protected] /]# head -13 /etc/passwd

[[email protected] /]# tail -1 /etc/passwd
[[email protected] /]# tail -2 /etc/passwd

过滤包含指定字符串的行

[[email protected] /]# grep root /etc/passwd
#在/etc/passwd中包含root的行

修改文本文件内容:vim(文本编辑器)

  • 三个模式:命令模式、插入模式(输入模式)、末行模式
    ]# vim /opt/nsd.txt #当文件不存在,会新建文件
  • 命令—>i键 或者 o键—>插入模式(按Esc回到命令模式)
    末行模式 :wq #保存并退出
    末行模式 :q! #强制不保存并退出

新建目录:mkdir

新建文件:touch

查看以及设置主机名的命令:hostname

查看网卡IP地址命令:ifconfig

查看cpu信息

…….
型号名称: Intel® Core™ i7-7700 CPU @ 3.60GHz
…….

查看内存信息

关机:poweroff

重启:reboot