您的位置:首页 > 运维架构 > Linux

Linux基础入门

2016-07-22 20:44 435 查看
知识点:

centos系统图形界面与字符界面切换

centos系统关机命令

查看centos系统版本

查看挂载命令

学习过的常用命令

hash初步与shell介绍

安装VMware Tools

命令与命令别名

screen命令与echo

centos命令使用帮助

1.centos系统图形界面与字符界面切换

终端:terminal
多任务、多用户
物理终端,控制台:console 直接连接物理硬件
虚拟终端 tty:
图形终端 :
串行终端 ttys:
伪终端 pty:
用户界面 GUI:GNome,KDE
CLI: bash,zsh, sh, csh, tcsh, ksh
CLI接口 命令行接口
[root@localhost ~]#
root:当前登录 的用户
localhost:当前主机名,非完整格式,
~:用户当前所在目录(current directory), 也称为工作目录(working directory);相对路径
#:命令提示符 ;#表示管理员帐号 root (有最高权限,能执行最高权限) ; $普通用户 非root用户(不具有管理权限,不能执行系统管理操作)
注意:建议使用非管理员帐号登录;
执行管理操作是临时切换至管理员,操作完成退回;

[root@centos6 ~]# init 3 关闭图形界面
[root@centos6 ~]# init 5 启动图形界面
ctrl+alt+F1-6 字符 F7 图形 centos5版本
ctrl+alt+F1 图形, F2-6字符 centos6,7
chvt #(#为数字 ) 切换
startx 图形界面
2.centos系统关机命令

halt : 关机不断电,手动关闭物理机(centos7)
关机断电,物理机断电(centos6)
poweroff:断电关机
3.查看centos系统版本

hostname命令

lsb_release命令
[root@centos6 ~]# hostname 显示主机名
centos6.zanghl centos6.zanghl为主机名

