day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root root 1578 Oct 23 15:08 passwd
# ls -ld /test --查看目录的属性
drwxr-xr-x. 2 root root 4096 Oct 24 19:41 /test
权限位,共9位
rw- r-- r--
所有者权限 所属组权限 其他人权限
权限的种类:
针对文件:
r --读权限
w --写权限
x --可执行权限
针对目录
r --读目录内的内容
w --是否可以在目录下创建、删除文件
x --是否可以进入此目录
修改文件的权限:
chmod --改变文件权限命令
语法:chmod [ugo][+-=][rwx] filename
等值修改:
[root@localhost test]# ls -l myfile
-rw-r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u=r myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod g=rw myfile
[root@localhost test]# ls -l myfile
-r--rw-r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o=rwx myfile
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
增值修改:
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+x myfile
[root@localhost test]# ls -l myfile
-r-xrw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+w,g+x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
减值修改:
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o-x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrw-. 1 root root 0 Oct 24 20:04 myfile
权限值(八进制数):
r 4
w 2
x 1
以权限值的形式分配权限:
[root@localhost test]# ls -l myfile
-rwx------. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 444 myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 755 myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 root root 0 Oct 24 20:04 myfile
修改文件的所有者和所属组:
chown
[root@localhost test]# chown oracle:oracle mysqlfile1
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle oracle 0 Oct 24 20:40 mysqlfile1
[root@localhost test]# chown mysql:oracle myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 mysql oracle 0 Oct 24 20:04 myfile
[root@localhost test]# chown oracle passwd --只改所有者
[root@localhost test]# ls -l passwd
-rw-r--r--. 1 oracle root 1578 Oct 23 15:08 passwd
[root@localhost test]# chown .mysql mysqlfile1 --只改所属组
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle mysql 0 Oct 24 20:40 mysqlfile1
day1027
补充小知识:
rhel6 包含一个图形终端和5个仿真终端
ctrl+alt+F(1~7) --各个仿真终端间切换
编译安装:也称源码安装
案例:安装MPlayer
1、解包
[root@teacher ~]# tar -zxvf MPlayer-1.1.1.tar.gz -C /usr/local/src/
[root@teacher MPlayer-1.1.1]# pwd
/usr/local/src/MPlayer-1.1.1
2、配置:(检测此软件安装需要哪些依赖的环境)
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer
--prefix:指定软件安装位置
[root@teacher MPlayer-1.1.1]# yum install gcc -y
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer --yasm=''
3、编译:
[root@teacher MPlayer-1.1.1]# make
4、安装:
[root@teacher MPlayer-1.1.1]# make install
加载声音模块:
[root@teacher Desktop]# modprobe snd_pcm_oss
播放歌曲:
[root@teacher bin]# pwd
/usr/local/mplayer/bin
[root@teacher bin]# ./mplayer /root/wuyuetian.mp3
day1028
linux系统的启动级别:
# vim /etc/inittab
0 - halt (Do NOT set initdefault to this) --关机
1 - Single user mode --单用户模式
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
--多用户模式文本模式,不支持nfs
3 - Full multiuser mode -- 多用户模式文本模式,支持nfs
4 - unused --未启用的模式
5 - X11 --图形终端
6 - reboot (Do NOT set initdefault to this) --重启
各个级别之间切换:
# init 0-6
如何修改模式启动级别:
# vim /etc/inittab
id:5:initdefault:
关机命令:
# shutdown -h now
# poweroff
# init 0
# halt
# shutdown -h 10 --指定10分钟后关机
# shutdown -c --取消关机命令
重启命令:
# reboot
# init 6
# shutdown -r
如何修改root密码:
到单用户模式下使用passwd命令修改
*****************************************************************************
光盘的挂载:
mount
1、建立挂载点
2、挂载mount
3、查看挂载信息
# df -h
# mount
如何实现开机自动挂载光盘:
1、挂载光驱内的光盘
# vim /etc/fstab --存储开机自动挂载设备信息# man 5 fstab
/dev/sr0 /mnt/iso iso9660 defaults,loop 0 0
设备名称 挂载点 文件系统类型 默认选项 是否备份数据 磁盘检查顺序
# mount -a --读取/etc/fstab中未挂载的设备挂载
2、挂载系统镜像iso文件
# dd if=/dev/sr0 of=/root/rhel6u4i386.iso --将光驱中的iso文件备份到本地
--if源文件
--of目标文件
临时挂载:
# mount -o loop /mnt/winD/iso/rhel-server-6.4-i386-dvd.iso /mnt/iso
(loop表示回环挂载)
开机自动挂载
# vim /etc/fstab
/root/rhel6u4i386.iso /mnt/iso iso9660 defaults,loop 0 0
(loop表示回环挂载)
day1029
访问屏幕广播地址:vncviewer 172.16.254.100 -->密码redhat
访问笔记地址firefox http://172.16.254.100/day1029.txt &
分区开机自动挂载
临时挂载windows分区:
# mount -t ntfs /dev/sda2 /mnt/winD
永久挂载windows分区:
# vim /etc/fstab
/dev/sda2 /mnt/winD ntfs defaults 0 0
总结: 分区fdisk---->通知内核读取分区表partx--->创建文件系统mkfs---->挂载使用mount---->开机自动挂载/etc/fstab
linux下的磁盘管理:
查看分区信息:
# fdisk -l
如何分区:
# fdisk /dev/sda
n --添加分区
p --打印分区表信息
d --删除一个分区
q --退出不保存
w --保存并退出
案例1:划分扩展分区:
[root@teacher ~]# fdisk /dev/sda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e --指定分区类型为扩展分区
Selected partition 4
First cylinder (5509-26108, default 5509): --分区的起始位置
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108):
--指定分区的结束为止
Using default value 26108
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
案例2:添加一个20G大小的分区
Command (m for help): n
First cylinder (5509-26108, default 5509):
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108): +20G --设置分区大小为20G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
通知内核重新读取分区
[root@teacher ~]# partx -a /dev/sda
[root@teacher ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
创建文件系统:
[root@teacher ~]# mkfs.ext4 /dev/sda5 --格式化sda5分区为ext4文件系统
或
[root@teacher ~]# mkfs -t ext4 /dev/sda5
挂载硬盘
[root@teacher ~]# mkdir /mnt/sda5
[root@teacher ~]# mount /dev/sda5 /mnt/sda5
实现开机自动挂载:
# vim /etc/fstab
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
***************************************************************************************************************
如何删除分区:
注意:先备份重要数据
1、删除fstab中对应的开机自动挂载记录
# vim /etc/fstab
2、卸载
# umount /dev/sda6
3、删除分区
[root@teacher ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-6): 6 --指定要删除的分区变号
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
4、通知内核重新读取分区表
[root@teacher ~]# partx -d --nr 6 /dev/sda
day102501
系统安装后的基本配置:
1、配置ip地址
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 --打开网卡配置文件
1 DEVICE=eth0 --网卡设备名称
2 HWADDR=00:0C:29:2B:47:94 --物理地址(MAC地址)
3 TYPE=Ethernet --网络类型(以太网)
4 UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4 --全球唯一标识符
5 ONBOOT=yes --是否开机自动激活
6 NM_CONTROLLED=no --是否受networkmanager的管理
7 BOOTPROTO=static
--获取ip地址的形式(dhcp动态、static静态、none不使用任何协议)
8 IPADDR=172.16.254.100 --ip地址
9 NETMASK=255.255.0.0 --子网掩码
[root@localhost ~]# service network restart --重启网络服务
[root@localhost ~]# ifconfig --查看网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:2B:47:94
inet addr:172.16.254.101 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe2b:4794/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13645 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1744909 (1.6 MiB) TX bytes:2056 (2.0 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11112 (10.8 KiB) TX bytes:11112 (10.8 KiB)
[root@localhost ~]# ping 172.16.254.101 --测试网络连通性
2、关闭selinux
永久关闭:
[root@localhost ~]# vim /etc/selinux/config --打开selinux配置文件
SELINUX=disabled --enforcing 强制开启
--permissive 警告,但不阻止
--disabled 关闭
[root@localhost ~]# sestatus --查看状态
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
[root@localhost ~]# reboot
[root@localhost ~]# sestatus --查看状态
SELinux status: disabled
临时关闭:
[root@localhost ~]# setenforce 0 (0:临时关闭,1:临时开启)
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
3、关闭防火墙(iptables)
[root@localhost ~]# iptables -L --查看状态
[root@localhost ~]# iptables -F --清空规则
[root@localhost ~]# iptables -L --再查看状态
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# service iptables stop --关闭iptables服务
[root@localhost ~]# chkconfig iptables off --开机不自动启动
4、设置主机名
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network --打开配置主机名的配置文件
NETWORKING=yes
HOSTNAME=teacher.uplooking.com
[root@localhost ~]# reboot --重启生效
临时修改
[root@localhost ~]# hostname teacher.uplooking.com
[root@localhost ~]# hostname
teacher.uplooking.com
作业:新建一个虚拟机,然后配置以上4步骤。
day102502
了解根目录下各个目录的作用:
见图片
文件查找:
locate --以文件名查找文件,基于数据库查找,是最快的查找方式
[root@teacher test]# touch ifcfg-eth0
[root@teacher test]# ls
ifcfg-eth0 passwd shadow
[root@teacher test]# locate ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@teacher test]# updatedb --更新数据库
数据库位置:
[root@teacher mlocate]# ls /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db
find --基于路径查找,比较慢,不用更新数据库
语法:find+路径+查找类型+参数
以文件名称查找:
[root@teacher test]# find / -name ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name "file*" --查找文件名称以file开头
/test/file1
/test/file2
/test/file5
/test/file4
/test/file3
[root@teacher test]# find / -name "*file*" --查找所有包含服了关键字的文件
以文件大小查找:(c、k、M、G)
[root@teacher test]# find /test -size +10k --查找大于10k大小
/test/install.log
[root@teacher test]# find /test -size 10k --查找等于10k大小
[root@teacher test]# find /test -size -10k --查找小于10k大小
以文件的类型查找:
root@teacher test]# find / -type f
-type支持的文件类型
f 普通文件
d 目录文件
l 软链接文件
s 套接字文件
p 管道文件
b 块设备文件
c 字符设备
[root@teacher test]# find /test -type d
[root@teacher test]# find /test -type f
[root@teacher test]# find /dev -type b
[root@teacher test]# find /bin -type l -ls
1179652 0 lrwxrwxrwx 1 root root 4 Oct 19 15:57 /bin/awk -> gawk
[root@teacher test]# find /var -type s
[root@teacher test]# find /var -type p -ls
通过文件的所有者查找文件:
[root@teacher test]# find /test -user mysql
综合运用:
[root@teacher test]# find /test -size +3k -type d
/test
/test/mydir
[root@teacher test]# find /test -size +3k -type f
/test/install.log
逻辑运算关系:
-and 并
# find /etc -size +50k -and -size -60k -and -type f
-o 或
# find /etc -size 1500k -o -size 0
-not 非(!)
# find /test -not -name "*.conf"
which: --查找命令文件所在路径
[root@teacher ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@teacher ~]# which pwd
/bin/pwd
[root@teacher ~]# which ifconfig
/sbin/ifconfig
[root@teacher ~]# which groupadd
/usr/sbin/groupadd
which去哪查找命令:
[root@teacher ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
[root@teacher ~]# which uplook
/usr/bin/which:no uplook in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
whereis:
--命令的绝对路径
--命令的帮助文件路径
--和命令同名的文件路径
[root@teacher ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@teacher ~]# man ls
[root@teacher ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
day102503
文件的打包与压缩:
windows下的打包压缩工具:winrar、360压缩、7zip、好压
压缩:有损压缩、无损压缩
压缩的好处:节省空间、用于网络传输、用于备份
linux下的压缩方式:
zip:
[root@teacher test]# zip /tmp/resolv.conf.zip resolv.conf --压缩单个文件
[root@teacher test]# less resolv.conf.zip --查看压缩包内容
[root@teacher test]# zip -r /tmp/test.zip /test --压缩整个目录
[root@teacher test]# unzip resolv.conf.zip -d /tmp --解压命令,d:代表解压到的路径
gzip:
[root@teacher test]# gzip ntp.conf --压缩单个文件,删除源文件
[root@teacher test]# less ntp.conf.gz --查看压缩文件内容
[root@teacher test]# zcat ntp.conf.gz --查看压缩文件内容
[root@teacher test]# gzip -r /test --压缩整个目录内的所有文件(不支持压缩整个目录)
[root@teacher test]# gunzip -r /test --解压目录内的所有文件
[root@teacher test]# gunzip ntp.conf.gz --解压单个文件
bzip2:
[root@teacher test]# bzip2 yum.conf --压缩单个文件,删除源文件
[root@teacher test]# less yum.conf.bz2 --查看文件内容
[root@teacher test]# bzcat yum.conf.bz2 --查看文件内容
[root@teacher test]# bunzip2 yum.conf.bz2 --解压单个文件
[root@teacher test]# bzip2 /test/* --压缩整个目录内的所有文件
[root@teacher test]# bunzip2 /test/* --解压整个目录内的所有压缩文件
作业:
1、安装一个虚拟机,然后设置ip地址、关闭iptables、关闭selinx、设置主机名
2、找出 /etc 底下,文件大小介于 50K 到 60K 之间的文件
3、找出 /etc 底下,文件大小大于 1500K 以及容量等于 0 的文件
4、找到yum命令的路径
5、找到ntp.conf文件的位置
6、拷贝/etc/inittab文件到/test目录下,分别用zip、gzip和bzip2命令进行压缩和解压实验
day102601
打包命令:
tar :实现打包和压缩
选项:
-c --create创建一个tar包
-x --解包
-v --显示创建过程
-f --指定包的名称
-t --查看包的内容
-C --指定解压路径
-z --将tar包压缩为.gz形式
-j --将tar包压缩为.bz2形式
# tar -cvf conf.tar sudo.conf yp.conf yum.conf --打包多个文件
# tar -tf conf.tar --查看包的内容
# tar -cvf /tmp/test.tar /test/ --打包整个目录
# tar -xvf /tmp/test.tar -C /usr/local/src/ --解包
# tar -zcvf /tmp/test.tar.gz /test --打包并压缩为gz形式
# tar -jcvf /tmp/test.tar.bz2 /test --打包并压缩为bz2形式
# tar -zxvf /tmp/test.tar.gz -C /usr/local/src/ --解压缩gz形式的tar包
# tar -jxvf /tmp/test.tar.bz2 -C /usr/local/src/ --解压缩bz2形式的tar包
远程拷贝命令:
从远程主机拷贝到本地
# scp 172.16.254.101:/root/kolourpaint-1.2.2_kde3.tar.bz2 /tmp
# scp 172.16.254.101:/root/notecase-1.9.8_slack.tar.gz /tmp
从本地拷贝到远程主机
# scp /root/kolourpaint-1.2.2_kde3.tar.bz2 172.16.23.23:/root
day102602
软件安装:
软件位置:1、系统光盘中。2、网络源
手动光盘的挂载:
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
[root@teacher Desktop]# mkdir /mnt/iso --建立挂载点
[root@teacher Desktop]# mount /dev/sr0 /mnt/iso --挂载光驱
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
如何卸载光盘:
[root@teacher ~]# umount /mnt/iso --umount+挂载点或设备路径
[root@teacher ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
软件包的命名格式:
httpd-2.2.15-26.el6.i686.rpm
软件包名-软件版本号-操作系统发行版-系统平台-扩展名
i686/i386 代表32位系统平台
x86_64 代表64位系统平台
noarch 代表32/64都支持
软件安装工具:rpm、yum
rpm --本地安装工具,不能解决依赖关系
-i --安装install
-v --显示安装过程
-h --是否显示#进度条
-e --卸载
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm --安装软件
# rpm -e vsftpd --卸载软件
# rpm -q unix2dos --查询软件是否安装
# rpm -qa --查看已经安装的包
# rpm -qa | wc -l --查看一共安装多少个软件
# rpm -qf /usr/bin/finger --查找一个命令由哪个软件包提供(注意:命令的绝对路径)
# rpm -qf `which finger` --嵌套执行命令
# rpm -ql httpd --查看一个软件产生了哪些文件
# rpm -ivh finger-0.17-39.el6.i686.rpm --force --覆盖安装
yum --Yellowdog Updater Modified --在线安装工具,可以解决依赖关系()
如何配置yum:
1、挂载光盘
# df -h | grep sr0
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
2、编辑yum的配置文件
# vim /etc/yum.repos.d/local.repo (文件名称必须以.repo结尾)
1 [base] --软件仓库的名称(即唯一标识符)
2 name=base --此软件仓库的描述信息,给管理员看的
3 baseurl=file:///mnt/iso --软件仓库路径
4 enabled=1 --是否启用此仓库
5 gpgcheck=0 --是否开启软件的数字签名认证
如何配置网络yum源:
9 [http]
10 name=http
11 baseurl=http://172.16.254.101/iso
12 enabled=1
13 gpgcheck=0
3、测试yum
# yum list
# yum clean all
利用yum安装软件包:
# yum install gcc -y --安装
# yum remove vsftpd --卸载
# yum search gcc --搜索所有包含gcc关键字的包名
# yum provides "*/finger" --查找一个命令由哪个软件包安装
利用yum安装软件包组:
# yum grouplist --查看软件包组
# yum groupinstall "Desktop" --安装软件包组
# yum groupremove "Desktop" --卸载软件包组
作业:1、安装一个最小化的虚拟机(不带图形)
2、配置ip地址、seliux、主机名、iptables、yum
3、安装图形
# startx 从文本终端切换到图形界面
总结yum:
挂载光盘(mount)---->编辑配置文件(.repo)---->测试yum list
day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root root 1578 Oct 23 15:08 passwd
# ls -ld /test --查看目录的属性
drwxr-xr-x. 2 root root 4096 Oct 24 19:41 /test
权限位,共9位
rw- r-- r--
所有者权限 所属组权限 其他人权限
权限的种类:
针对文件:
r --读权限
w --写权限
x --可执行权限
针对目录
r --读目录内的内容
w --是否可以在目录下创建、删除文件
x --是否可以进入此目录
修改文件的权限:
chmod --改变文件权限命令
语法:chmod [ugo][+-=][rwx] filename
等值修改:
[root@localhost test]# ls -l myfile
-rw-r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u=r myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod g=rw myfile
[root@localhost test]# ls -l myfile
-r--rw-r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o=rwx myfile
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
增值修改:
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+x myfile
[root@localhost test]# ls -l myfile
-r-xrw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+w,g+x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
减值修改:
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o-x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrw-. 1 root root 0 Oct 24 20:04 myfile
权限值(八进制数):
r 4
w 2
x 1
以权限值的形式分配权限:
[root@localhost test]# ls -l myfile
-rwx------. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 444 myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 755 myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 root root 0 Oct 24 20:04 myfile
修改文件的所有者和所属组:
chown
[root@localhost test]# chown oracle:oracle mysqlfile1
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle oracle 0 Oct 24 20:40 mysqlfile1
[root@localhost test]# chown mysql:oracle myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 mysql oracle 0 Oct 24 20:04 myfile
[root@localhost test]# chown oracle passwd --只改所有者
[root@localhost test]# ls -l passwd
-rw-r--r--. 1 oracle root 1578 Oct 23 15:08 passwd
[root@localhost test]# chown .mysql mysqlfile1 --只改所属组
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle mysql 0 Oct 24 20:40 mysqlfile1
day1027
补充小知识:
rhel6 包含一个图形终端和5个仿真终端
ctrl+alt+F(1~7) --各个仿真终端间切换
编译安装:也称源码安装
案例:安装MPlayer
1、解包
[root@teacher ~]# tar -zxvf MPlayer-1.1.1.tar.gz -C /usr/local/src/
[root@teacher MPlayer-1.1.1]# pwd
/usr/local/src/MPlayer-1.1.1
2、配置:(检测此软件安装需要哪些依赖的环境)
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer
--prefix:指定软件安装位置
[root@teacher MPlayer-1.1.1]# yum install gcc -y
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer --yasm=''
3、编译:
[root@teacher MPlayer-1.1.1]# make
4、安装:
[root@teacher MPlayer-1.1.1]# make install
加载声音模块:
[root@teacher Desktop]# modprobe snd_pcm_oss
播放歌曲:
[root@teacher bin]# pwd
/usr/local/mplayer/bin
[root@teacher bin]# ./mplayer /root/wuyuetian.mp3
day1028
linux系统的启动级别:
# vim /etc/inittab
0 - halt (Do NOT set initdefault to this) --关机
1 - Single user mode --单用户模式
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
--多用户模式文本模式,不支持nfs
3 - Full multiuser mode -- 多用户模式文本模式,支持nfs
4 - unused --未启用的模式
5 - X11 --图形终端
6 - reboot (Do NOT set initdefault to this) --重启
各个级别之间切换:
# init 0-6
如何修改模式启动级别:
# vim /etc/inittab
id:5:initdefault:
关机命令:
# shutdown -h now
# poweroff
# init 0
# halt
# shutdown -h 10 --指定10分钟后关机
# shutdown -c --取消关机命令
重启命令:
# reboot
# init 6
# shutdown -r
如何修改root密码:
到单用户模式下使用passwd命令修改
*****************************************************************************
光盘的挂载:
mount
1、建立挂载点
2、挂载mount
3、查看挂载信息
# df -h
# mount
如何实现开机自动挂载光盘:
1、挂载光驱内的光盘
# vim /etc/fstab --存储开机自动挂载设备信息# man 5 fstab
/dev/sr0 /mnt/iso iso9660 defaults,loop 0 0
设备名称 挂载点 文件系统类型 默认选项 是否备份数据 磁盘检查顺序
# mount -a --读取/etc/fstab中未挂载的设备挂载
2、挂载系统镜像iso文件
# dd if=/dev/sr0 of=/root/rhel6u4i386.iso --将光驱中的iso文件备份到本地
--if源文件
--of目标文件
临时挂载:
# mount -o loop /mnt/winD/iso/rhel-server-6.4-i386-dvd.iso /mnt/iso
(loop表示回环挂载)
开机自动挂载
# vim /etc/fstab
/root/rhel6u4i386.iso /mnt/iso iso9660 defaults,loop 0 0
(loop表示回环挂载)
day1029
访问屏幕广播地址:vncviewer 172.16.254.100 -->密码redhat
访问笔记地址firefox http://172.16.254.100/day1029.txt &
分区开机自动挂载
临时挂载windows分区:
# mount -t ntfs /dev/sda2 /mnt/winD
永久挂载windows分区:
# vim /etc/fstab
/dev/sda2 /mnt/winD ntfs defaults 0 0
总结: 分区fdisk---->通知内核读取分区表partx--->创建文件系统mkfs---->挂载使用mount---->开机自动挂载/etc/fstab
linux下的磁盘管理:
查看分区信息:
# fdisk -l
如何分区:
# fdisk /dev/sda
n --添加分区
p --打印分区表信息
d --删除一个分区
q --退出不保存
w --保存并退出
案例1:划分扩展分区:
[root@teacher ~]# fdisk /dev/sda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e --指定分区类型为扩展分区
Selected partition 4
First cylinder (5509-26108, default 5509): --分区的起始位置
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108):
--指定分区的结束为止
Using default value 26108
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
案例2:添加一个20G大小的分区
Command (m for help): n
First cylinder (5509-26108, default 5509):
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108): +20G --设置分区大小为20G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
通知内核重新读取分区
[root@teacher ~]# partx -a /dev/sda
[root@teacher ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
创建文件系统:
[root@teacher ~]# mkfs.ext4 /dev/sda5 --格式化sda5分区为ext4文件系统
或
[root@teacher ~]# mkfs -t ext4 /dev/sda5
挂载硬盘
[root@teacher ~]# mkdir /mnt/sda5
[root@teacher ~]# mount /dev/sda5 /mnt/sda5
实现开机自动挂载:
# vim /etc/fstab
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
***************************************************************************************************************
如何删除分区:
注意:先备份重要数据
1、删除fstab中对应的开机自动挂载记录
# vim /etc/fstab
2、卸载
# umount /dev/sda6
3、删除分区
[root@teacher ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-6): 6 --指定要删除的分区变号
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
4、通知内核重新读取分区表
[root@teacher ~]# partx -d --nr 6 /dev/sda
day102501
系统安装后的基本配置:
1、配置ip地址
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 --打开网卡配置文件
1 DEVICE=eth0 --网卡设备名称
2 HWADDR=00:0C:29:2B:47:94 --物理地址(MAC地址)
3 TYPE=Ethernet --网络类型(以太网)
4 UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4 --全球唯一标识符
5 ONBOOT=yes --是否开机自动激活
6 NM_CONTROLLED=no --是否受networkmanager的管理
7 BOOTPROTO=static
--获取ip地址的形式(dhcp动态、static静态、none不使用任何协议)
8 IPADDR=172.16.254.100 --ip地址
9 NETMASK=255.255.0.0 --子网掩码
[root@localhost ~]# service network restart --重启网络服务
[root@localhost ~]# ifconfig --查看网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:2B:47:94
inet addr:172.16.254.101 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe2b:4794/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13645 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1744909 (1.6 MiB) TX bytes:2056 (2.0 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11112 (10.8 KiB) TX bytes:11112 (10.8 KiB)
[root@localhost ~]# ping 172.16.254.101 --测试网络连通性
2、关闭selinux
永久关闭:
[root@localhost ~]# vim /etc/selinux/config --打开selinux配置文件
SELINUX=disabled --enforcing 强制开启
--permissive 警告,但不阻止
--disabled 关闭
[root@localhost ~]# sestatus --查看状态
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
[root@localhost ~]# reboot
[root@localhost ~]# sestatus --查看状态
SELinux status: disabled
临时关闭:
[root@localhost ~]# setenforce 0 (0:临时关闭,1:临时开启)
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
3、关闭防火墙(iptables)
[root@localhost ~]# iptables -L --查看状态
[root@localhost ~]# iptables -F --清空规则
[root@localhost ~]# iptables -L --再查看状态
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# service iptables stop --关闭iptables服务
[root@localhost ~]# chkconfig iptables off --开机不自动启动
4、设置主机名
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network --打开配置主机名的配置文件
NETWORKING=yes
HOSTNAME=teacher.uplooking.com
[root@localhost ~]# reboot --重启生效
临时修改
[root@localhost ~]# hostname teacher.uplooking.com
[root@localhost ~]# hostname
teacher.uplooking.com
作业:新建一个虚拟机,然后配置以上4步骤。
day102502
了解根目录下各个目录的作用:
见图片
文件查找:
locate --以文件名查找文件,基于数据库查找,是最快的查找方式
[root@teacher test]# touch ifcfg-eth0
[root@teacher test]# ls
ifcfg-eth0 passwd shadow
[root@teacher test]# locate ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@teacher test]# updatedb --更新数据库
数据库位置:
[root@teacher mlocate]# ls /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db
find --基于路径查找,比较慢,不用更新数据库
语法:find+路径+查找类型+参数
以文件名称查找:
[root@teacher test]# find / -name ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name "file*" --查找文件名称以file开头
/test/file1
/test/file2
/test/file5
/test/file4
/test/file3
[root@teacher test]# find / -name "*file*" --查找所有包含服了关键字的文件
以文件大小查找:(c、k、M、G)
[root@teacher test]# find /test -size +10k --查找大于10k大小
/test/install.log
[root@teacher test]# find /test -size 10k --查找等于10k大小
[root@teacher test]# find /test -size -10k --查找小于10k大小
以文件的类型查找:
root@teacher test]# find / -type f
-type支持的文件类型
f 普通文件
d 目录文件
l 软链接文件
s 套接字文件
p 管道文件
b 块设备文件
c 字符设备
[root@teacher test]# find /test -type d
[root@teacher test]# find /test -type f
[root@teacher test]# find /dev -type b
[root@teacher test]# find /bin -type l -ls
1179652 0 lrwxrwxrwx 1 root root 4 Oct 19 15:57 /bin/awk -> gawk
[root@teacher test]# find /var -type s
[root@teacher test]# find /var -type p -ls
通过文件的所有者查找文件:
[root@teacher test]# find /test -user mysql
综合运用:
[root@teacher test]# find /test -size +3k -type d
/test
/test/mydir
[root@teacher test]# find /test -size +3k -type f
/test/install.log
逻辑运算关系:
-and 并
# find /etc -size +50k -and -size -60k -and -type f
-o 或
# find /etc -size 1500k -o -size 0
-not 非(!)
# find /test -not -name "*.conf"
which: --查找命令文件所在路径
[root@teacher ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@teacher ~]# which pwd
/bin/pwd
[root@teacher ~]# which ifconfig
/sbin/ifconfig
[root@teacher ~]# which groupadd
/usr/sbin/groupadd
which去哪查找命令:
[root@teacher ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
[root@teacher ~]# which uplook
/usr/bin/which:no uplook in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
whereis:
--命令的绝对路径
--命令的帮助文件路径
--和命令同名的文件路径
[root@teacher ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@teacher ~]# man ls
[root@teacher ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
day102503
文件的打包与压缩:
windows下的打包压缩工具:winrar、360压缩、7zip、好压
压缩:有损压缩、无损压缩
压缩的好处:节省空间、用于网络传输、用于备份
linux下的压缩方式:
zip:
[root@teacher test]# zip /tmp/resolv.conf.zip resolv.conf --压缩单个文件
[root@teacher test]# less resolv.conf.zip --查看压缩包内容
[root@teacher test]# zip -r /tmp/test.zip /test --压缩整个目录
[root@teacher test]# unzip resolv.conf.zip -d /tmp --解压命令,d:代表解压到的路径
gzip:
[root@teacher test]# gzip ntp.conf --压缩单个文件,删除源文件
[root@teacher test]# less ntp.conf.gz --查看压缩文件内容
[root@teacher test]# zcat ntp.conf.gz --查看压缩文件内容
[root@teacher test]# gzip -r /test --压缩整个目录内的所有文件(不支持压缩整个目录)
[root@teacher test]# gunzip -r /test --解压目录内的所有文件
[root@teacher test]# gunzip ntp.conf.gz --解压单个文件
bzip2:
[root@teacher test]# bzip2 yum.conf --压缩单个文件,删除源文件
[root@teacher test]# less yum.conf.bz2 --查看文件内容
[root@teacher test]# bzcat yum.conf.bz2 --查看文件内容
[root@teacher test]# bunzip2 yum.conf.bz2 --解压单个文件
[root@teacher test]# bzip2 /test/* --压缩整个目录内的所有文件
[root@teacher test]# bunzip2 /test/* --解压整个目录内的所有压缩文件
作业:
1、安装一个虚拟机,然后设置ip地址、关闭iptables、关闭selinx、设置主机名
2、找出 /etc 底下,文件大小介于 50K 到 60K 之间的文件
3、找出 /etc 底下,文件大小大于 1500K 以及容量等于 0 的文件
4、找到yum命令的路径
5、找到ntp.conf文件的位置
6、拷贝/etc/inittab文件到/test目录下,分别用zip、gzip和bzip2命令进行压缩和解压实验
day102601
打包命令:
tar :实现打包和压缩
选项:
-c --create创建一个tar包
-x --解包
-v --显示创建过程
-f --指定包的名称
-t --查看包的内容
-C --指定解压路径
-z --将tar包压缩为.gz形式
-j --将tar包压缩为.bz2形式
# tar -cvf conf.tar sudo.conf yp.conf yum.conf --打包多个文件
# tar -tf conf.tar --查看包的内容
# tar -cvf /tmp/test.tar /test/ --打包整个目录
# tar -xvf /tmp/test.tar -C /usr/local/src/ --解包
# tar -zcvf /tmp/test.tar.gz /test --打包并压缩为gz形式
# tar -jcvf /tmp/test.tar.bz2 /test --打包并压缩为bz2形式
# tar -zxvf /tmp/test.tar.gz -C /usr/local/src/ --解压缩gz形式的tar包
# tar -jxvf /tmp/test.tar.bz2 -C /usr/local/src/ --解压缩bz2形式的tar包
远程拷贝命令:
从远程主机拷贝到本地
# scp 172.16.254.101:/root/kolourpaint-1.2.2_kde3.tar.bz2 /tmp
# scp 172.16.254.101:/root/notecase-1.9.8_slack.tar.gz /tmp
从本地拷贝到远程主机
# scp /root/kolourpaint-1.2.2_kde3.tar.bz2 172.16.23.23:/root
day102602
软件安装:
软件位置:1、系统光盘中。2、网络源
手动光盘的挂载:
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
[root@teacher Desktop]# mkdir /mnt/iso --建立挂载点
[root@teacher Desktop]# mount /dev/sr0 /mnt/iso --挂载光驱
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
如何卸载光盘:
[root@teacher ~]# umount /mnt/iso --umount+挂载点或设备路径
[root@teacher ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
软件包的命名格式:
httpd-2.2.15-26.el6.i686.rpm
软件包名-软件版本号-操作系统发行版-系统平台-扩展名
i686/i386 代表32位系统平台
x86_64 代表64位系统平台
noarch 代表32/64都支持
软件安装工具:rpm、yum
rpm --本地安装工具,不能解决依赖关系
-i --安装install
-v --显示安装过程
-h --是否显示#进度条
-e --卸载
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm --安装软件
# rpm -e vsftpd --卸载软件
# rpm -q unix2dos --查询软件是否安装
# rpm -qa --查看已经安装的包
# rpm -qa | wc -l --查看一共安装多少个软件
# rpm -qf /usr/bin/finger --查找一个命令由哪个软件包提供(注意:命令的绝对路径)
# rpm -qf `which finger` --嵌套执行命令
# rpm -ql httpd --查看一个软件产生了哪些文件
# rpm -ivh finger-0.17-39.el6.i686.rpm --force --覆盖安装
yum --Yellowdog Updater Modified --在线安装工具,可以解决依赖关系()
如何配置yum:
1、挂载光盘
# df -h | grep sr0
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
2、编辑yum的配置文件
# vim /etc/yum.repos.d/local.repo (文件名称必须以.repo结尾)
1 [base] --软件仓库的名称(即唯一标识符)
2 name=base --此软件仓库的描述信息,给管理员看的
3 baseurl=file:///mnt/iso --软件仓库路径
4 enabled=1 --是否启用此仓库
5 gpgcheck=0 --是否开启软件的数字签名认证
如何配置网络yum源:
9 [http]
10 name=http
11 baseurl=http://172.16.254.101/iso
12 enabled=1
13 gpgcheck=0
3、测试yum
# yum list
# yum clean all
利用yum安装软件包:
# yum install gcc -y --安装
# yum remove vsftpd --卸载
# yum search gcc --搜索所有包含gcc关键字的包名
# yum provides "*/finger" --查找一个命令由哪个软件包安装
利用yum安装软件包组:
# yum grouplist --查看软件包组
# yum groupinstall "Desktop" --安装软件包组
# yum groupremove "Desktop" --卸载软件包组
作业:1、安装一个最小化的虚拟机(不带图形)
2、配置ip地址、seliux、主机名、iptables、yum
3、安装图形
# startx 从文本终端切换到图形界面
总结yum:
挂载光盘(mount)---->编辑配置文件(.repo)---->测试yum list
day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root root 1578 Oct 23 15:08 passwd
# ls -ld /test --查看目录的属性
drwxr-xr-x. 2 root root 4096 Oct 24 19:41 /test
权限位,共9位
rw- r-- r--
所有者权限 所属组权限 其他人权限
权限的种类:
针对文件:
r --读权限
w --写权限
x --可执行权限
针对目录
r --读目录内的内容
w --是否可以在目录下创建、删除文件
x --是否可以进入此目录
修改文件的权限:
chmod --改变文件权限命令
语法:chmod [ugo][+-=][rwx] filename
等值修改:
[root@localhost test]# ls -l myfile
-rw-r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u=r myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod g=rw myfile
[root@localhost test]# ls -l myfile
-r--rw-r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o=rwx myfile
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
增值修改:
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+x myfile
[root@localhost test]# ls -l myfile
-r-xrw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+w,g+x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
减值修改:
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o-x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrw-. 1 root root 0 Oct 24 20:04 myfile
权限值(八进制数):
r 4
w 2
x 1
以权限值的形式分配权限:
[root@localhost test]# ls -l myfile
-rwx------. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 444 myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 755 myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 root root 0 Oct 24 20:04 myfile
修改文件的所有者和所属组:
chown
[root@localhost test]# chown oracle:oracle mysqlfile1
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle oracle 0 Oct 24 20:40 mysqlfile1
[root@localhost test]# chown mysql:oracle myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 mysql oracle 0 Oct 24 20:04 myfile
[root@localhost test]# chown oracle passwd --只改所有者
[root@localhost test]# ls -l passwd
-rw-r--r--. 1 oracle root 1578 Oct 23 15:08 passwd
[root@localhost test]# chown .mysql mysqlfile1 --只改所属组
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle mysql 0 Oct 24 20:40 mysqlfile1
day1027
补充小知识:
rhel6 包含一个图形终端和5个仿真终端
ctrl+alt+F(1~7) --各个仿真终端间切换
编译安装:也称源码安装
案例:安装MPlayer
1、解包
[root@teacher ~]# tar -zxvf MPlayer-1.1.1.tar.gz -C /usr/local/src/
[root@teacher MPlayer-1.1.1]# pwd
/usr/local/src/MPlayer-1.1.1
2、配置:(检测此软件安装需要哪些依赖的环境)
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer
--prefix:指定软件安装位置
[root@teacher MPlayer-1.1.1]# yum install gcc -y
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer --yasm=''
3、编译:
[root@teacher MPlayer-1.1.1]# make
4、安装:
[root@teacher MPlayer-1.1.1]# make install
加载声音模块:
[root@teacher Desktop]# modprobe snd_pcm_oss
播放歌曲:
[root@teacher bin]# pwd
/usr/local/mplayer/bin
[root@teacher bin]# ./mplayer /root/wuyuetian.mp3
day1028
linux系统的启动级别:
# vim /etc/inittab
0 - halt (Do NOT set initdefault to this) --关机
1 - Single user mode --单用户模式
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
--多用户模式文本模式,不支持nfs
3 - Full multiuser mode -- 多用户模式文本模式,支持nfs
4 - unused --未启用的模式
5 - X11 --图形终端
6 - reboot (Do NOT set initdefault to this) --重启
各个级别之间切换:
# init 0-6
如何修改模式启动级别:
# vim /etc/inittab
id:5:initdefault:
关机命令:
# shutdown -h now
# poweroff
# init 0
# halt
# shutdown -h 10 --指定10分钟后关机
# shutdown -c --取消关机命令
重启命令:
# reboot
# init 6
# shutdown -r
如何修改root密码:
到单用户模式下使用passwd命令修改
*****************************************************************************
光盘的挂载:
mount
1、建立挂载点
2、挂载mount
3、查看挂载信息
# df -h
# mount
如何实现开机自动挂载光盘:
1、挂载光驱内的光盘
# vim /etc/fstab --存储开机自动挂载设备信息# man 5 fstab
/dev/sr0 /mnt/iso iso9660 defaults,loop 0 0
设备名称 挂载点 文件系统类型 默认选项 是否备份数据 磁盘检查顺序
# mount -a --读取/etc/fstab中未挂载的设备挂载
2、挂载系统镜像iso文件
# dd if=/dev/sr0 of=/root/rhel6u4i386.iso --将光驱中的iso文件备份到本地
--if源文件
--of目标文件
临时挂载:
# mount -o loop /mnt/winD/iso/rhel-server-6.4-i386-dvd.iso /mnt/iso
(loop表示回环挂载)
开机自动挂载
# vim /etc/fstab
/root/rhel6u4i386.iso /mnt/iso iso9660 defaults,loop 0 0
(loop表示回环挂载)
day1029
访问屏幕广播地址:vncviewer 172.16.254.100 -->密码redhat
访问笔记地址firefox http://172.16.254.100/day1029.txt &
分区开机自动挂载
临时挂载windows分区:
# mount -t ntfs /dev/sda2 /mnt/winD
永久挂载windows分区:
# vim /etc/fstab
/dev/sda2 /mnt/winD ntfs defaults 0 0
总结: 分区fdisk---->通知内核读取分区表partx--->创建文件系统mkfs---->挂载使用mount---->开机自动挂载/etc/fstab
linux下的磁盘管理:
查看分区信息:
# fdisk -l
如何分区:
# fdisk /dev/sda
n --添加分区
p --打印分区表信息
d --删除一个分区
q --退出不保存
w --保存并退出
案例1:划分扩展分区:
[root@teacher ~]# fdisk /dev/sda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e --指定分区类型为扩展分区
Selected partition 4
First cylinder (5509-26108, default 5509): --分区的起始位置
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108):
--指定分区的结束为止
Using default value 26108
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
案例2:添加一个20G大小的分区
Command (m for help): n
First cylinder (5509-26108, default 5509):
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108): +20G --设置分区大小为20G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
通知内核重新读取分区
[root@teacher ~]# partx -a /dev/sda
[root@teacher ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
创建文件系统:
[root@teacher ~]# mkfs.ext4 /dev/sda5 --格式化sda5分区为ext4文件系统
或
[root@teacher ~]# mkfs -t ext4 /dev/sda5
挂载硬盘
[root@teacher ~]# mkdir /mnt/sda5
[root@teacher ~]# mount /dev/sda5 /mnt/sda5
实现开机自动挂载:
# vim /etc/fstab
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
***************************************************************************************************************
如何删除分区:
注意:先备份重要数据
1、删除fstab中对应的开机自动挂载记录
# vim /etc/fstab
2、卸载
# umount /dev/sda6
3、删除分区
[root@teacher ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-6): 6 --指定要删除的分区变号
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
4、通知内核重新读取分区表
[root@teacher ~]# partx -d --nr 6 /dev/sda
day102501
系统安装后的基本配置:
1、配置ip地址
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 --打开网卡配置文件
1 DEVICE=eth0 --网卡设备名称
2 HWADDR=00:0C:29:2B:47:94 --物理地址(MAC地址)
3 TYPE=Ethernet --网络类型(以太网)
4 UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4 --全球唯一标识符
5 ONBOOT=yes --是否开机自动激活
6 NM_CONTROLLED=no --是否受networkmanager的管理
7 BOOTPROTO=static
--获取ip地址的形式(dhcp动态、static静态、none不使用任何协议)
8 IPADDR=172.16.254.100 --ip地址
9 NETMASK=255.255.0.0 --子网掩码
[root@localhost ~]# service network restart --重启网络服务
[root@localhost ~]# ifconfig --查看网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:2B:47:94
inet addr:172.16.254.101 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe2b:4794/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13645 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1744909 (1.6 MiB) TX bytes:2056 (2.0 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11112 (10.8 KiB) TX bytes:11112 (10.8 KiB)
[root@localhost ~]# ping 172.16.254.101 --测试网络连通性
2、关闭selinux
永久关闭:
[root@localhost ~]# vim /etc/selinux/config --打开selinux配置文件
SELINUX=disabled --enforcing 强制开启
--permissive 警告,但不阻止
--disabled 关闭
[root@localhost ~]# sestatus --查看状态
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
[root@localhost ~]# reboot
[root@localhost ~]# sestatus --查看状态
SELinux status: disabled
临时关闭:
[root@localhost ~]# setenforce 0 (0:临时关闭,1:临时开启)
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
3、关闭防火墙(iptables)
[root@localhost ~]# iptables -L --查看状态
[root@localhost ~]# iptables -F --清空规则
[root@localhost ~]# iptables -L --再查看状态
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# service iptables stop --关闭iptables服务
[root@localhost ~]# chkconfig iptables off --开机不自动启动
4、设置主机名
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network --打开配置主机名的配置文件
NETWORKING=yes
HOSTNAME=teacher.uplooking.com
[root@localhost ~]# reboot --重启生效
临时修改
[root@localhost ~]# hostname teacher.uplooking.com
[root@localhost ~]# hostname
teacher.uplooking.com
作业:新建一个虚拟机,然后配置以上4步骤。
day102502
了解根目录下各个目录的作用:
见图片
文件查找:
locate --以文件名查找文件,基于数据库查找,是最快的查找方式
[root@teacher test]# touch ifcfg-eth0
[root@teacher test]# ls
ifcfg-eth0 passwd shadow
[root@teacher test]# locate ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@teacher test]# updatedb --更新数据库
数据库位置:
[root@teacher mlocate]# ls /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db
find --基于路径查找,比较慢,不用更新数据库
语法:find+路径+查找类型+参数
以文件名称查找:
[root@teacher test]# find / -name ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name "file*" --查找文件名称以file开头
/test/file1
/test/file2
/test/file5
/test/file4
/test/file3
[root@teacher test]# find / -name "*file*" --查找所有包含服了关键字的文件
以文件大小查找:(c、k、M、G)
[root@teacher test]# find /test -size +10k --查找大于10k大小
/test/install.log
[root@teacher test]# find /test -size 10k --查找等于10k大小
[root@teacher test]# find /test -size -10k --查找小于10k大小
以文件的类型查找:
root@teacher test]# find / -type f
-type支持的文件类型
f 普通文件
d 目录文件
l 软链接文件
s 套接字文件
p 管道文件
b 块设备文件
c 字符设备
[root@teacher test]# find /test -type d
[root@teacher test]# find /test -type f
[root@teacher test]# find /dev -type b
[root@teacher test]# find /bin -type l -ls
1179652 0 lrwxrwxrwx 1 root root 4 Oct 19 15:57 /bin/awk -> gawk
[root@teacher test]# find /var -type s
[root@teacher test]# find /var -type p -ls
通过文件的所有者查找文件:
[root@teacher test]# find /test -user mysql
综合运用:
[root@teacher test]# find /test -size +3k -type d
/test
/test/mydir
[root@teacher test]# find /test -size +3k -type f
/test/install.log
逻辑运算关系:
-and 并
# find /etc -size +50k -and -size -60k -and -type f
-o 或
# find /etc -size 1500k -o -size 0
-not 非(!)
# find /test -not -name "*.conf"
which: --查找命令文件所在路径
[root@teacher ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@teacher ~]# which pwd
/bin/pwd
[root@teacher ~]# which ifconfig
/sbin/ifconfig
[root@teacher ~]# which groupadd
/usr/sbin/groupadd
which去哪查找命令:
[root@teacher ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
[root@teacher ~]# which uplook
/usr/bin/which:no uplook in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
whereis:
--命令的绝对路径
--命令的帮助文件路径
--和命令同名的文件路径
[root@teacher ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@teacher ~]# man ls
[root@teacher ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
day102503
文件的打包与压缩:
windows下的打包压缩工具:winrar、360压缩、7zip、好压
压缩:有损压缩、无损压缩
压缩的好处:节省空间、用于网络传输、用于备份
linux下的压缩方式:
zip:
[root@teacher test]# zip /tmp/resolv.conf.zip resolv.conf --压缩单个文件
[root@teacher test]# less resolv.conf.zip --查看压缩包内容
[root@teacher test]# zip -r /tmp/test.zip /test --压缩整个目录
[root@teacher test]# unzip resolv.conf.zip -d /tmp --解压命令,d:代表解压到的路径
gzip:
[root@teacher test]# gzip ntp.conf --压缩单个文件,删除源文件
[root@teacher test]# less ntp.conf.gz --查看压缩文件内容
[root@teacher test]# zcat ntp.conf.gz --查看压缩文件内容
[root@teacher test]# gzip -r /test --压缩整个目录内的所有文件(不支持压缩整个目录)
[root@teacher test]# gunzip -r /test --解压目录内的所有文件
[root@teacher test]# gunzip ntp.conf.gz --解压单个文件
bzip2:
[root@teacher test]# bzip2 yum.conf --压缩单个文件,删除源文件
[root@teacher test]# less yum.conf.bz2 --查看文件内容
[root@teacher test]# bzcat yum.conf.bz2 --查看文件内容
[root@teacher test]# bunzip2 yum.conf.bz2 --解压单个文件
[root@teacher test]# bzip2 /test/* --压缩整个目录内的所有文件
[root@teacher test]# bunzip2 /test/* --解压整个目录内的所有压缩文件
作业:
1、安装一个虚拟机,然后设置ip地址、关闭iptables、关闭selinx、设置主机名
2、找出 /etc 底下,文件大小介于 50K 到 60K 之间的文件
3、找出 /etc 底下,文件大小大于 1500K 以及容量等于 0 的文件
4、找到yum命令的路径
5、找到ntp.conf文件的位置
6、拷贝/etc/inittab文件到/test目录下,分别用zip、gzip和bzip2命令进行压缩和解压实验
day102601
打包命令:
tar :实现打包和压缩
选项:
-c --create创建一个tar包
-x --解包
-v --显示创建过程
-f --指定包的名称
-t --查看包的内容
-C --指定解压路径
-z --将tar包压缩为.gz形式
-j --将tar包压缩为.bz2形式
# tar -cvf conf.tar sudo.conf yp.conf yum.conf --打包多个文件
# tar -tf conf.tar --查看包的内容
# tar -cvf /tmp/test.tar /test/ --打包整个目录
# tar -xvf /tmp/test.tar -C /usr/local/src/ --解包
# tar -zcvf /tmp/test.tar.gz /test --打包并压缩为gz形式
# tar -jcvf /tmp/test.tar.bz2 /test --打包并压缩为bz2形式
# tar -zxvf /tmp/test.tar.gz -C /usr/local/src/ --解压缩gz形式的tar包
# tar -jxvf /tmp/test.tar.bz2 -C /usr/local/src/ --解压缩bz2形式的tar包
远程拷贝命令:
从远程主机拷贝到本地
# scp 172.16.254.101:/root/kolourpaint-1.2.2_kde3.tar.bz2 /tmp
# scp 172.16.254.101:/root/notecase-1.9.8_slack.tar.gz /tmp
从本地拷贝到远程主机
# scp /root/kolourpaint-1.2.2_kde3.tar.bz2 172.16.23.23:/root
day102602
软件安装:
软件位置:1、系统光盘中。2、网络源
手动光盘的挂载:
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
[root@teacher Desktop]# mkdir /mnt/iso --建立挂载点
[root@teacher Desktop]# mount /dev/sr0 /mnt/iso --挂载光驱
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
如何卸载光盘:
[root@teacher ~]# umount /mnt/iso --umount+挂载点或设备路径
[root@teacher ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
软件包的命名格式:
httpd-2.2.15-26.el6.i686.rpm
软件包名-软件版本号-操作系统发行版-系统平台-扩展名
i686/i386 代表32位系统平台
x86_64 代表64位系统平台
noarch 代表32/64都支持
软件安装工具:rpm、yum
rpm --本地安装工具,不能解决依赖关系
-i --安装install
-v --显示安装过程
-h --是否显示#进度条
-e --卸载
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm --安装软件
# rpm -e vsftpd --卸载软件
# rpm -q unix2dos --查询软件是否安装
# rpm -qa --查看已经安装的包
# rpm -qa | wc -l --查看一共安装多少个软件
# rpm -qf /usr/bin/finger --查找一个命令由哪个软件包提供(注意:命令的绝对路径)
# rpm -qf `which finger` --嵌套执行命令
# rpm -ql httpd --查看一个软件产生了哪些文件
# rpm -ivh finger-0.17-39.el6.i686.rpm --force --覆盖安装
yum --Yellowdog Updater Modified --在线安装工具,可以解决依赖关系()
如何配置yum:
1、挂载光盘
# df -h | grep sr0
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
2、编辑yum的配置文件
# vim /etc/yum.repos.d/local.repo (文件名称必须以.repo结尾)
1 [base] --软件仓库的名称(即唯一标识符)
2 name=base --此软件仓库的描述信息,给管理员看的
3 baseurl=file:///mnt/iso --软件仓库路径
4 enabled=1 --是否启用此仓库
5 gpgcheck=0 --是否开启软件的数字签名认证
如何配置网络yum源:
9 [http]
10 name=http
11 baseurl=http://172.16.254.101/iso
12 enabled=1
13 gpgcheck=0
3、测试yum
# yum list
# yum clean all
利用yum安装软件包:
# yum install gcc -y --安装
# yum remove vsftpd --卸载
# yum search gcc --搜索所有包含gcc关键字的包名
# yum provides "*/finger" --查找一个命令由哪个软件包安装
利用yum安装软件包组:
# yum grouplist --查看软件包组
# yum groupinstall "Desktop" --安装软件包组
# yum groupremove "Desktop" --卸载软件包组
作业:1、安装一个最小化的虚拟机(不带图形)
2、配置ip地址、seliux、主机名、iptables、yum
3、安装图形
# startx 从文本终端切换到图形界面
总结yum:
挂载光盘(mount)---->编辑配置文件(.repo)---->测试yum list
day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root root 1578 Oct 23 15:08 passwd
# ls -ld /test --查看目录的属性
drwxr-xr-x. 2 root root 4096 Oct 24 19:41 /test
权限位,共9位
rw- r-- r--
所有者权限 所属组权限 其他人权限
权限的种类:
针对文件:
r --读权限
w --写权限
x --可执行权限
针对目录
r --读目录内的内容
w --是否可以在目录下创建、删除文件
x --是否可以进入此目录
修改文件的权限:
chmod --改变文件权限命令
语法:chmod [ugo][+-=][rwx] filename
等值修改:
[root@localhost test]# ls -l myfile
-rw-r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u=r myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod g=rw myfile
[root@localhost test]# ls -l myfile
-r--rw-r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o=rwx myfile
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
增值修改:
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+x myfile
[root@localhost test]# ls -l myfile
-r-xrw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+w,g+x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
减值修改:
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o-x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrw-. 1 root root 0 Oct 24 20:04 myfile
权限值(八进制数):
r 4
w 2
x 1
以权限值的形式分配权限:
[root@localhost test]# ls -l myfile
-rwx------. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 444 myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 755 myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 root root 0 Oct 24 20:04 myfile
修改文件的所有者和所属组:
chown
[root@localhost test]# chown oracle:oracle mysqlfile1
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle oracle 0 Oct 24 20:40 mysqlfile1
[root@localhost test]# chown mysql:oracle myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 mysql oracle 0 Oct 24 20:04 myfile
[root@localhost test]# chown oracle passwd --只改所有者
[root@localhost test]# ls -l passwd
-rw-r--r--. 1 oracle root 1578 Oct 23 15:08 passwd
[root@localhost test]# chown .mysql mysqlfile1 --只改所属组
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle mysql 0 Oct 24 20:40 mysqlfile1
day1027
补充小知识:
rhel6 包含一个图形终端和5个仿真终端
ctrl+alt+F(1~7) --各个仿真终端间切换
编译安装:也称源码安装
案例:安装MPlayer
1、解包
[root@teacher ~]# tar -zxvf MPlayer-1.1.1.tar.gz -C /usr/local/src/
[root@teacher MPlayer-1.1.1]# pwd
/usr/local/src/MPlayer-1.1.1
2、配置:(检测此软件安装需要哪些依赖的环境)
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer
--prefix:指定软件安装位置
[root@teacher MPlayer-1.1.1]# yum install gcc -y
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer --yasm=''
3、编译:
[root@teacher MPlayer-1.1.1]# make
4、安装:
[root@teacher MPlayer-1.1.1]# make install
加载声音模块:
[root@teacher Desktop]# modprobe snd_pcm_oss
播放歌曲:
[root@teacher bin]# pwd
/usr/local/mplayer/bin
[root@teacher bin]# ./mplayer /root/wuyuetian.mp3
day1028
linux系统的启动级别:
# vim /etc/inittab
0 - halt (Do NOT set initdefault to this) --关机
1 - Single user mode --单用户模式
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
--多用户模式文本模式,不支持nfs
3 - Full multiuser mode -- 多用户模式文本模式,支持nfs
4 - unused --未启用的模式
5 - X11 --图形终端
6 - reboot (Do NOT set initdefault to this) --重启
各个级别之间切换:
# init 0-6
如何修改模式启动级别:
# vim /etc/inittab
id:5:initdefault:
关机命令:
# shutdown -h now
# poweroff
# init 0
# halt
# shutdown -h 10 --指定10分钟后关机
# shutdown -c --取消关机命令
重启命令:
# reboot
# init 6
# shutdown -r
如何修改root密码:
到单用户模式下使用passwd命令修改
*****************************************************************************
光盘的挂载:
mount
1、建立挂载点
2、挂载mount
3、查看挂载信息
# df -h
# mount
如何实现开机自动挂载光盘:
1、挂载光驱内的光盘
# vim /etc/fstab --存储开机自动挂载设备信息# man 5 fstab
/dev/sr0 /mnt/iso iso9660 defaults,loop 0 0
设备名称 挂载点 文件系统类型 默认选项 是否备份数据 磁盘检查顺序
# mount -a --读取/etc/fstab中未挂载的设备挂载
2、挂载系统镜像iso文件
# dd if=/dev/sr0 of=/root/rhel6u4i386.iso --将光驱中的iso文件备份到本地
--if源文件
--of目标文件
临时挂载:
# mount -o loop /mnt/winD/iso/rhel-server-6.4-i386-dvd.iso /mnt/iso
(loop表示回环挂载)
开机自动挂载
# vim /etc/fstab
/root/rhel6u4i386.iso /mnt/iso iso9660 defaults,loop 0 0
(loop表示回环挂载)
day1029
访问屏幕广播地址:vncviewer 172.16.254.100 -->密码redhat
访问笔记地址firefox http://172.16.254.100/day1029.txt &
分区开机自动挂载
临时挂载windows分区:
# mount -t ntfs /dev/sda2 /mnt/winD
永久挂载windows分区:
# vim /etc/fstab
/dev/sda2 /mnt/winD ntfs defaults 0 0
总结: 分区fdisk---->通知内核读取分区表partx--->创建文件系统mkfs---->挂载使用mount---->开机自动挂载/etc/fstab
linux下的磁盘管理:
查看分区信息:
# fdisk -l
如何分区:
# fdisk /dev/sda
n --添加分区
p --打印分区表信息
d --删除一个分区
q --退出不保存
w --保存并退出
案例1:划分扩展分区:
[root@teacher ~]# fdisk /dev/sda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e --指定分区类型为扩展分区
Selected partition 4
First cylinder (5509-26108, default 5509): --分区的起始位置
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108):
--指定分区的结束为止
Using default value 26108
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
案例2:添加一个20G大小的分区
Command (m for help): n
First cylinder (5509-26108, default 5509):
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108): +20G --设置分区大小为20G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
通知内核重新读取分区
[root@teacher ~]# partx -a /dev/sda
[root@teacher ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
创建文件系统:
[root@teacher ~]# mkfs.ext4 /dev/sda5 --格式化sda5分区为ext4文件系统
或
[root@teacher ~]# mkfs -t ext4 /dev/sda5
挂载硬盘
[root@teacher ~]# mkdir /mnt/sda5
[root@teacher ~]# mount /dev/sda5 /mnt/sda5
实现开机自动挂载:
# vim /etc/fstab
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
***************************************************************************************************************
如何删除分区:
注意:先备份重要数据
1、删除fstab中对应的开机自动挂载记录
# vim /etc/fstab
2、卸载
# umount /dev/sda6
3、删除分区
[root@teacher ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-6): 6 --指定要删除的分区变号
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
4、通知内核重新读取分区表
[root@teacher ~]# partx -d --nr 6 /dev/sda
day102501
系统安装后的基本配置:
1、配置ip地址
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 --打开网卡配置文件
1 DEVICE=eth0 --网卡设备名称
2 HWADDR=00:0C:29:2B:47:94 --物理地址(MAC地址)
3 TYPE=Ethernet --网络类型(以太网)
4 UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4 --全球唯一标识符
5 ONBOOT=yes --是否开机自动激活
6 NM_CONTROLLED=no --是否受networkmanager的管理
7 BOOTPROTO=static
--获取ip地址的形式(dhcp动态、static静态、none不使用任何协议)
8 IPADDR=172.16.254.100 --ip地址
9 NETMASK=255.255.0.0 --子网掩码
[root@localhost ~]# service network restart --重启网络服务
[root@localhost ~]# ifconfig --查看网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:2B:47:94
inet addr:172.16.254.101 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe2b:4794/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13645 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1744909 (1.6 MiB) TX bytes:2056 (2.0 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11112 (10.8 KiB) TX bytes:11112 (10.8 KiB)
[root@localhost ~]# ping 172.16.254.101 --测试网络连通性
2、关闭selinux
永久关闭:
[root@localhost ~]# vim /etc/selinux/config --打开selinux配置文件
SELINUX=disabled --enforcing 强制开启
--permissive 警告,但不阻止
--disabled 关闭
[root@localhost ~]# sestatus --查看状态
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
[root@localhost ~]# reboot
[root@localhost ~]# sestatus --查看状态
SELinux status: disabled
临时关闭:
[root@localhost ~]# setenforce 0 (0:临时关闭,1:临时开启)
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
3、关闭防火墙(iptables)
[root@localhost ~]# iptables -L --查看状态
[root@localhost ~]# iptables -F --清空规则
[root@localhost ~]# iptables -L --再查看状态
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# service iptables stop --关闭iptables服务
[root@localhost ~]# chkconfig iptables off --开机不自动启动
4、设置主机名
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network --打开配置主机名的配置文件
NETWORKING=yes
HOSTNAME=teacher.uplooking.com
[root@localhost ~]# reboot --重启生效
临时修改
[root@localhost ~]# hostname teacher.uplooking.com
[root@localhost ~]# hostname
teacher.uplooking.com
作业:新建一个虚拟机,然后配置以上4步骤。
day102502
了解根目录下各个目录的作用:
见图片
文件查找:
locate --以文件名查找文件,基于数据库查找,是最快的查找方式
[root@teacher test]# touch ifcfg-eth0
[root@teacher test]# ls
ifcfg-eth0 passwd shadow
[root@teacher test]# locate ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@teacher test]# updatedb --更新数据库
数据库位置:
[root@teacher mlocate]# ls /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db
find --基于路径查找,比较慢,不用更新数据库
语法:find+路径+查找类型+参数
以文件名称查找:
[root@teacher test]# find / -name ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name "file*" --查找文件名称以file开头
/test/file1
/test/file2
/test/file5
/test/file4
/test/file3
[root@teacher test]# find / -name "*file*" --查找所有包含服了关键字的文件
以文件大小查找:(c、k、M、G)
[root@teacher test]# find /test -size +10k --查找大于10k大小
/test/install.log
[root@teacher test]# find /test -size 10k --查找等于10k大小
[root@teacher test]# find /test -size -10k --查找小于10k大小
以文件的类型查找:
root@teacher test]# find / -type f
-type支持的文件类型
f 普通文件
d 目录文件
l 软链接文件
s 套接字文件
p 管道文件
b 块设备文件
c 字符设备
[root@teacher test]# find /test -type d
[root@teacher test]# find /test -type f
[root@teacher test]# find /dev -type b
[root@teacher test]# find /bin -type l -ls
1179652 0 lrwxrwxrwx 1 root root 4 Oct 19 15:57 /bin/awk -> gawk
[root@teacher test]# find /var -type s
[root@teacher test]# find /var -type p -ls
通过文件的所有者查找文件:
[root@teacher test]# find /test -user mysql
综合运用:
[root@teacher test]# find /test -size +3k -type d
/test
/test/mydir
[root@teacher test]# find /test -size +3k -type f
/test/install.log
逻辑运算关系:
-and 并
# find /etc -size +50k -and -size -60k -and -type f
-o 或
# find /etc -size 1500k -o -size 0
-not 非(!)
# find /test -not -name "*.conf"
which: --查找命令文件所在路径
[root@teacher ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@teacher ~]# which pwd
/bin/pwd
[root@teacher ~]# which ifconfig
/sbin/ifconfig
[root@teacher ~]# which groupadd
/usr/sbin/groupadd
which去哪查找命令:
[root@teacher ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
[root@teacher ~]# which uplook
/usr/bin/which:no uplook in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
whereis:
--命令的绝对路径
--命令的帮助文件路径
--和命令同名的文件路径
[root@teacher ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@teacher ~]# man ls
[root@teacher ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
day102503
文件的打包与压缩:
windows下的打包压缩工具:winrar、360压缩、7zip、好压
压缩:有损压缩、无损压缩
压缩的好处:节省空间、用于网络传输、用于备份
linux下的压缩方式:
zip:
[root@teacher test]# zip /tmp/resolv.conf.zip resolv.conf --压缩单个文件
[root@teacher test]# less resolv.conf.zip --查看压缩包内容
[root@teacher test]# zip -r /tmp/test.zip /test --压缩整个目录
[root@teacher test]# unzip resolv.conf.zip -d /tmp --解压命令,d:代表解压到的路径
gzip:
[root@teacher test]# gzip ntp.conf --压缩单个文件,删除源文件
[root@teacher test]# less ntp.conf.gz --查看压缩文件内容
[root@teacher test]# zcat ntp.conf.gz --查看压缩文件内容
[root@teacher test]# gzip -r /test --压缩整个目录内的所有文件(不支持压缩整个目录)
[root@teacher test]# gunzip -r /test --解压目录内的所有文件
[root@teacher test]# gunzip ntp.conf.gz --解压单个文件
bzip2:
[root@teacher test]# bzip2 yum.conf --压缩单个文件,删除源文件
[root@teacher test]# less yum.conf.bz2 --查看文件内容
[root@teacher test]# bzcat yum.conf.bz2 --查看文件内容
[root@teacher test]# bunzip2 yum.conf.bz2 --解压单个文件
[root@teacher test]# bzip2 /test/* --压缩整个目录内的所有文件
[root@teacher test]# bunzip2 /test/* --解压整个目录内的所有压缩文件
作业:
1、安装一个虚拟机,然后设置ip地址、关闭iptables、关闭selinx、设置主机名
2、找出 /etc 底下,文件大小介于 50K 到 60K 之间的文件
3、找出 /etc 底下,文件大小大于 1500K 以及容量等于 0 的文件
4、找到yum命令的路径
5、找到ntp.conf文件的位置
6、拷贝/etc/inittab文件到/test目录下,分别用zip、gzip和bzip2命令进行压缩和解压实验
day102601
打包命令:
tar :实现打包和压缩
选项:
-c --create创建一个tar包
-x --解包
-v --显示创建过程
-f --指定包的名称
-t --查看包的内容
-C --指定解压路径
-z --将tar包压缩为.gz形式
-j --将tar包压缩为.bz2形式
# tar -cvf conf.tar sudo.conf yp.conf yum.conf --打包多个文件
# tar -tf conf.tar --查看包的内容
# tar -cvf /tmp/test.tar /test/ --打包整个目录
# tar -xvf /tmp/test.tar -C /usr/local/src/ --解包
# tar -zcvf /tmp/test.tar.gz /test --打包并压缩为gz形式
# tar -jcvf /tmp/test.tar.bz2 /test --打包并压缩为bz2形式
# tar -zxvf /tmp/test.tar.gz -C /usr/local/src/ --解压缩gz形式的tar包
# tar -jxvf /tmp/test.tar.bz2 -C /usr/local/src/ --解压缩bz2形式的tar包
远程拷贝命令:
从远程主机拷贝到本地
# scp 172.16.254.101:/root/kolourpaint-1.2.2_kde3.tar.bz2 /tmp
# scp 172.16.254.101:/root/notecase-1.9.8_slack.tar.gz /tmp
从本地拷贝到远程主机
# scp /root/kolourpaint-1.2.2_kde3.tar.bz2 172.16.23.23:/root
day102602
软件安装:
软件位置:1、系统光盘中。2、网络源
手动光盘的挂载:
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
[root@teacher Desktop]# mkdir /mnt/iso --建立挂载点
[root@teacher Desktop]# mount /dev/sr0 /mnt/iso --挂载光驱
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
如何卸载光盘:
[root@teacher ~]# umount /mnt/iso --umount+挂载点或设备路径
[root@teacher ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
软件包的命名格式:
httpd-2.2.15-26.el6.i686.rpm
软件包名-软件版本号-操作系统发行版-系统平台-扩展名
i686/i386 代表32位系统平台
x86_64 代表64位系统平台
noarch 代表32/64都支持
软件安装工具:rpm、yum
rpm --本地安装工具,不能解决依赖关系
-i --安装install
-v --显示安装过程
-h --是否显示#进度条
-e --卸载
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm --安装软件
# rpm -e vsftpd --卸载软件
# rpm -q unix2dos --查询软件是否安装
# rpm -qa --查看已经安装的包
# rpm -qa | wc -l --查看一共安装多少个软件
# rpm -qf /usr/bin/finger --查找一个命令由哪个软件包提供(注意:命令的绝对路径)
# rpm -qf `which finger` --嵌套执行命令
# rpm -ql httpd --查看一个软件产生了哪些文件
# rpm -ivh finger-0.17-39.el6.i686.rpm --force --覆盖安装
yum --Yellowdog Updater Modified --在线安装工具,可以解决依赖关系()
如何配置yum:
1、挂载光盘
# df -h | grep sr0
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
2、编辑yum的配置文件
# vim /etc/yum.repos.d/local.repo (文件名称必须以.repo结尾)
1 [base] --软件仓库的名称(即唯一标识符)
2 name=base --此软件仓库的描述信息,给管理员看的
3 baseurl=file:///mnt/iso --软件仓库路径
4 enabled=1 --是否启用此仓库
5 gpgcheck=0 --是否开启软件的数字签名认证
如何配置网络yum源:
9 [http]
10 name=http
11 baseurl=http://172.16.254.101/iso
12 enabled=1
13 gpgcheck=0
3、测试yum
# yum list
# yum clean all
利用yum安装软件包:
# yum install gcc -y --安装
# yum remove vsftpd --卸载
# yum search gcc --搜索所有包含gcc关键字的包名
# yum provides "*/finger" --查找一个命令由哪个软件包安装
利用yum安装软件包组:
# yum grouplist --查看软件包组
# yum groupinstall "Desktop" --安装软件包组
# yum groupremove "Desktop" --卸载软件包组
作业:1、安装一个最小化的虚拟机(不带图形)
2、配置ip地址、seliux、主机名、iptables、yum
3、安装图形
# startx 从文本终端切换到图形界面
总结yum:
挂载光盘(mount)---->编辑配置文件(.repo)---->测试yum list
day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root root 1578 Oct 23 15:08 passwd
# ls -ld /test --查看目录的属性
drwxr-xr-x. 2 root root 4096 Oct 24 19:41 /test
权限位,共9位
rw- r-- r--
所有者权限 所属组权限 其他人权限
权限的种类:
针对文件:
r --读权限
w --写权限
x --可执行权限
针对目录
r --读目录内的内容
w --是否可以在目录下创建、删除文件
x --是否可以进入此目录
修改文件的权限:
chmod --改变文件权限命令
语法:chmod [ugo][+-=][rwx] filename
等值修改:
[root@localhost test]# ls -l myfile
-rw-r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u=r myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod g=rw myfile
[root@localhost test]# ls -l myfile
-r--rw-r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o=rwx myfile
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
增值修改:
[root@localhost test]# ls -l myfile
-r--rw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+x myfile
[root@localhost test]# ls -l myfile
-r-xrw-rwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod u+w,g+x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
减值修改:
[root@localhost test]# ls -l myfile
-rwxrwxrwx. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod o-x myfile
[root@localhost test]# ls -l myfile
-rwxrwxrw-. 1 root root 0 Oct 24 20:04 myfile
权限值(八进制数):
r 4
w 2
x 1
以权限值的形式分配权限:
[root@localhost test]# ls -l myfile
-rwx------. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 444 myfile
[root@localhost test]# ls -l myfile
-r--r--r--. 1 root root 0 Oct 24 20:04 myfile
[root@localhost test]# chmod 755 myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 root root 0 Oct 24 20:04 myfile
修改文件的所有者和所属组:
chown
[root@localhost test]# chown oracle:oracle mysqlfile1
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle oracle 0 Oct 24 20:40 mysqlfile1
[root@localhost test]# chown mysql:oracle myfile
[root@localhost test]# ls -l myfile
-rwxr-xr-x. 1 mysql oracle 0 Oct 24 20:04 myfile
[root@localhost test]# chown oracle passwd --只改所有者
[root@localhost test]# ls -l passwd
-rw-r--r--. 1 oracle root 1578 Oct 23 15:08 passwd
[root@localhost test]# chown .mysql mysqlfile1 --只改所属组
[root@localhost test]# ls -l mysqlfile1
-rw-rw-r--. 1 oracle mysql 0 Oct 24 20:40 mysqlfile1
day1027
补充小知识:
rhel6 包含一个图形终端和5个仿真终端
ctrl+alt+F(1~7) --各个仿真终端间切换
编译安装:也称源码安装
案例:安装MPlayer
1、解包
[root@teacher ~]# tar -zxvf MPlayer-1.1.1.tar.gz -C /usr/local/src/
[root@teacher MPlayer-1.1.1]# pwd
/usr/local/src/MPlayer-1.1.1
2、配置:(检测此软件安装需要哪些依赖的环境)
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer
--prefix:指定软件安装位置
[root@teacher MPlayer-1.1.1]# yum install gcc -y
[root@teacher MPlayer-1.1.1]# ./configure --prefix=/usr/local/mplayer --yasm=''
3、编译:
[root@teacher MPlayer-1.1.1]# make
4、安装:
[root@teacher MPlayer-1.1.1]# make install
加载声音模块:
[root@teacher Desktop]# modprobe snd_pcm_oss
播放歌曲:
[root@teacher bin]# pwd
/usr/local/mplayer/bin
[root@teacher bin]# ./mplayer /root/wuyuetian.mp3
day1028
linux系统的启动级别:
# vim /etc/inittab
0 - halt (Do NOT set initdefault to this) --关机
1 - Single user mode --单用户模式
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
--多用户模式文本模式,不支持nfs
3 - Full multiuser mode -- 多用户模式文本模式,支持nfs
4 - unused --未启用的模式
5 - X11 --图形终端
6 - reboot (Do NOT set initdefault to this) --重启
各个级别之间切换:
# init 0-6
如何修改模式启动级别:
# vim /etc/inittab
id:5:initdefault:
关机命令:
# shutdown -h now
# poweroff
# init 0
# halt
# shutdown -h 10 --指定10分钟后关机
# shutdown -c --取消关机命令
重启命令:
# reboot
# init 6
# shutdown -r
如何修改root密码:
到单用户模式下使用passwd命令修改
*****************************************************************************
光盘的挂载:
mount
1、建立挂载点
2、挂载mount
3、查看挂载信息
# df -h
# mount
如何实现开机自动挂载光盘:
1、挂载光驱内的光盘
# vim /etc/fstab --存储开机自动挂载设备信息# man 5 fstab
/dev/sr0 /mnt/iso iso9660 defaults,loop 0 0
设备名称 挂载点 文件系统类型 默认选项 是否备份数据 磁盘检查顺序
# mount -a --读取/etc/fstab中未挂载的设备挂载
2、挂载系统镜像iso文件
# dd if=/dev/sr0 of=/root/rhel6u4i386.iso --将光驱中的iso文件备份到本地
--if源文件
--of目标文件
临时挂载:
# mount -o loop /mnt/winD/iso/rhel-server-6.4-i386-dvd.iso /mnt/iso
(loop表示回环挂载)
开机自动挂载
# vim /etc/fstab
/root/rhel6u4i386.iso /mnt/iso iso9660 defaults,loop 0 0
(loop表示回环挂载)
day1029
访问屏幕广播地址:vncviewer 172.16.254.100 -->密码redhat
访问笔记地址firefox http://172.16.254.100/day1029.txt &
分区开机自动挂载
临时挂载windows分区:
# mount -t ntfs /dev/sda2 /mnt/winD
永久挂载windows分区:
# vim /etc/fstab
/dev/sda2 /mnt/winD ntfs defaults 0 0
总结: 分区fdisk---->通知内核读取分区表partx--->创建文件系统mkfs---->挂载使用mount---->开机自动挂载/etc/fstab
linux下的磁盘管理:
查看分区信息:
# fdisk -l
如何分区:
# fdisk /dev/sda
n --添加分区
p --打印分区表信息
d --删除一个分区
q --退出不保存
w --保存并退出
案例1:划分扩展分区:
[root@teacher ~]# fdisk /dev/sda
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e --指定分区类型为扩展分区
Selected partition 4
First cylinder (5509-26108, default 5509): --分区的起始位置
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108):
--指定分区的结束为止
Using default value 26108
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
案例2:添加一个20G大小的分区
Command (m for help): n
First cylinder (5509-26108, default 5509):
Using default value 5509
Last cylinder, +cylinders or +size{K,M,G} (5509-26108, default 26108): +20G --设置分区大小为20G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
通知内核重新读取分区
[root@teacher ~]# partx -a /dev/sda
[root@teacher ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
创建文件系统:
[root@teacher ~]# mkfs.ext4 /dev/sda5 --格式化sda5分区为ext4文件系统
或
[root@teacher ~]# mkfs -t ext4 /dev/sda5
挂载硬盘
[root@teacher ~]# mkdir /mnt/sda5
[root@teacher ~]# mount /dev/sda5 /mnt/sda5
实现开机自动挂载:
# vim /etc/fstab
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
***************************************************************************************************************
如何删除分区:
注意:先备份重要数据
1、删除fstab中对应的开机自动挂载记录
# vim /etc/fstab
2、卸载
# umount /dev/sda6
3、删除分区
[root@teacher ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-6): 6 --指定要删除的分区变号
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
/dev/sda4 5509 26108 165466494 5 Extended
/dev/sda5 5509 8120 20977852+ 83 Linux
Command (m for help): w
4、通知内核重新读取分区表
[root@teacher ~]# partx -d --nr 6 /dev/sda
day102501
系统安装后的基本配置:
1、配置ip地址
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 --打开网卡配置文件
1 DEVICE=eth0 --网卡设备名称
2 HWADDR=00:0C:29:2B:47:94 --物理地址(MAC地址)
3 TYPE=Ethernet --网络类型(以太网)
4 UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4 --全球唯一标识符
5 ONBOOT=yes --是否开机自动激活
6 NM_CONTROLLED=no --是否受networkmanager的管理
7 BOOTPROTO=static
--获取ip地址的形式(dhcp动态、static静态、none不使用任何协议)
8 IPADDR=172.16.254.100 --ip地址
9 NETMASK=255.255.0.0 --子网掩码
[root@localhost ~]# service network restart --重启网络服务
[root@localhost ~]# ifconfig --查看网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:2B:47:94
inet addr:172.16.254.101 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe2b:4794/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13645 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1744909 (1.6 MiB) TX bytes:2056 (2.0 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11112 (10.8 KiB) TX bytes:11112 (10.8 KiB)
[root@localhost ~]# ping 172.16.254.101 --测试网络连通性
2、关闭selinux
永久关闭:
[root@localhost ~]# vim /etc/selinux/config --打开selinux配置文件
SELINUX=disabled --enforcing 强制开启
--permissive 警告,但不阻止
--disabled 关闭
[root@localhost ~]# sestatus --查看状态
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
[root@localhost ~]# reboot
[root@localhost ~]# sestatus --查看状态
SELinux status: disabled
临时关闭:
[root@localhost ~]# setenforce 0 (0:临时关闭,1:临时开启)
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
3、关闭防火墙(iptables)
[root@localhost ~]# iptables -L --查看状态
[root@localhost ~]# iptables -F --清空规则
[root@localhost ~]# iptables -L --再查看状态
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# service iptables stop --关闭iptables服务
[root@localhost ~]# chkconfig iptables off --开机不自动启动
4、设置主机名
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network --打开配置主机名的配置文件
NETWORKING=yes
HOSTNAME=teacher.uplooking.com
[root@localhost ~]# reboot --重启生效
临时修改
[root@localhost ~]# hostname teacher.uplooking.com
[root@localhost ~]# hostname
teacher.uplooking.com
作业:新建一个虚拟机,然后配置以上4步骤。
day102502
了解根目录下各个目录的作用:
见图片
文件查找:
locate --以文件名查找文件,基于数据库查找,是最快的查找方式
[root@teacher test]# touch ifcfg-eth0
[root@teacher test]# ls
ifcfg-eth0 passwd shadow
[root@teacher test]# locate ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@teacher test]# updatedb --更新数据库
数据库位置:
[root@teacher mlocate]# ls /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db
find --基于路径查找,比较慢,不用更新数据库
语法:find+路径+查找类型+参数
以文件名称查找:
[root@teacher test]# find / -name ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name ifcfg-eth0
/test/ifcfg-eth0
[root@teacher test]# find /test -name "file*" --查找文件名称以file开头
/test/file1
/test/file2
/test/file5
/test/file4
/test/file3
[root@teacher test]# find / -name "*file*" --查找所有包含服了关键字的文件
以文件大小查找:(c、k、M、G)
[root@teacher test]# find /test -size +10k --查找大于10k大小
/test/install.log
[root@teacher test]# find /test -size 10k --查找等于10k大小
[root@teacher test]# find /test -size -10k --查找小于10k大小
以文件的类型查找:
root@teacher test]# find / -type f
-type支持的文件类型
f 普通文件
d 目录文件
l 软链接文件
s 套接字文件
p 管道文件
b 块设备文件
c 字符设备
[root@teacher test]# find /test -type d
[root@teacher test]# find /test -type f
[root@teacher test]# find /dev -type b
[root@teacher test]# find /bin -type l -ls
1179652 0 lrwxrwxrwx 1 root root 4 Oct 19 15:57 /bin/awk -> gawk
[root@teacher test]# find /var -type s
[root@teacher test]# find /var -type p -ls
通过文件的所有者查找文件:
[root@teacher test]# find /test -user mysql
综合运用:
[root@teacher test]# find /test -size +3k -type d
/test
/test/mydir
[root@teacher test]# find /test -size +3k -type f
/test/install.log
逻辑运算关系:
-and 并
# find /etc -size +50k -and -size -60k -and -type f
-o 或
# find /etc -size 1500k -o -size 0
-not 非(!)
# find /test -not -name "*.conf"
which: --查找命令文件所在路径
[root@teacher ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@teacher ~]# which pwd
/bin/pwd
[root@teacher ~]# which ifconfig
/sbin/ifconfig
[root@teacher ~]# which groupadd
/usr/sbin/groupadd
which去哪查找命令:
[root@teacher ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
[root@teacher ~]# which uplook
/usr/bin/which:no uplook in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
whereis:
--命令的绝对路径
--命令的帮助文件路径
--和命令同名的文件路径
[root@teacher ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@teacher ~]# man ls
[root@teacher ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
day102503
文件的打包与压缩:
windows下的打包压缩工具:winrar、360压缩、7zip、好压
压缩:有损压缩、无损压缩
压缩的好处:节省空间、用于网络传输、用于备份
linux下的压缩方式:
zip:
[root@teacher test]# zip /tmp/resolv.conf.zip resolv.conf --压缩单个文件
[root@teacher test]# less resolv.conf.zip --查看压缩包内容
[root@teacher test]# zip -r /tmp/test.zip /test --压缩整个目录
[root@teacher test]# unzip resolv.conf.zip -d /tmp --解压命令,d:代表解压到的路径
gzip:
[root@teacher test]# gzip ntp.conf --压缩单个文件,删除源文件
[root@teacher test]# less ntp.conf.gz --查看压缩文件内容
[root@teacher test]# zcat ntp.conf.gz --查看压缩文件内容
[root@teacher test]# gzip -r /test --压缩整个目录内的所有文件(不支持压缩整个目录)
[root@teacher test]# gunzip -r /test --解压目录内的所有文件
[root@teacher test]# gunzip ntp.conf.gz --解压单个文件
bzip2:
[root@teacher test]# bzip2 yum.conf --压缩单个文件,删除源文件
[root@teacher test]# less yum.conf.bz2 --查看文件内容
[root@teacher test]# bzcat yum.conf.bz2 --查看文件内容
[root@teacher test]# bunzip2 yum.conf.bz2 --解压单个文件
[root@teacher test]# bzip2 /test/* --压缩整个目录内的所有文件
[root@teacher test]# bunzip2 /test/* --解压整个目录内的所有压缩文件
作业:
1、安装一个虚拟机,然后设置ip地址、关闭iptables、关闭selinx、设置主机名
2、找出 /etc 底下,文件大小介于 50K 到 60K 之间的文件
3、找出 /etc 底下,文件大小大于 1500K 以及容量等于 0 的文件
4、找到yum命令的路径
5、找到ntp.conf文件的位置
6、拷贝/etc/inittab文件到/test目录下,分别用zip、gzip和bzip2命令进行压缩和解压实验
day102601
打包命令:
tar :实现打包和压缩
选项:
-c --create创建一个tar包
-x --解包
-v --显示创建过程
-f --指定包的名称
-t --查看包的内容
-C --指定解压路径
-z --将tar包压缩为.gz形式
-j --将tar包压缩为.bz2形式
# tar -cvf conf.tar sudo.conf yp.conf yum.conf --打包多个文件
# tar -tf conf.tar --查看包的内容
# tar -cvf /tmp/test.tar /test/ --打包整个目录
# tar -xvf /tmp/test.tar -C /usr/local/src/ --解包
# tar -zcvf /tmp/test.tar.gz /test --打包并压缩为gz形式
# tar -jcvf /tmp/test.tar.bz2 /test --打包并压缩为bz2形式
# tar -zxvf /tmp/test.tar.gz -C /usr/local/src/ --解压缩gz形式的tar包
# tar -jxvf /tmp/test.tar.bz2 -C /usr/local/src/ --解压缩bz2形式的tar包
远程拷贝命令:
从远程主机拷贝到本地
# scp 172.16.254.101:/root/kolourpaint-1.2.2_kde3.tar.bz2 /tmp
# scp 172.16.254.101:/root/notecase-1.9.8_slack.tar.gz /tmp
从本地拷贝到远程主机
# scp /root/kolourpaint-1.2.2_kde3.tar.bz2 172.16.23.23:/root
day102602
软件安装:
软件位置:1、系统光盘中。2、网络源
手动光盘的挂载:
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
[root@teacher Desktop]# mkdir /mnt/iso --建立挂载点
[root@teacher Desktop]# mount /dev/sr0 /mnt/iso --挂载光驱
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@teacher Desktop]# df -h --查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
如何卸载光盘:
[root@teacher ~]# umount /mnt/iso --umount+挂载点或设备路径
[root@teacher ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 40G 3.0G 35G 8% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sr0 3.0G 3.0G 0 100% /media/RHEL_6.4 i386 Disc 1
软件包的命名格式:
httpd-2.2.15-26.el6.i686.rpm
软件包名-软件版本号-操作系统发行版-系统平台-扩展名
i686/i386 代表32位系统平台
x86_64 代表64位系统平台
noarch 代表32/64都支持
软件安装工具:rpm、yum
rpm --本地安装工具,不能解决依赖关系
-i --安装install
-v --显示安装过程
-h --是否显示#进度条
-e --卸载
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm --安装软件
# rpm -e vsftpd --卸载软件
# rpm -q unix2dos --查询软件是否安装
# rpm -qa --查看已经安装的包
# rpm -qa | wc -l --查看一共安装多少个软件
# rpm -qf /usr/bin/finger --查找一个命令由哪个软件包提供(注意:命令的绝对路径)
# rpm -qf `which finger` --嵌套执行命令
# rpm -ql httpd --查看一个软件产生了哪些文件
# rpm -ivh finger-0.17-39.el6.i686.rpm --force --覆盖安装
yum --Yellowdog Updater Modified --在线安装工具,可以解决依赖关系()
如何配置yum:
1、挂载光盘
# df -h | grep sr0
/dev/sr0 3.0G 3.0G 0 100% /mnt/iso
2、编辑yum的配置文件
# vim /etc/yum.repos.d/local.repo (文件名称必须以.repo结尾)
1 [base] --软件仓库的名称(即唯一标识符)
2 name=base --此软件仓库的描述信息,给管理员看的
3 baseurl=file:///mnt/iso --软件仓库路径
4 enabled=1 --是否启用此仓库
5 gpgcheck=0 --是否开启软件的数字签名认证
如何配置网络yum源:
9 [http]
10 name=http
11 baseurl=http://172.16.254.101/iso
12 enabled=1
13 gpgcheck=0
3、测试yum
# yum list
# yum clean all
利用yum安装软件包:
# yum install gcc -y --安装
# yum remove vsftpd --卸载
# yum search gcc --搜索所有包含gcc关键字的包名
# yum provides "*/finger" --查找一个命令由哪个软件包安装
利用yum安装软件包组:
# yum grouplist --查看软件包组
# yum groupinstall "Desktop" --安装软件包组
# yum groupremove "Desktop" --卸载软件包组
作业:1、安装一个最小化的虚拟机(不带图形)
2、配置ip地址、seliux、主机名、iptables、yum
3、安装图形
# startx 从文本终端切换到图形界面
总结yum:
挂载光盘(mount)---->编辑配置文件(.repo)---->测试yum list
day1019
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report ls translation bugs to
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
练习:
1.新建组g1、g2和g3
2.更改组g1的gid为2014,更改组名为group1
3.删除组g2
4.新建用户user2014,指定uid为777,主组为group1,附属主为g3
5.更改用户user2014的密码为uplooking
6.使用man,查看如何使用passwd命令锁定用户,并锁定user2014,测试是否可以登录系统
day1024
unix/linux系统的特点:
linux系统是类unix系统
UNIX设计哲学
KEEP IT SIMPLE , STUPID !
UNIX 系统的主要原则
1. 没有信息就是好事
2. 一切都是文件:包括内核中的配置等
3. 配置信息以文本形式保存
4. 避免不必要的用户交互,以参数来完成信息传递
5. 组合短小的程序完成复杂任务 (少总比多好)
基本权限的管理:
# ls -l passwd --查看文件的属性
-rw-r--r--. 1 root&