这几堂课没有听 ,把同学的笔记拿过来看看
ULE(linux基础)
alt+ctrl+左右工作区切换
1.关闭防火墙
[root@localhost ~]# iptables -F
[root@localhost ~]# service iptables save
2.关闭selinux
[root@localhost ~]# setenforce 0
[root@localhost ~]# gedit/etc/selinux/config
SELINUX=disabled
连接教师机
查看笔记
浏览器ftp://172.16.140.1
下载笔记
位置--->连接服务器--->172.16.140.1
远程桌面
[root@localhost ~]# vncviewer 172.16.140.1
-----------------------------------------------------
[root@localhost 桌面]#
用户@主机名 当前位置 #(管理员提示符号)
命令组成
命令 【参数】.... 【file】.....
[]可选项 ....可以一个或者多个
[root@localhost ~]# ls 【-l】 【install.log】
[root@localhost ~]# ls -l install.log
-#rw-r--r--#.# 1# root# root# 66263# 3月 212015# install.log
文件类型#基本权限#是否在开启selinux情况下创建#硬链接数#文件拥有者#文件所属组#大小#最后一次修改时间#文件名
文件类型(7种)
- 普通文件 file
d 目录文件 directory
l 符号链接文件 symbolic
b 块设备文件 block
c 字符设备文件 charset
p 管道文件 pipe
s 套接字文件 socket
ls -l 长格式 -a 显示隐藏文件 -d 显示目录本身信息 -h 按最大单位显示 -R 递归
帮助命令
1.ls --help
2.info ls
3.type
type cd
cd is a shell builtin 内部命令
type passwd
passwd is /usr/bin/passwd 外部命令
type ls
ls is aliased to `ls --color=auto' 别名
制作别名
alias la='ls -al'
unalias la
别名>外部>内部
4.man ls
man 1 用户命令
man 2 系统调用
man 3 库调用
man 4 特殊文件
man 5 配置文件
man 6 游戏
man 7 杂项
man 8 系统命令
man -f passwd 查询关于passwd的章节
man -k passwd | grep --color passwd 模糊查询
-------------------------------
pwd 当前路径
cd cd 回家目录 cd ~回家目录 cd . cd .. 上层目录
cd ../.. 上层的上层
目录结构
/bin/ /usr/bin/ /usr/local/bin/ 用户可执行目录
/sbin/ /usr/sbin/ /usr/local/sbin/ 系统可执行目录
/lib/ /usr/lib/ /usr/local/lib/ 库文件目录
/lib64/ /usr/lib64/ /usr/local/lib64/ 64位库文件目录
/boot/ 启动程序目录(内核和启动文件 引导程序)
/etc/ 配置文件目录
/usr/ 应用程序目录
/var/ 服务器数据目录(数据,日志)
/root/ root管理员家目录
/home/ 普通用户家目录
/dev/ 设备文件目录(块设备和字符设备)
/cgroup/ 控制系统资源目录
/tmp/ 临时文件目录
/media/ 媒介目录
/sys/ 伪文件系统(内存信息和进程信息 硬件信息)
/selinux/ selinux使用的目录
/misc和/net autofs使用的目录
/mnt 其它挂载点
/srv 服务器数据目录
/opt 第三方软件目录
绝对路径和相对路径
绝对路径:从/开始的路径
相对路径:相对于当前目录的路径
--------------------------------------------------
查看文件内容的命令
1.head 默认前10行
[root@localhost ~]# head /root/install.log
[root@localhost ~]# head -n 50/root/install.log
[root@localhost ~]# head -50/root/install.log
2.tail 默认后10行
[root@localhost ~]# tail /root/install.log
[root@localhost ~]# tail -50/root/install.log
[root@localhost ~]# tail -f/var/log/messages 动态监控日志文件
3.more 文件百分比
[root@localhost ~]# more /root/install.log
4.less
[root@localhost ~]# less /root/install.log
5.cat
[root@localhost ~]# cat -n install.log
[root@localhost ~]# cat -b install.log 只显示有效行
[root@localhost ~]# cat -n/root/install.log | less
[root@localhost ~]# cat -n install.log |head -1000 | tail -1 显示第1000行
创建文件
[root@localhost ~]# touch aa.txt
[root@localhost ~]# touch cc.txt tt.txt
[root@localhost ~]# touch abc{1..5}.txt
[root@localhost ~]# touch {a,b,c}{1..3}.txt
创建目录
[root@localhost ~]# mkdir abcd
[root@localhost ~]# mkdir abce abcf
[root@localhost ~]# mkdir abc{1..10}
[root@localhost ~]# mkdir -p xx/yy
[root@localhost ~]# mkdir -pv xx/yy -p 递归 -v显示过程
拷贝文件cp
cp 源文件地址 目录地址
[root@localhost ~]# cp /root/tt.txt /tmp/
[root@localhost ~]# cp /root/tt.txt/tmp/kk.txt
[root@localhost ~]# cp -r /root/abcd/ /tmp/
[root@localhost ~]# cp -r /root/abcd//tmp/king
剪切移动文件mv
[root@localhost ~]# mv cc.txt /tmp/
[root@localhost ~]# mv aa.txt /tmp/new.txt
[root@localhost ~]# mv tt.txt hh.txt
[root@localhost ~]# mv abce/ /tmp/
删除
rmdir 只删除空目录
[root@localhost ~]# rm abc1.txt
[root@localhost ~]# rm -f hh.txt
[root@localhost ~]# rm -rf abc1/
[root@localhost ~]# rm -rf *.txt
[root@localhost ~]# rm -rf abc*
命令行
> 覆盖 >> 追加
-----------------------------------------------
vim(文本编辑器)
3种基本模式:命令模式 输入模式 末行模式
命令模式进入输入模式的方法
a当前字符后输入
A当前行行尾输入
i当前字符前输入
I当前行行首输入
o当前行下一行输入
O当前行的上一行输入
s删除当前字符后输入
S删除当前行后输入
Home键 行首 End键 行尾
命令模式
u撤销一步操作
ctrl+r 重做
复制一行 yy 粘贴p P光标所在行上一行粘贴
复制50行 50yy
剪切1行 dd
剪切50行 50dd
^ 行首
$ 行尾
d^ 删除(剪切)当前字符到行首(不包含当前字符)
d$ 删除(剪切)当前字符到行尾(包含当前字符)
y^
y$
G 末行
gg 首行
750G 定位到750行
dgg 删除当前行到首行
dG 删除当前行到尾行
ygg
yG
`` 返回上次工作行
w一个单词的首字符 dw yw
末行模式 shift+:
:w :q :wq
:w! :q! :wq!
功能选项
行号
:set nu
:set nonu
自动缩进
:set autoindent
:set noautoindent
制表符长度(新键入的制表符)
:set softtabstop=4
修改文件中所有的制表符
:set tabstop=4
永久生效 写入vim配置文件:/etc/vimrc
:e /root/aa.txt 打开文件
:r /root/aa.sh 追加读入
:w /root/kk.txt 另存
:2,10w /root/new.txt 另存2-10行
:e! 重新打开当前文件
查找
/ab ?a n N
替换
:%s/ab/xx/gc %所有行 s 替换 g 全局 c交互式
:3,7s/ab/xx/gc
:3,$s/^/#/ 3-最后一行 注释
:%s/^#// 删除所有开头的#
:%s/ //g 删除所有的空格
:%s/^ *//g 去掉所有开头的空格
:%s/\t//g 替换所有的制表符
:3,5s/\n// 去掉3-5行换行符
删除空行
:g/^$/d 只删除只有换行符的行
:g/^\s*$/d 删除所有的空行
设置密码
:X
多文件操作
vimdiff aa.txt cc.txt tt.txt
ctrl+w+w
vim -O aa.txt cc.txt tt.txt
vim -o aa.txt cc.txt tt.txt
-------------------------------------------------------
用户管理
useradd robin
id robin
uid=0 root
uid=1-499 系统用户
uid=500-60000 普通用户
用户配置文件:/etc/passwd
robin:x:500:500::/home/robin:/bin/bash
用户名:密码占位符:uid:gid:描述信息:家目录:shell
/sbin/nologin 非交互式shell
useradd -u 1000 -g robin -c putong -d/home/zorro -s /bin/bash zorro
uid gid 描述 家目录 shell
添加组
groupadd -g 2000 uplooking
配置文件:/etc/group
uplooking:x:2000:
组名:组密码占位符号:gid:
练习:
添加组upup 指定gid为 3000
添加用户king uid 3000 属于upup组 描述 hello 家目录在/tmp shellbash
su - king
groupadd -g 3000 upup
useradd -u 3000 -g upup -c hello -d/tmp/king -s /bin/bash king
useradd -o -u 0 admin 重复uid
修改组信息
groupmod -g 2500 upup
修改帐号信息
usermod -u -g -c -s -d 用户名
删除帐号
userdel -r king
删除组
groupdel upup
设置密码
passwd robin
密码保存位置:/etc/shadow
-------------------------------------------------
用户家目录下的配置文件
.bash_history 保存用户历史命令的文件(当用户退出时写入)
.bash_logout 当用户退出时执行的命令
.bashrc 保存用户定义的别名和函数
.bash_profile 保存用户定义命令搜索位置
env 查看环境变量
自定变量不能被子进程所继承
环境变量可以被子进程所继承
.bashrc shell级别环境变量配置文件
.bash_profile 登录级别环境配置文件
/etc/bashrc 全局shell级别环境变量配置文件
/etc/profile 全局登录级别环境配置文件
加载环境变量配置文件的顺序
/etc/profile
.bash_profile
.bashrc
/etc/bashrc
su robin 和 su - robin
su - robin 登录级别切换
su robin shell级别切换
-----------------------------------------
权限管理
[root@localhost ~]# ll install.log
-rw-r--r--. 1 robin upup 66263 3月 2120:04 install.log
rwx | rwx | rwx
robin upup other
user group other
u g o
uid=0------->user-------->group------>other
对于文件来说:
r---------cattail head
w---------vim > >>
x---------./绝对路径 (rx 普通用户执行)
对于目录来说:
r---------ls (rx 详细信息)
w---------touchrm (wx) (rwx 删除所有文件)
x---------cd
file.txt rwxrwxrwx root root zorro ?
文件能不能被删除取决于上层目录权限
chmod u=r file/dir
chmod u=r,g=rw file/dir
chmod u=r,g=w,o=rwx file/dir
chmod ug=rwx,o=r file/dir
chmod ugo=rwx file/dir
chmod a=rwx file/dir
chmod u-r file/dir
chmod u-r,g+w file/dir
chmod u-r,g+w,o+wx file/dir
chmod ug+rw file/dir
chmod ugo+rwx file/dir
chmod a-rwx file/dir
r--------------4
w--------------2
x--------------1
r-xr---wx 543 671 rw-rwx--x
练习:
查询一下目录或者文件 数据表示权限
/ 555
/etc 755
/tmp 1777
/root 550
/home/robin 700
/etc/shadow 000
/etc/passwd 644
root用户创建的文件权限 644
root用户创建的目录权限 755
普通用户创建的文件权限 664
普通用户创建的目录权限 775
root用户在/tmp下创建文件aa.txt 修改权限为 拥有者没权限 所属组读权限 其他人写和执行权限 3种方式改
644 rw-r--r--
chmod u=,g=r,o=wx /tmp/aa.txt
chmod u-rw,o=r,o+wx /tmp/aa.txt
chmod 043 /tmp/aa.txt
umask 权限反掩码
root 0022
普通 0002
[root@localhost tmp]# chmod -R 777 test/
---------------------------------------------------
修改拥有者 所属组
[root@localhost tmp]# chown robin test/
[root@localhost tmp]# chgrp upup test/
[root@localhost tmp]# chown .robin test/
[root@localhost tmp]# chown zorro.upuptest/
[root@localhost tmp]# chown -R zorro.upup test/
.=:
练习:
1.文件 老板boss 不能读写 公司所有人都能看 ?
2./tmp/test
/tmp/test/tt.txt
robin
zorro
robin可以删除tt.txt 但是不能读写
zorro不可以删除tt.txt 但是可以读写
------------------------------------------------------------
进程管理
静态查询
ps -ef unix风格 -e 所有进程 -f 详细信息
ps aux BSD风格 a 所有终端运行程序 u 显示详细信息 x所有进程
动态查询
top
杀进程
xclock -update 1
kill -15 pid
kill -9 pid
ps -ef | grep xclock
kill -l
pkill xclock
killall httpd
xkill
前后台切换
xclock -update 1 前台
xclock -update 1 & 后台
ctrl+z 调到后台 (停止状态)
jobs 查询后台进程[编号]
bg 编号 后台运行
fg 编号 调到前台
kill %[编号] 杀后台进程
PROCESS STATECODES
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is
being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by
its parent.
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL
pthreads do)
+ is in the foreground process group
--------------------------------------------------------
高级命令(查找命令)
grep --color root /etc/passwd
grep --color ^root /etc/passwd 开头
grep --color root$ /etc/passwd 结尾
wc -l /etc/passwd 计算行数
wc -w /etc/passwd 计算单词数
wc -c aa.txt 计算字符
sort aa.txt 默认首字符排序
sort -n aa.txt 按数字排序(升序)
sort -n -r aa.txt 降序
sort -n -u aa.txt 去掉重复行
uniq aa.txt 默认去掉连续重复行
uniq -u aa.txt 显示不重复行
uniq -d aa.txt 显示重复行
uniq -d -c aa.txt 统计重复次数
cat -n /etc/passwd | head -20 | tail -1 |rev 左右颠倒
cat -n /etc/passwd | head -20 | tail -2 |tac 上下颠倒
cut
cut -d: -f 1 /etc/passwd
cut -d: -f 1,3,6 /etc/passwd
cut -d: -f 1,2-4 /etc/passwd
cut -c 1 /etc/passwd
cut -c 1,4 /etc/passwd
cut -c 1-4 /etc/passwd
1.统计你系统中可以登录的用户
grep bash /etc/passwd | wc -l
cut -d: -f 7 /etc/passwd | grep bash | wc-l
grep -c bash /etc/passwd
2.[root@localhost ~]# ifconfig eth0 | awk-F':| +' '/Bcast/{print $4}'
172.16.140.1
ifconfig eth0 | head -2 | tail -1 | cut -d:-f 2 | cut -d' ' -f 1
ifconfig eth0 | grep Bcast| cut -d: -f 2 |cut -d' ' -f 1
查找命令
1.which 只能查命令
2.whereis
3.locate (updatedb更新)
4.find命令
find 路径 参数 对象
find / -name aa.txt
find / -name '*install*'
find /etc -name '*host*'
find / -type l 根据类型
find / -name aa.txt -exec rm {} \;
find / -name tt.txt -exec ls -l {} \;
find / -name tt.txt -ls
find / -name tt.txt -ok rm {} \;
find /root -size 65k -ls
find /root -size +65k -ls
find /root -size -65k -ls
find /root -size -65k -o -size +10k
find /root -size -65k -a -size +10k
find /root \( -size -65k -o -size +10k \)-ls
---------------------------------------------------------
软件安装
压缩打包
gzip install.log
gunzip install.log.gz
bzip2 install.log
bunzip2 install.log.bz2
du -sh /boot/
tar -cvf boot.tar /boot/ 只打包不压缩
tar -zcvf boot.tar.gz /boot/ 打包压缩 -z 调用gzip c 创建 v 显示打包过程 -f 文件
tar -zxvf boot.tar.gz 解压缩包
tar -ztvf boot.tar.gz 查询
tar -jcvf boot.tar.bz2 /boot/ -j 调用bzip2压缩
tar -jxvf boot.tar.bz2 -x 解包
tar -jtvf boot.tar.bz2
tar -zcvf /tmp/boot.tar.gz /boot/ 指定路径打包
tar -zxvf boot.tar.gz -C /tmp/ 指定解包路径
练习:
将/etc打包 放到/tmp gzip压缩
在将/tmp/etc.tar.gz 解包 放到/root
软件安装
mount/var/ftp/ULA/rhel-server-6.4-x86_64-dvd.iso /mnt/ -o loop
umount /var/ftp/ULA/rhel-server-6.4-x86_64-dvd.iso
umount /mnt
umount -l /mnt
mount /dev/cdrom /mnt 挂载光盘
mount /dev/sdb1 /mnt 挂up盘
umount /dev/sdb1 卸载u盘
光盘目录下目录的作用
HighAvailability 高可用集群软件
LoadBalancer 负载均衡集群软件
Server 普通软件包
ResilientStorage 存储软件
ScalableFileSystem 文件系统软件
Packages 光盘上的所有软件包
cd /yum/Packages/
rpm -ivhhttpd-2.2.15-26.el6.x86_64.rpm -i 安装 -v 安装过程 -h 安装百分比
rpm -q httpd 是否安装
rpm -ql httpd 安装位置
rpm -ql httpd | sort | cut -d\/ -f 2 | uniq
rpm -qa 检索所有的安装包
rpm -qf /etc/man.config 通过文件查软件包
rpm -qf `which mount` 查询命令的安装包
rpm -e httpd 卸载
yum的使用
1.mount/var/ftp/ULA/rhel-server-6.4-x86_64-dvd.iso /yum/ -o loop
2.cd/etc/yum.repos.d/
rm-rf /etc/yum.repos.d/*
touch /etc/yum.repos.d/yum.repo
3.vim /etc/yum.repos.d/yum.repo
[rhel6.4]
name=rhel6.4
baseurl=file:///yum
gpgcheck=0
enabled=1
测试
yum clean all 清除缓存
yum makecache 建立缓存
yum install httpd-devel 安装软件
yum remove httpd-devel 移除软件
yum reinstall httpd-devel 重新安装
计划任务
启动计划任务服务:servicecrond restart
crontab -e
* * * * *
分 时 日 月 周
分(00-59)
时(00-23)
日(1-31)
月(1-12)
周(0-7 0和7都是周日)
* * * * * date >> /tmp/date.txt 每分钟一次
*/5 * * * *date >> /tmp/date.txt 每5分钟一次
10 * * * * date >> /tmp/date.txt 每小的第10分执行
10 10 * * *date >> /tmp/date.txt 每天的10点10分
10 10 10 * * date >> /tmp/date.txt 每月10号的10点10分
10 10 10 10 * date >> /tmp/date.txt 每年10月10号10点10分
10 10 10 10 7 date >> /tmp/date.txt 每年的10月10号10点10分 或者 每周日10点10分
10 10-15 * * *date >> /tmp/date.txt 每天的10-15点的10分
10 10,15 * * * date >> /tmp/date.txt 每天的10点和15点的10分
10 10,15-20 * * * date >>/tmp/date.txt
crontab -l 查询
crontab -r 移除计划任务
练习:
在你系统时间的2分钟后备份boot目录到/tmp目录下 要求:备份文件名字
月-日-时-boot.tar.gz
1.crontab -e
37 14 * * * /home/backup.sh
2.vim /home/backup.sh
#!/bin/bash
tar -zcvf /tmp/`date +%m-%d-%H`-boot.tar.gz/boot
3.chmod +x /home/backup.sh
网络设置
mii-tool eth0 查询网卡是否连接网线
setup 设置静态ip
service network restart 启动网卡
ifconfig eth0 显示ip地址
ifconfig eth0 192.168.10.1 临时更改ip
ping 192.168.10.1
--------------------------------------------
ssh服务
ssh 192.168.3.222
ssh root@192.168.3.222
scp minicom.log 192.168.3.1:/tmp/
service sshd stop
service sshd start
---------------------------------------------
ftp
yum install vsftpd
yum install lftp
service vsftpd restart
数据目录:/var/ftp/
lftp 192.168.3.1
get biji.txt
mirror pub/
------------------------------------
nfs
配置文件: /etc/exports
vim /etc/exports
/nfs 192.168.3.0/24(rw)
启动服务器
service nfs restart
chmod 777 /nfs
客户端
showmount -e 192.168.3.1
mount 192.168.3.1:/nfs /opt