[root@centos6 ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.8 (Final)
Release: 6.8
Codename: Final

lsb_release--> cat /etc/centos-release

[root@centos6 ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m
登录提示信息

[root@centos6 ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m
登录提示信息

[root@centos6 ~]# cat /etc/centos-release centos6版本
CentOS release 6.8 (Final)
[root@centos7 ~]# cat /etc/system-release centos7版本
CentOS Linux release 7.2.1511 (Core)
系统版本存放

4.查看挂载命令

查看挂载df命令

[root@centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 104806400 3507264 101299136 4% /
devtmpfs 1918944 0 1918944 0% /dev
tmpfs 1933472 88 1933384 1% /dev/shm
tmpfs 1933472 9168 1924304 1% /run
tmpfs 1933472 0 1933472 0% /sys/fs/cgroup
/dev/sda5 20961280 32928 20928352 1% /testdir
/dev/sda1 201388 141692 59696 71% /boot
tmpfs 386696 16 386680 1% /run/user/0
/dev/sr0 72414 72414 0 100% /run/media/root/VMware Tools
5.[b]学习过的常用命令[/b]

lscpu 查看CPU
cat 显示
who 查看当前系统用户以及终端
who am i
chvt
poweroff 关机
halt 关机
hostname 显示主机名
nano 文本编辑
init 3,5 关闭,开启图形界面
startx 开启图形界面
tty 查看当前终端设备
ifconfig 查看主机IP
uname -r 显示系统内核版本号
free 查看内存剩余情况
df 查看硬盘挂载
lsb_release -a 查看系统版本
echo 回显
gedit 图形界面下的文本编辑
cp 复制

6.hash初步

*
root 管理员账户
普通账户
UID=0 为管理员
[root@centos7 ~]# id -u
0 查看当前用户uid
[root@centos7 ~]# id -u zang
1000 查看zang用户的uid

terminal:终端 console:控制台
[root@centos7 ~]# cat /etc/shells 查看可用的shell
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh

查看所用的shell类型
[root@localhost ~]# echo $SHELL
/bin/bash
[root@centos7 ~]# getent passwd zang
zang:x:1000:1000:zang:/home/zang:/bin/bash
查看zang用户的shell类型

hash :搜寻到的外部命令路径结果缓存至kv(key-value) 存储
内部→缓存→外部 (命令执行时查找顺序)

hash -d 清除命令缓存
[root@centos6 ~]# hash hash查看
hits command
1 /bin/nano
1 /bin/hostname
2 /bin/cat
1 /bin/uname
1 /usr/bin/who
1 /usr/bin/free
1 /usr/bin/lsb_release
[root@centos6 ~]# hash -d cat 从hash表中删除cat
[root@centos6 ~]# hash hash显示结果cat已被删除
hits command
1 /bin/nano
1 /bin/hostname
1 /bin/uname
1 /usr/bin/who
1 /usr/bin/free
1 /usr/bin/lsb_release

[root@centos6 ~]# hash -r 清空hash表
[root@centos6 ~]# hash hash查看
hash: hash table empty

7.安装VMware Tools

在VMware虚拟机上面选择虚拟机选项,安装VMware tools
cd /media/VMware\ Tools/ cd到VMware Tools 光盘挂载所在的文件夹
ls 查看/media/VMware Tools 文件夹下面的内容
cp VMwareTools-10.0.0-2977863.tar.gz /testdir/ 将VMware Tools的压缩包拷贝到/testdir目录下
cd /testdir cd命令进入到/testdir目录
ls 查看复制的文件
tar xvf VMwareTools-10.0.0-2977863.tar.gz 解压VMware Tools的文件压缩包文件
cd vmware-tools-distrib/ 进入我们刚才解压的文件夹中
ls 查看找到vmware-install.pl
./vmware-install.pl d 进行对于VMware Tools的安装 (d为一切按照安装 软件的默认进行安装)

8.命令与命令别名
[root@centos7 ~]#
用户 主机名 目录 提示符
root centos7 ~ #
[root@centos7 ~]# echo $PS1
[\u@\h \W]\$
命令格式COMMAND [OPTIONS...] [ARGUMENTS...]选项 参数选项:用于启用或关闭命令的某个或某些功能;短选项:-c, 例如:-l, -h长选项:--word ,例如:--all, --human-readable参数:命令的作用对象,比如文件名,用户名等
命令分类
内部命令:系统自带的
[root@centos7 ~]# type cd
cd is a shell builtin
外部命令:硬盘上的文件
[root@centos7 ~]# type ifconfig
ifconfig is /usr/sbin/ifconfig
区别当前使用的命令是内部 或外部命令:
# type COMMAND[root@centos7 ~]# type cdcd is a shell builtin[root@centos7 ~]# type ifconfigifconfig is /usr/sbin/ifconfig注意:执行过命令之后,缓存中会保存,再次执行命令的时候,首先从缓存中读取;
若缓存中没有被清空,直接从缓存中进行读取,直接执行该命令;
若缓存被清空,需从$PATH中重新去查询命令所在的文件,然后再次执行
内部命令可以禁用
[root@centos6 ~]# enable -n cd
[root@centos6 ~]# cd /
-bash: cd: command not found
[root@centos7 ~]# enable -n cd[root@centos7 ~]# cd /
[root@centos7 ~]# cd /
[root@centos7 ~]# enable cd
[root@centos7 ~]# cd /
[root@centos7 /]#
[root@centos6 ~]# enable cd
[root@centos6 ~]# cd /
[root@centos6 /]#

which命令用于查外部命令
[root@centos7 /]# which ifconfig
/usr/sbin/ifconfig

centos6不支持命令的选项tab补全
取消和结束命令执行:Ctrl+c ,Ctrl+d
多个命令可以用;符号分开
[root@centos6 ~]# who;tty;ls -l
root tty1 2016-07-22 13:36 (:0)
root pts/0 2016-07-22 14:36 (172.18.18.122)
/dev/pts/0
total 108
-rw-------. 1 root root 1499 Jul 20 17:07 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 22 12:01 Desktop
drwxr-xr-x. 2 root root 4096 Jul 20 17:17 Documents
一个命令可以用\ 分成多行

alias 别名
[root@centos7 /]# alias ls 查询别名
alias ls='ls --color=auto'
\ls 'ls' /usr/bin/ls 不用别名直接使用命令
别名优先级大于内部命令

9.screen命令与echo
screen 命令:
screen:screen -S NAME 打开新的screen
screen -x NAME 加入会话
[root@centos6 ~]# exit 退出并关闭screen
Ctrl+a,d 剥离当前screen
[root@centos6 ~]# screen -ls 显示所有已经打开的screen
screen -r [SESSION] 恢复某screen
注意:
(1)当使用系统时只有一个screen请求时,直接使用screen -x 直接连接
(2)当使用系统上面有多个screen请求时,必须使用screen -x [SESSION]进行帮助
若请求的名称不同,直接指明需要连接的screen名称
若请求名称相同或者相似,需指出需要连接的screen名称和该进程前面的PID的进程号
(3)对于系统备份时间长,运行长的命令,建议先开启screen,后执行,防止当前shell出现断网等情况,导致的数据的丢失和错误。
(4)使用时加入会话建议直接使用程序的PID进行连接。

echo命令
说明:echo 会将输入的字符串送往标准输出。
输出的字符串间以空白字符隔开, 并在最后加
上换行号
echo "$VAR_NAME": 变量会替换,双引号表弱引用
echo '$VAR_NAME': 变量不会替换,强引用
$echo –e “Enter the file name: \c”
echo 需要使用-e 参数来打印转义字符.
\a 发出警告声;
\b 退格键
\c 最后不加上换行符号;
\n 换行且光标移至行首;
\r 光标移至行首,但不换行;
\t 插入tab; ;
\\ 插入\ 字符
\0nnn 插入nnn (八进制)所代表的ASCII 字符
echo -e "\033[43;31mred color\033[0m"
\xHH 插入HH (十六进制)所代表的ASCII 字符
echo -n 不在字符的最后自动换行
[root@centos6 ~]# /etc/DIR_COLORS 颜色管理文件
reset:乱码恢复
命令行扩展:$( ) 或 或 ``
把一个命令的输出打印给另一个命令的参数
$ echo "This system's name is $(hostname ) "
This system's name is server1.example.com
$echo "i am `whoami ` "
i am root
括号扩展:{ }
打印重复字符串的简化形式
$ echo file{1,3,5}
file1 file3 file5
$ rm -f file{1,3,5}

10.centos命令使用帮助
使用帮助
whatis
[root@centos6 ~]# whatis rm
rm (1p) - remove directory entries
rm (1) - remove files or directories

生成whatis的数据库
CentOS7 mandb
CentOS6 makewhatis
[root@centos6 ~]# makewhatis 创建whatis数据库 或者man -f[root@centos7 ~]#mandbhistory:/.bash_history(用户执行完命令正常退出后把内存中的命令历史写入到此命令中)查看命令的帮助:
CentOS7:
查看内部命令的帮助文件,help COMMAND
查看外部命令的配置文件,man COMMAND
COMMAND --help
查看该命令是否是内部或外部命令,使用type COMMAND
COMMAND --help 内部命令

Display(显示)

man and info

补充知识
clock:显示硬件时钟
-s:--hctosys:以硬件时钟为准,校正系统时钟
-w:--systohc:以系统时间为准,校正硬件时钟
reset:恢复命令行界面的乱码
定义文件名称颜色的配置文件 /etc/DIR_COLORS
history
用户输入命令的历史配置文件 在用户的家目录下面 .bash_history
系统使用的时候,命令保存在内存当中,只有当用户注销或者关机的时候,历史才能写到该用户的家目录下面

2016-07-22 zanghl

本文出自 “zanghl_blog” 博客,请务必保留此出处http://zanghl.blog.51cto.com/11267212/1828956
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: