1. buffer和cache buffer强调写,cache强调读,读写都带的时候,几乎无差别。buffer另外也有排队等待被处理的意思,cache基本没有。
2. bash配置文件 2.1 全局配置 1 2 3 /etc/profile /etc/profile.d/*.sh /etc/bashrc
2.2 用户配置 1 2 ~/.bash_profile, ~/.bash_login, ~/.profile(同时存在时,依次读取) ~/.bashrc
2.3 profile和bashrc 1) profile文件:
2) bashrc文件:
2.4 登录shell和非登录shell 1) Login Shell: 通过终端登录
1 2 3 su - USERNAME su -l USERNAME /etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile --> ~/.bashrc --> /etc/bashrc
2) Non-Login Shell:
1 2 3 4 su USERNAME GUI终端下打开Console 自动执行的shell脚本 ~/.bashrc --> /etc/bashrc --> /etc/profile.d/*.sh
3. 随机数 1 2 3 4 5 6 7 8 9 10 date | md5sum date +%s | sha256sum | base64 | head -c 32; echo openssl rand -base64 32 cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -1 strings /dev/urandom | grep -o '[a-zA-Z0-9]' | head -32 | tr -d '\n' ; echo
4. 脚本中修改用户密码 4.1 使用代码组 1 2 3 4 5 6 { echo 'pass' sleep 1 echo 'pass' sleep 1 } | passwd abc
4.2 --stdin
1 echo 'pass' | passwd --stdin abc
4.3 查看是否已设置密码 1 2 passwd -S abc | awk '{print $2}'
5. 使用stdin来屏蔽敏感信息 1 2 3 4 5 6 7 8 9 10 11 12 13 $ cat shield_sensitive_info.sh name=$1 read passecho "username=$name " echo "password=$pass " $ echo 123 | ./shield_sensitive_info.sh abc $ ./shield_sensitive_info.sh abc <<EOF 123 EOF
6. 释放内存 查看系统内存使用情况
1 2 free -m cat /proc/meminfo
释放内存
1 2 3 4 5 6 7 8 echo 1 > /proc/sys/vm/drop_cachesecho 2 > /proc/sys/vm/drop_cachesecho 3 >/proc/sys/vm/drop_caches
7. 磁盘管理 7.1 创建分区(fdisk, sfdisk, part) 1) 分区操作
1 2 3 4 5 6 fdisk /dev/sdb n add a new partition p print the partition table w write table to disk and exit l list known partition types t 82: swap, 83: linux, 8e: lvm, fd: raid
2) 查看分区信息
3) 查看内核识别的分区
1 2 3 cat /proc/partions partprobe [/dev/sda] partx -a /dev/sda
4) 大磁盘分区,2TB以上
1 2 3 4 parted /dev/sdb parted /dev/sdc print parted /dev/sdc mkpart logical ext3 19.2GB 19.7GB parted /dev/sdc rm 8
7.2 创建文件系统 默认支持的文件系统:mkfs.xx
VFS: Virtual Filesystem
ext[2-4], xfs
iso9660
nfs, cifs
jfs, resiserfs, vfat
gfs, sfs2, ocfs
1) mkfs
1 2 3 mkfs -t ext3 /dev/sdb1 mkfs.ext3 /dev/sdb2 mkfs.ext3 -b 1024 /dev/sdb3
2) mke2fs (/etc/mke2fs.conf)
1 2 3 4 5 6 7 -b [1024|2048|4096] -i bytes-per-inode # 多少个字节预留一个inode,默认8192 (每8K一个inode) -N numbers-of-inode -L label -j # ext3 -m ratio # 预留给超级用户的磁盘百分比,默认%5 -r blocks # 预留的blocks数量
1 2 3 4 5 6 mke2fs -j -L "ora_logical" -b 2048 -i 8192 /dev/sdb1 mke2fs -j /dev/sdb1 mke2fs -t ext4 -m 2 /dev/sdb1 tune2fs -l /dev/sdb1 | grep "Reserved"
3) tune2fs 调整文件系统属性
1 2 3 4 5 6 -j # ext2->ext3 -L label -m N # 调整预留百分比 -c N # 指定挂载次数达到N次,进行自检,0或-1关闭自检 -i N # 每挂载使用多少天自检,默认180,0或-1关闭自检 -l # 显示超级块中的信息, dumpe2fs
1 2 tune2fs -j /dev/sda5 tune2fs -l /dev/sda5 | grep 'Block size'
4) e2label 查看或定义卷标
1 2 e2label /dev/sda5 e2label /dev/sda5 mydisk
5) blkid 查看设备的相关属性属性(UUID, FSTYPE, LABEL)
6) dumpe2fs 分区系统,BLOCK-GROUPs
7.3 检查文件系统 1) fsck
1 2 3 -t FSTYPE -a # 自动修复,不询问 -f # 强制价差
1 2 fsck -C -f -t ext3 /dev/sdb1 fsck -f /dev/sdb1
2) e2fsck 专用修复ext2,ext3
1 2 3 4 5 fsck -y /dev/sda1 e2fsck -p /dev/sdb1 mke2fs -c /dev/sdb1
7.4 挂载 1) mount [options] DEVICE MOUNT_POINT
DEVICE:
DEV
LABEL=”mysql-data”
UUID=”uuid”
options:
1 2 3 4 5 6 7 8 9 10 11 12 13 -t fstype -a 挂载/etc/fstab中全部auto的分区 -r readonly -n, --no-mtab 不更新/etc/mtab -o defaults rw,suid,dev,exec,auto,nousers,async,realtime ro readonly noatime 访问不更新atime noauto mount -a不挂载 sync 同步写入 nodev 不读文件系统上的字符或块设备 remount 重新挂载 loop 本地回环设备
1 2 3 4 mount -o remount,ro /dev/sdb1 mount -o ro /dev/cdrom /media mount -o loop,ro /root/RHEL6.iso /media
2) umount [DEVICE|MOUNT_POINT]
1 2 3 4 umount /mnt umount: /mnt: device is busy. fuser -km /mnt