9常见shell命令
自行百度
linux
redhat 5.4 7.2
localhost login
localhost:主机名
linux的管理员是root
linux下文件夹叫目录
linux下一切皆为文件
init 5 进入图形界面
1.linux下常用的脚本语言
bash shell cshell kshell
2.终端
[root@localhost ~]#
root 当前登陆用户是root
@localhost 当前主机名是localhost
~ linux下文件夹叫目录当前所在目录是家目录
家目录:用户登陆系统的默认所在目录
3.目录结构
/ 根 存放系统中所有文件的位置
/bin 存放普通用户命令的位置
/sbin 存放管理员命令位置
/boot 系统启动时候所需文件位置
/dev 存放系统硬件文件所在位置
/etc 存放系统配置文件
/home 普通用户的家目录所在目录
/mnt 系统默认挂载点
/opt /usr 普通用户安装软件的目标位置
/proc 存放系统当前运行信息
/root 管理员的家目录
/tmp 存放临时文件的位置
/var 存放系统运行信息(日志)
4.基本命令
who 当前登陆系统的所有的用户的登陆属性信息
who am i 当前登陆系统用户的登陆属性信息
whoami 当前登陆用户的用户名
pwd 当前目录所在的绝对路径
绝对路径: 以/开头的路径
相对路径: 不以/开头的路径
. 当前目录
.. 上一级目录
ls 列表当前目录下所有文件名
ls /root 列表/root目录下所有文件名
ls -a 列表当前目录下所有文件名(包括隐藏文件(.开头的文件))
ls -l 列表当前目录下所有文件的文件属性信息
ls -ld /root 列表/root目录的文件属性信息
cd 切换目录
cd 进入到家目录
cd .. 目录切换到上一级目录
cd - 目录切换到上一次操作所在目录
cd / 目录切换到根目录
cd ~ 目录切换到家目录
5.帮助
1.man
man ls 查看ls的官方文档(q退出)
2.info
info ls 查看ls的说明文档(q退出)
3--help
ls --help 查看ls的参数帮助
补充:文件属性信息
-rwx------. 1 root root 1452 5月 21 00:15 initial-setup-ks.cfg
1:文件类型 -普通文件 d目录
2-10:权限
11:文件节点
12:拥有者
13:拥有组
14:文件大小
15:最后修改时间
16:文件名
6.配置linux的IP
1.搜索ip没有使用的
a.必须和宿主机网卡在一个网段
b.局域网必须没有别人使用
开始--运行--cmd ping 10.10.104.X(X 1-254)
10.10.104.44 作为linux的ip
2.命令设置
setup---network configuration--edit devices--eth0--(name、device不改动,取消dhcp功能(空格)、static ip上面ip、netmask 255.255.255.0)--ok--save--save&quit--quit--service network restart
补充:查看主机ip地址 ifconfig
7.虚拟机网络配置
桥接 客户机可以和宿主机局域网中主机进行通信
网络地址转换 客户机可以上网但是无法和局域网主机通信
仅主机 客户机和宿主机私有网络通道
建议:桥接
右键标签--设置--网络适配器--桥接、复制物理网络连接状态
------------------------------------------------------
vi编辑器(创建、修改文件)
vim
1.vi的模式
命令
编辑
末行
2.打开文件
vi 文件名
vi install.log
3.命令模式
跳转
G 光标跳转到内容末行行首
gg 光标跳转到内容首行行首
10gg光标跳转到第十行行首
^ 光标跳转到本行内容行首
$ 光标跳转到本行内容行尾
复制
yy 复制当前行
10yy 复制10行
粘贴
p
剪切/删除
dd 删除当前行内容
10dd 删除10行内容
搜索
?i386 搜索i386关键字
/noarch 搜索noarch关键字
i 命令模式进入到编辑模式
O o
A a
S s
4.编辑模式
自己动手丰衣足食
按esc进入命令模式
5.末行模式
显示行号 :set nu
取消显示行号 :set nonu
保存 :w
退出 :q
强制保存退出 :wq!
替换
:1,$s/l/MMMM/ 全文搜索l替换为MMMM,只替换每行第一个
:713s/1/20/g 713行搜索1替换为20,全部替换
------------------------------------------------------
包、压缩文件、压缩包
包 tar
创建的包文件都是.tar结尾
tar -cvf test.tar install.log desktop 创建包文件test.tar内容为install.log 和desktop
tar -tvf test.tar 查看包文件test.tar
tar -xvf test.tar -C /tmp/ 解包包文件到/tmp目录
tar -xvf test.tar 解包包文件到当前目录
注意:解包指定目录需要加-C
压缩文件 gzip
查看文件、目录大小
du -sh install.log
压缩机别默认为6,共9个级别
压缩比
1G---512m 压缩比小,速度快
1G---32m 压缩比大,速度慢
gzip不能压缩目录
gzip install.log 压缩文件install.log
gzip -l install.log.gz 列表压缩文件内容
gzip -d install.log.gz 解压压缩文件
压缩包
先打包,后压缩
tar -cvf test2.tar Desktop/ install.log
gzip test2.tar
--------------
tar -czvf test3.tar.gz Desktop/ install.log 创建压缩包文件
tar -tzvf test3.tar.gz 查看压缩包文件内容
tar -xzvf test3.tar.gz -C /opt/ 解压压缩包到指定目录
linux 发行版:
redhat CentOS Ubuntu Debian...
常用终端快捷键
alt f10 最大化终端窗口
Ctrl shift + 放大字体
Ctrl - 缩小字体
Ctrl l 清屏(相当于clear命令)
==========================================
Linux命令:
ls 查看文件或者目录(list):
-a 查看所有文件,包括隐藏文件(文件名以.开头的文件)
-l 以列表形式查看文件信息
-h 以适合用户读的方式显示文件大小
ls 默认查看当前目录(文件夹)
[root@localhost ~]# ls
anaconda-ks.cfg install.log VMwareTools-9.6.2-1688356.tar.gz
Desktop install.log.syslog vmware-tools-distrib
查看指定的目录或者文件
[root@localhost ~]# ls /usr
bin games kerberos libexec sbin src X11R6
etc include lib local share tmp
查看当前目录和/usr目录
[root@localhost ~]# ls . /usr
.:
anaconda-ks.cfg install.log VMwareTools-9.6.2-1688356.tar.gz
Desktop install.log.syslog vmware-tools-distrib
/usr:
bin games kerberos libexec sbin src X11R6
etc include lib local share tmp
[root@localhost ~]# ls -l
total 59952
-rw------- 1 root root 1327 Oct 24 14:12 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Oct 24 21:14 Desktop
-rw-r--r-- 1 root root 30675 Oct 24 14:12 install.log
-rw-r--r-- 1 root root 3738 Oct 24 14:12 install.log.syslog
-rw-r--r-- 1 root root 61260572 Mar 21 2014 VMwareTools-9.6.2-1688356.tar.gz
drwxr-xr-x 7 root root 4096 Mar 21 2014 vmware-tools-distrib
[root@localhost test]# ls -a
. .. aa .aa file .file
[root@localhost ~]# ls -lh
total 59M
drwxr-xr-x 3 root root 4.0K Oct 24 23:26 111
-rw-r--r-- 1 root root 856 Oct 25 05:25 abc.txt
-rw------- 1 root root 1.3K Oct 24 14:12 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Oct 25 02:27 bfile
drwxr-xr-x 2 root root 4.0K Oct 24 21:14 Desktop
-rw-r--r-- 1 root root 0 Oct 24 23:39 file
-rw-r--r-- 1 root root 30K Oct 24 14:12 install.log
-rw-r--r-- 1 root root 3.7K Oct 24 14:12 install.log.syslog
drwxr-xr-x 4 root root 4.0K Oct 25 05:51 test
-rw-r--r-- 1 root root 59M Mar 21 2014 VMwareTools-9.6.2-1688356.tar.gz
drwxr-xr-x 7 root root 4.0K Mar 21 2014 vmware-tools-distrib
-------------------------------------------------------
查看当前工作目录的路径(print working directory)
[root@localhost ~]# pwd
/root
cd 切换目录(change directory)
切换到/etc/ssh(根目录下面的etc下面的ssh目录)
[root@localhost ~]# cd /etc/ssh
cd 默认到家目录
[root@localhost ssh]# cd
[root@localhost ~]# pwd
/root
切换到上一次所在目录
[root@localhost ssh]# cd -
/root
. 代表当前所在目录
.. 代表当前所在目录的上一级目录
~ 当前登录用户的家目录
window路径表示方法:
C:\Windows\System32\drivers\etc\host
Linux路径表示方法:
/etc/ssh/sshd_config
linux路径:
1>. 绝对路径: 从/开始的路径表示方法
/etc/ssh/sshd_configv
2>. 相对路径: 不是从/目录开始的路径
..
.
/vmware-tools-distrib
vmware-tools-distrib
date 查看日期和时间
[root@localhost ssh]# date
Mon Oct 24 22:00:22 EDT 2016
[root@localhost ssh]# date "+%H"
22
[root@localhost ssh]# date "+%M"
03
[root@localhost ssh]# date "+%H:%M"
22:03
[root@localhost ssh]# date "+%H:%M:%S"
22:03:57
[root@localhost ssh]# date "+%T"
22:04:23
[root@localhost ssh]# date "+%F"
2016-10-24
---------------------------------------
touch 创建空文件
在/opt下面创建空文件file
[root@localhost ~]# touch /opt/file
[root@localhost ~]# ls /opt/
file
---------------------------------------
mkdir 创建目录(make directory)
在当前目录下创建aaa子目录,在/opt下面创建bbb子目录
[root@localhost ~]# mkdir aaa /opt/bbb
[root@localhost ~]# ls
aaa file test
anaconda-ks.cfg install.log VMwareTools-9.6.2-1688356.tar.gz
Desktop install.log.syslog vmware-tools-distrib
[root@localhost ~]# ls /opt/
bbb file
-p 可以嵌套创建目录
[root@localhost ~]# mkdir -p 111/222/333
[root@localhost ~]# ls 111/
222
[root@localhost ~]# ls 111/222/
333
--------------------------------------------
rm 删除文件(remove)
-f --force 强制删除,不会提示
-r 删除目录和里面的所有内容
删除当前目录下的file文件
[root@localhost ~]# rm -f file
删除/opt/bbb目录
[root@localhost ~]# rm -fr /opt/bbb/
[root@localhost ~]# ls /opt/
--------------------------------------------
cp 复制文件(copy)
格式:
cp 源文件 目标文件
复制当前目录下的file到/opt下面
[root@localhost ~]# cp file /opt
[root@localhost ~]# ls /opt/
file
复制当前目录下的file到/opt下面,名字改为newfile
[root@localhost ~]# cp file /opt/newfile
[root@localhost ~]# ls /opt/
file newfile
-r 复制目录和里面的所有文件
把当前目录下的test子目录复制到/opt下面
[root@localhost ~]# cp -r test /opt
[root@localhost ~]# ls /opt/
file newfile test
[root@localhost ~]# ls /opt/test/
abc
把当前目录下的test子目录复制到/opt下面, 名字改为newtest
[root@localhost ~]# cp -r test /opt/newtest
[root@localhost ~]# ls /opt/
file newfile newtest test
--练习题:
在当前目录下的dir目录下创建一个子目录,名字叫file
mkdir dir/file
删除/opt下面的abc目录
rm -rf /opt/abc
把/opt下面的test目录拷贝到/目录下
cp -r /opt/test/ /
把/opt下面的test目录拷贝到当前目录下
cp -r /opt/test/ .
把/opt下面的test目录拷贝到当前目录下,名字改为newtest
cp -r /opt/test/ newtest
-----------------------------------------------
mv 移动文件或者修改文件名(move)
格式:
mv 源文件 目标文件
把/opt下面的file 文件移动到当前目录下
[root@localhost ~]# mv /opt/file .
把/opt下面的file 文件移动到当前目录下,名字修改为afile
[root@localhost ~]# mv /opt/file afile
mv 移动目录与普通文件,用法一样
[root@localhost ~]# ls /opt/
newfile newtest test
修改/opt下的test目录的文件名
[root@localhost ~]# mv /opt/test/ /opt/xxx
[root@localhost ~]# ls /opt/
newfile newtest xxx
把当前目录下的afile名字改为bfile
[root@localhost ~]# mv afile bfile
-----------------------------------------
练习
1. 在/opt下面创建一个aaa目录,把目录的名字改为bbb,把bbb目录拷贝到当前目录下,
删除原来的bbb目录,在当前目录下的bbb里面创建一个普通文件file,把当前目录下的bbb移动到/tmp下面,名字改为xxx
mkdir /opt/aaa
mv /opt/aaa /opt/bbb
cp -r /opt/bbb .
rm -rf /opt/bbb
touch bbb/file
mv bbb /tmp/xxx
/根目录下的几个系统目录介绍:
etc 存放系统和程序的配置文件
bin 存放所有用户都有权限执行的命令
sbin 存放只有管理员才能执行的命令
root 管理员家目录
mnt 临时的挂载点
home 普通用户的家目录默认放在home
var 存放系统运行过程中经常变化的文件
lib 存放系统的库文件
tmp 临时目录
上古神器
vim 三种工作模式:
1> 命令模式
h j k l 代替四个方向键
nyy 从当前行开始向下复制n行
np 在当前行下面粘贴n次
ndd 从当前行开始向下剪切n行
0 把光标移动到行首
$ 把光标移动到行尾
gg 光标移动到第一行
nG 光标移动到第n行
G 光标移动到最后一行
/hello 查找文档中所有的hello关键字
n 移动光标到下一个匹配的关键字
N 移动光标到上一个匹配的关键字
u 撤销一个操作
Ctrl r 恢复撤销的操作
2> 插入模式(编辑模式)
进入插入模式
i 在当前字符前面插入
I 在当前行首插入
a 在当前字符后面插入G
A 在当前行尾插入
o 在当前行下面新建一行插入
O 在当前行上面新建一行插入
s 删除当前字符插入
S 删除当前行插入
ESC 返回到命令模式
3> 底行模式(末行模式)
:w 保存
:q 退出
:wq 保存退出
:q! 强制退出
:set nu[mber] 显示行号
:set nonu[mber] 不显示行号
:%s/hello/Hi/g 把文档中所有的hello关键字替换成Hi
把/etc/passwd复制到/tmp目录下,完成下面练习
1. 查找文件中所有的root关键字
/root
2. 删掉文件最后一行
G
dd
3. 把第10行剪切到第15行
10G
dd
14G
p
4. 把文件中所有的root替换成admin
:%s/root/admin/g
5. 把文件中的所有:替换成-
:%s/:/-/g
-----------------------------------------
cat tac
head tail
more less
[root@localhost ~]# cat abc.txt
111
222
333
444
555
666
777
888
999
10
11
12
13
从最后一行打印
[root@localhost ~]# tac abc.txt
13
12
11
10
999
888
777
666
555
444
333
222
111
查看文件的"头",默认前10行
[root@localhost ~]# head abc.txt
111
222
333
444
555
666
777
888
999
10
查看文件前三行
[root@localhost ~]# head -n 3 abc.txt
111
222
333
查看文件前三行
[root@localhost ~]# head -3 abc.txt
111
222
333
查看文件所有行,除了最后5行
[root@localhost ~]# head -n -5 abc.txt
111
222
333
444
555
666
777
888
查看文件的"尾",默认最后10行
[root@localhost ~]# tail abc.txt
444
555
666
777shoadd
888
999
10
11
12
13
查看最后5行
[root@localhost ~]# tail -n 5 abc.txt
999
10
11
12
13
查看最后5行
[root@localhost ~]# tail -5 abc.txt
999
10
11
12
13
操作系统通配符
* 匹配任意多个字符
? 匹配一个字符
find 查找文件
格式:
find 查找位置 -查找方式 参数
-name 按照文件名查找
[root@localhost ~]# find /etc -name "sshd_config"
/etc/ssh/sshd_config
在/etc下查找所有以ssh开头的文件
[root@localhost ~]# find /etc -name "ssh*"
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh
/etc/ssh/ssh_host_dsa_key
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_dsa_key.pub
/etc/ssh/ssh_host_key
/etc/ssh/sshd_config
/etc/ssh/ssh_config
/etc/ssh/ssh_host_key.pub
-size 按照文件大小查找
常用单位
c 字节byte
k 1024c
M 1024k
G 1024M
+ 超过
- 小于
在当前目录下查找,大小超过10k的文件
[root@localhost test]# find . -size +10k
./file1
./file2
[root@localhost test]# find . -size 7M
----------------------------------------------
locate 文件名
[root@localhost test]# locate file2
手动更新文件信息数据库
[root@localhost test]# updatedb
[root@localhost test]# locate file2
/root/test/file2
------------------------------------------------
用户管理
创建用户
[root@localhost ~]# useradd mary
给新用户设置密码
[root@localhost ~]# passwd mary
Changing password for user mary.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
删除用户
[root@localhost ~]# userdel -r mary
临时切换用户身份: su - 新用户
su 新用户: 切换后系统环境还是原来的用户的
[root@localhost ~]# su - tom
[tom@localhost ~]$ pwd
/home/tom
-------------------------------------------
Linux文件类型
- 普通文件
d 目录
l 符号链接(软链接)
c 字符设备
b 块设备
s 套接字
p 管道
-----------------------------------------------
chown (change owner)
[root@localhost ~]# ll ab
-rw-r--r-- 1 root root 0 Oct 25 21:08 ab
把文件拥有者(属主)改为tom
[root@localhost ~]# chown tom ab
[root@localhost ~]# ll ab
-rw-r--r-- 1 tom root 0 Oct 25 21:08 ab
把属组改为gdm组
[root@localhost ~]# chown :gdm ab
[root@localhost ~]# ll ab
-rw-r--r-- 1 tom gdm 0 Oct 25 21:08 ab
同时修改文件的属主和属组
[root@localhost ~]# chown root:root ab
[root@localhost ~]# ll ab
-rw-r--r-- 1 root root 0 Oct 25 21:08 ab
-R 针对目录和里面的所有内容执行相同的操作
[root@localhost ~]# chown -R tom:tom test
[root@localhost ~]# ll -d test/
drwxr-xr-x 3 tom tom 4096 Oct 25 21:24 test/
[root@localhost ~]# ll test/
total 8004
drwxr-xr-x 2 tom tom 4096 Oct 25 05:50 aa
-rw-r--r-- 1 tom tom 132 Oct 25 21:19 file
-rw-r--r-- 1 tom tom 13332 Oct 25 21:23 file1
-rw-r--r-- 1 tom tom 8159184 Oct 25 21:24 file2
文件访问权限:
r 读 read
w 写 write
x 执行 execute
修改文件访问权限chmod:
1>. 字符方式修改
r
w
x
u 文件拥有者(属主) user
g 属组用户 group
o 其他人 other
+
-
=
[root@localhost tmp]# ll ab
-rw-r----- 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod u=rwx,g=rx,o=- ab
[root@localhost tmp]# ll ab
-rwxr-x--- 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod g-x,o+r ab
[root@localhost tmp]# ll ab
-rwxr--r-- 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod a+x ab
[root@localhost tmp]# ll ab
-rwxr-xr-x 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod -x ab
[root@localhost tmp]# ll ab
-rw-r--r-- 1 root root 9 Oct 25 22:36 ab
2>. 数字方式修改
r 4
w 2
x 1
--- 0
--x 1
-w- 2
-wx 3
r-- 4
r-x 5
rw- 6
rwx 7
[root@localhost tmp]# ll ab
-rw-r--r-- 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod 754 ab
[root@localhost tmp]# ll ab
-rwxr-xr-- 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod 777 ab
[root@localhost tmp]# ll ab
-rwxrwxrwx 1 root root 9 Oct 25 22:36 ab
[root@localhost tmp]# chmod 644 ab
[root@localhost tmp]# ll ab
-rw-r--r-- 1 root root 9 Oct 25 22:36 ab
-R 修改目录和里面所有内容的权限
[root@localhost ~]# chmod -R 777 test/
[root@localhost ~]# ll -d test/
drwxrwxrwx 3 tom tom 4096 Oct 25 21:24 test/
[root@localhost ~]# ll test/
total 8004
drwxrwxrwx 2 tom tom 4096 Oct 25 05:50 aa
-rwxrwxrwx 1 tom tom 132 Oct 25 21:19 file
-rwxrwxrwx 1 tom tom 13332 Oct 25 21:23 file1
-rwxrwxrwx 1 tom tom 8159184 Oct 25 21:24 file2
wc 打印文件统计数据
-c 字节数
-m 字符数
-w 单词数
-l 打印行数
[root@localhost ~]# wc -c abc.txt
79 abc.txt
[root@localhost ~]# wc -m abc.txt
79 abc.txt
[root@localhost ~]# wc -w abc.txt
16 abc.txt
[root@localhost ~]# wc -l abc.txt
4 abc.txt
grep 过滤文件的行
打印文件中包含hello的行
[root@localhost ~]# grep -n --color hello abc.txt
1:hello hi
3:hi how are you fine hello
4:Thank you and you hello
打印文件中以hello开始的行
[root@localhost ~]# grep -n --color ^hello abc.txt
1:hello hi
打印文件中以hello结尾的行
[root@localhost ~]# grep -n --color hello$ abc.txt
3:hi how are you fine hello
4:Thank you and you hello
-------------------------------------------
管道
cmd1 | cmd2
把cmd1的输出,作为cmd2的输入
[root@localhost ~]# ls -l | grep ^-
-rw-rw-rw- 1 root root 0 Oct 25 21:08 ab
-rw-r--r-- 1 root root 114 Oct 25 23:41 abc.txt
-rw------- 1 root root 1327 Oct 24 14:12 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Oct 25 02:27 bfile
-rw-r--r-- 1 root root 0 Oct 24 23:39 file
-rw-r--r-- 1 root root 30675 Oct 24 14:12 install.log
-rw-r--r-- 1 root root 3738 Oct 24 14:12 install.log.syslog
-rw-r--r-- 1 root root 61260572 Mar 21 2014 VMwareTools-9.6.2-1688356.tar.gz
[root@localhost ~]# ls -l | grep ^- | wc -l
8
查找/etc下面所有的以.conf结尾的文件
find /etc -name "*.conf"
查询/etc下面有多少个以.conf结尾的文件
find /etc -name "*.conf" | wc -l
---------------------------------------------
查看文件或者目录的占用磁盘空间大小
[root@localhost ~]# du -sh test/
80K test/
创建压缩包,解压缩
tar创建压缩包:
方法1.
[root@localhost ~]# tar -czvf test.tar.gz test/
test/
test/file1
test/aa/
test/aa/file1
test/file2
test/file
[root@localhost ~]# ll -h test.tar*
-rw-r--r-- 1 root root 70K Oct 26 02:36 test.tar
-rw-r--r-- 1 root root 522 Oct 26 02:38 test.tar.gz
或者命名为xxxxx.tgz
[root@localhost ~]# tar -czvf test.tgz test/
方法2.
[root@localhost ~]# tar cjvf test.tar.bz2 test/
test/
test/file1
test/aa/
test/aa/file1
test/file2
test/file
解压缩: xvf
-C 指定解压位置
[root@localhost ~]# tar xvf test.tar.bz2 -C /opt
test/
test/file1
test/aa/
test/aa/file1
test/file2
test/file
把/etc目录创建压缩包,生成在/opt下面,名字叫etc.tar.gz
tar czvf /opt/etc.tar.gz /etc
把上面创建的压缩包解压到家目录下
tar xvf /opt/etc.tar.gz -C ~
----------------------------------------
程序: 可执行文件
进程: 程序执行一次的过程
查看系统所有进程
[root@localhost ~]# ps -ef
或者
[root@localhost ~]# ps aux
强制结束一个进程
kill -9 进程的pid
查看CPU信息
[root@localhost ~]# cat /proc/cpuinfo
查看内存信息
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1010 990 20 0 93 727
-/+ buffers/cache: 169 841
Swap: 2047 0 2047
查看网卡eth0的配置
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:90:A5:00
inet addr:192.168.72.131 Bcast:192.168.72.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe90:a500/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1302 errors:0 dropped:0 overruns:0 frame:0
TX packets:974 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:693827 (677.5 KiB) TX bytes:165777 (161.8 KiB)
Interrupt:67 Base address:0x2024
配置网卡的ip地址和子网掩码
[root@localhost ~]# ifconfig eth0 10.10.104.101 netmask 255.255.255.128
ping 命令的使用
-c 3 发送三次数据包
[root@localhost ~]# ping -c 3 10.10.104.22
PING 10.10.104.22 (10.10.104.22) 56(84) bytes of data.
64 bytes from 10.10.104.22: icmp_seq=1 ttl=128 time=0.198 ms
64 bytes from 10.10.104.22: icmp_seq=2 ttl=128 time=0.307 ms
64 bytes from 10.10.104.22: icmp_seq=3 ttl=128 time=0.310 ms
检查ssh服务是否运行
[root@localhost ~]# service sshd status
openssh-daemon (pid 3689) is running...
linux 系统服务管理:
service 服务名 status/stop/start/restart
例子: sshd远程登录服务
service sshd status/stop/start/restart
查看sshd服务在每个运行级别是否开机启动(图形界面对应运行级别5)
[root@localhost ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
设置sshd服务在运行级别5开机不启动
[root@localhost ~]# chkconfig --level 5 sshd off
Linux检查某个端口号是否被占用(监听)
[root@localhost ~]# netstat -an | grep 端口号
tcp 0 0 :::222 :::* LISTEN
Windows查看端口号是否被占用:
netstat -an | findstr 端口号
端口号: tomcat8080
oracl 1521
mysql 3306
http 80
sshd 22
-------------------------------------------------------
设置网卡eth0的静态IP和子网掩码
[root@localhost ~]# setup
或者
[root@localhost ~]# vim /etc/sysconfig/networking/devices/ifcfg-eth0
重启网络服务,立刻生效
[root@localhost ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
设置命令简写,只在当前窗口有效
[root@localhost ~]# alias rm='rm -rf'
查看系统的命令简写
[root@localhost ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -rf'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
临时设置环境变量
[root@localhost ~]# export TEST=lllllllllllllll
当前用户环境的配置文件: .bashrc
可以在该文件里设置环境变量,命令简写等
[root@localhost ~]# vim .bashrc
修改完该文件后,需要重新读取才能马上生效
[root@localhost ~]# source .bashrc
或者
[root@localhost ~]# . .bashrc
redhat 安装软件包
方法1: rpm
rpm -ivh xxxx.rmp
方法2: yum
把安装红帽系统的ISO镜像文件挂载到虚拟机
卸载文件系统
[root@localhost ~]# umount /dev/scd0
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
18156292 2733168 14485960 16% /
/dev/sda1 101086 12111 83756 13% /boot
tmpfs 517548 0 517548 0% /dev/shm
挂载文件系统
[root@localhost ~]# mount /dev/scd0 /mnt
mount: block device /dev/scd0 is write-protected, mounting read-only
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
18156292 2733168 14485960 16% /
/dev/sda1 101086 12111 83756 13% /boot
tmpfs 517548 0 517548 0% /dev/shm
/dev/scd0 2935370 2935370 0 100% /mnt
yum软件仓库配置文件
[root@localhost Server]# vim /etc/yum.repos.d/rhel-debuginfo.repo
本地源格式如下
[test]
name=Red
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
执行下面2条命令
[root@localhost ~]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@localhost ~]# yum list
卸载软件包
[root@localhost ~]# yum remove vim* -y
安装软件包
[root@localhost ~]# yum install vim* -y
[root@localhost ~]# yum remove wireshark* -y
[root@localhost ~]# yum install wireshark* -y
-------------------- LAMP (LINUX APACHE MYSQL PHP) 环境软件测试环境搭建---------------------------
检查是否安装Apache服务器,如果没有就安装
[root@localhost ~]# service httpd status
httpd: unrecognized service
[root@localhost ~]# yum install httpd* -y
检查是否安装MySQL服务器,如果没有就安装
[root@localhost ~]# service mysqld status
mysqld: unrecognized service
[root@localhost ~]# yum install mysql* -y
检查是否安装php,如果没有就安装
[root@localhost ~]# php
bash: php: command not found
[root@localhost ~]# yum install php* -y
确认Apache和MySQL安装成功并且启动
[root@localhost ~]# service mysqld status
mysqld (pid 12407) is running...
[root@localhost ~]# service mysqld status
mysqld (pid 12407) is running...
[root@localhost ~]# php
[root@localhost ~]#
删除该配置文件
[root@localhost ~]# rm /etc/httpd/conf.d/welcome.conf -rf
重启Apache服务
service httpd restart
把ecshop文档目录拷贝到apache默认的文档目录下
[root@localhost ~]# ls /var/www/html/
ecshop
---------------------------------------------------
连接远程MySQL服务器:
mysql.exe -h 10.10.100.23 -uroot -p123456
设置root用户可以从任意主机连接MySQL数据库服务器
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
------------------------------------------------------------------------
安装JDK:
1. 检查是否安装了其他版本的JDK,如果有,先卸载其他版本的
yum remove java* -y
2. 把要安装的jdk压缩包解压缩
3. 在家目录下的.bashrc中配置环境变量
vim ./~/.bashrc
export JAVA_HOME=/root/jdk1.8.0_111
export PATH=/root/jdk1.8.0_111/bin:$PATH
检查是否安装配置成功
[root@localhost ~]# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode)
[root@localhost ~]# echo $PATH
/root/jdk1.8.0_111/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@localhost ~]# echo $JAVA_HOME
/root/jdk1.8.0_111
[root@localhost ~]#
--------------------------------------------------------
安装tomcat
1. 解压缩tomcat压缩包
2. 执行bin目录下的startup.sh
./startup.sh
3. 打开浏览器测试
http://ip:8080