鸟哥

bc计算器 scale=4 小数是4位

whatis ls
make what is
ls --help
man ls
man -k pass
info pass

[root@centos01 ~]# ls /etc/init.d/ #服务所在的文件夹

[root@centos01 ~]# runlevel #查找自己在哪个级别 n 表示上一个没有
N 5
-bash-4.1# init 3 #切换到3级别的服务

级别0 关机模式
级别1 单用户模式,相当于windows的安全模式
级别2 单用户模式,不能使用nfs
级别3 正常的模式,不能使用图形化模式
级别4 未定义
级别5 图形化界面
级别6 重启

-bash-4.1# startx 启用图形化界面

-bash-4.1# chmod -R 000 01 #递归改变01文件夹权限

chown tom 01 #改变01文件夹为tom

chown tom:tom 01 #把文件夹改为tomf个人和tom组
chgrp tom 01 #把所属组改为tom组
tree #查看文件树结构
[root@centos01 ~]# lsb_release -a #查看centos 是哪个版本
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.4 (Final)
Release: 6.4
Codename: Final
[root@centos01 ~]# cat /etc/issue #查看centos 是哪个版本
CentOS release 6.4 (Final)
Kernel \r on an \m

创建目录
[jack@centos01 ~]$ mkdir xx yy zz #同时创建xx yy zz 文件夹
[jack@centos01 ~]$ mkdir -p 01/02/03 #同时创建目录和子目录

[root@centos01 ~]# echo $PATH #环境变量

[jack@centos01 ~]$ ls -ld --time=atime 01 #文件夹的访问时间

[jack@centos01 ~]$ ls -ld --cime=atime 01 #文件夹的的生成时间

[jack@centos01 ~]$ ls -R 01 #递归显示文件夹里面内容
[jack@centos01 ~]$ cp /01/* #COPY 01 文件夹所有内容
[jack@centos01 ~]$ cp -p /01/* #copy文件包括属性
[jack@centos01 ~]$ cp -a /01/* #copy 所有内容包括属性
[jack@centos01 ~]$ cp -u /01/* #copy 对比最新文件,以最新文件为准
[jack@centos01 ~]$ cp xx yy #copy 快捷方式为实为xx快捷方式 的原文件
[jack@centos01 ~]$ cp -d xx yy #copy 快捷方式为实为xx快捷方式
[jack@centos01 ~]$ dirname /etc/sysconfig/network-scripts/ifcfg-eth0 #显示该目录目录名
/etc/sysconfig/network-scripts

[jack@centos01 ~]$ cat -n /etc/sysconfig/network-scripts/ifcfg-eth0 #查看文本以行数显示
1 DEVICE=eth0
2 HWADDR=00:0c:29:79:38:bb
3 TYPE=Ethernet
4 UUID=31b2e3cb-096e-41a8-a6aa-da6db0935222
5 ONBOOT=yes
6 NM_CONTROLLED=yes
7 BOOTPROTO=static
8 IPADDR=192.168.1.7
9 NETMASK=255.255.255.0
10 DNS2=114.114.114.114
11 GATEWAY=192.168.1.1
12 DNS1=202.96.134.133
13 IPV6INIT=no
14 USERCTL=no
[jack@centos01 ~]$ nl /etc/sysconfig/network-scripts/ifcfg-eth0 #查看文本以行数显示

more 文件名 然后 :/ 22 查找22并高亮
tail -f *.log 时时查看日志变化

[root@centos01 ~]# od -t c /bin/ls #查看二进制文件内容
[root@centos01 ~]# strace /bin/ls #查看二进制文件内容

查找命令文件
http://www.jb51.net/os/RedHat/1307.html

[root@centos01 ~]# which setup #命令位置
/usr/sbin/setup
[root@centos01 ~]# whereis date #命令位置
date: /bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
[root@centos01 ~]# whereis -b date #命令位置
date: /bin/date
[root@centos01 ~]# whereis -m date #命令位置
date: /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
[root@centos01 ~]# locate ifcfg #查找“ifcfg” 相关文件
[root@centos01 ~]# updatedb #如新创建的文件需要更新updatedb数据库
[root@centos01 ~]# find / -name *ifcfg* #在/ 目录下查找 ifcfg 相关文件
[root@centos01 ~]# find / -name "*.log" #查找.log 文件类型的文件
[root@centos01 ~]# find / -user jack #查找jack用户的所有文件
[root@centos01 ~]# find / -user jack -group market #查找属于jack 又属于market组的文件
[root@centos01 ~]# find / -user jack or -group market #查找属于jack 或者属于market组的文件
[root@centos01 ~]# find / -uid 500 #查找uid为500 这个用户的文件
[root@centos01 ~]# find / -size +2M #查找大于2M的文件
[root@centos01 ~]# find / -size-2M #查找小于2M的文件
[root@centos01 ~]# find / -size +2M -size -5M #查找大于2 小于5M的文件
[root@centos01 ~]# find / -ctime 1 #查找大于一天的文件
[root@centos01 ~]# find / -ctime -1 #查找小于一天的文件
[root@centos01 ~]# find -cmin -1 #查找小于一分钟的文件
[root@centos01 ~]# find -cmin -20 #查找小于20分钟的时间
[root@centos01 ~]# find -newer 01 # 查找01 之前创建的文件
[root@centos01 ~]#find -atime n  # 查找系统中最后n*24小时访问的文件
[root@centos01 ~]#find /opt/soft/test/ -perm 777 #查找ugos777权限的文件
[root@centos01 etc]# find . -size +1000c -print #按大小查找文件
[root@centos01 test]# find -perm +644 #ugo 或, 6 4 4 的权限
./01
./02
./wanger
[root@centos01 test]# find -perm -644 # ugo u要有6 g要有4 o 要有4 的权限的文件

[root@centos01 test]# find -perm -644         # ugo  u要有6 g要有4 o 要有4 的权限的文件
[jack@centos01 ~]$ filefrag -v 01       #查看01文个属于哪个块
[root@centos01 ~]# dumpe2fs /dev/sda1     #查看分区1信息
[root@centos01 ~]# ls -id /etc/
913922 /etc/
[root@centos01 01]# ls -id /           #逐步找块信息
2 /
[root@centos01 01]# ls -id /01/
653033 /01/
[root@centos01 01]# ls -id /01/02
653040 /01/02 
 
[root@centos01 01]# dumpe2fs  /dev/sda1 |more   
[root@centos01 01]# df -h      #查看已挂载文件系统情况
[root@centos01 01]# du -sh /etc/    #查看etc文件夹大小
 
[root@centos01 ~]# fdisk -l /dev/sda   #查看sda分区信息
[root@centos01 ~]# fdisk /dev/sda      #对硬盘进行分区
[root@centos01 ~]# partprobe /dev/sda    #更新sda 分区表
 
[root@centos01 ~]# mkfs. #格式化文件系统
mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.vfat    
mkfs.ext2     mkfs.ext4     mkfs.msdos 
 
[root@centos01 ~]# badblocks #检查分区大小
[root@centos01 ~]# fsck    -f -b
[root@centos01 ~]# badblocks -sv /dev/sda1   
[root@centos01 ~]# fuse -mv /dev/sda1
[root@centos01 ~]# cat /etc/fstab   #开机自动挂载
[root@centos01 ~]# mount /dev/cdrom /mnt/   #挂载光盘到/mnt
-bash-4.1# cp /etc/services .       #
[root@centos01 ~]# yum install ncompress  
[root@centos01 ~]# uncompress services.Z
[root@centos01 ~]# compress -v services
 
[root@centos01 test]# cp /etc/hosts .    #copy hosts文件到当前目录
[root@centos01 test]# cp /etc/hosts .
[root@centos01 test]# ls
hosts
[root@centos01 test]# gzip hosts #压缩hosts文件
[root@centos01 test]# ls
hosts.gz
[root@centos01 test]# zcat hosts.gz  #查看host.gz 文件内容
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@centos01 test]# gzip -d hosts.gz    #解压host.gz 文件
[root@centos01 test]# gzip -c hosts >hosts.gz
[root@centos01 test]# ls
hosts  hosts.gz
[root@centos01 test]# zip hosts.zip hosts     #压缩hosts文件为hosts.zip
  adding: hosts (deflated 65%)
[root@centos01 test]# ls
hosts  hosts.zip
[root@centos01 test]# ls
hosts  hosts.zip
[root@centos01 test]# unzip hosts.zip     #解压hosts.zip 文件
[root@centos01 test]# tar cvf hosts.tar hosts   #归档原文件
 
[root@centos01 test]# tar cvf hosts.tar hosts --remove-files   #归档原文件,并保留原文件
 
[root@centos01 test]# tar tvf hosts.tar   #不解压,查看tar文件里面的内容
[root@centos01 test]# tar xvf hosts.tar     #解压tar文件
[root@centos01 test]# tar xx.tar * --remove-files     #归档当前文件夹所有文件为xx.tar 并删除原文件
[root@centos01 test]# tar tvf xx.tar #查看xx.tar 文件内容
[root@centos01 test]# tar xvf xx.tar 01       #只解压xx.tar 里面的01 文件
[root@centos01 test]# tar zcvf xx.tar.gz  * --remove-files  #归档并压缩当前文件夹
[root@centos01 test]# tar zxvf xx.tar.gz --remove-files #归档并解压当前文件夹
mount
dd
dump
cpio
 
vi 、vim文件编辑器
 
vi 命令模式
插入模式
ex模式
 
yy   3+yy     u  p  dd    wq q   x !
 
:set number    再 4
s/*/*/
s/*/*/g
%s/*/*/g
1,12s/^/#/g    把第1到12行注释掉
1,12s/^#//g    把第1到12行取消注释
 
:set  number             3+shiftg   快速进入3行
 
r     再8
ctrl +v   可视模块    选中,再按↑   按y 再按p手复制
:next   下一个文档
:n 下一个文档
:N
:sp  分屏  再ctrl+ww  屏幕相互切换
[root@ntpserver sysconfig]# unix2dos     linux文档格式转换为dos格式
 
[root@ntpserver ~]# cal ; date 
[root@ntpserver ~]# set #显示所有的变量
[root@ntpserver ~]# env      #显示所有环境变量
[root@ntpserver ~]# export     #显示所有环境变量
[root@ntpserver ~]# export     -p #显示所有环境变量
 
[root@ntpserver ~]# export   aa=3        #定义环境变量aa=3
[root@ntpserver ~]#    aa=3                 #定义本地变量aa=3
declare
 
[root@ntpserver ~]# echo $PS2  #查看SP2环境变量
>
[root@ntpserver ~]# echo $PS1
 
read aa        #输入的值给aa
-bash-4.1# ulimit   # 限制命令
 
history  -c    #  删除历史命令
 
stty -a    显示标准设备输入环境变量
 
-bash-4.1# echo $? 命令对错
 
&& 与   ||或
 
[root@ntpserver ~]# ifconfig eth0 |tee xx|grep "inet addr"   管道倒重定向
 
[root@centos01 ~]# cut -d: -f1 /etc/passwd     #查看现有用户
[root@centos01 ~]# last |cut -d" " -f1   #查看最后登陆的用户
[root@centos01 ~]# grep root /etc/passwd  --color   #过滤passwd 文件中的root 并标颜色
[root@centos01 ~]# grep -inv root /etc/passwd  --color   #-i 忽略大小写;-n显示在哪行出现 -v 排除找到的行
[root@centos01 test]# cut -d: -f3 passwd  | sort       #查找并排序
[root@centos01 test]# cut -d: -f3 passwd  | sort -n     #查找并以数字的顺序排序
[root@centos01 test]# cut -d: -f3 passwd  | sort -nr    #从大到小的排序
[root@centos01 test]# sort -t: -k3 passwd    #以第三部分排序
[root@centos01 test]# last |cut -d" " -f1 |sort -u    #查找最后操作
[root@centos01 test]# last |cut -d" " -f1 |sort|uniq -c   #重复多少次
[root@centos01 test]# wc passwd  # wc 34行53单词数 1619 个字符
  34   53 1619 passwd
 
[root@centos01 test]# cat passwd |tr -d ":"     #删除passwd里面所有的“:”
[root@centos01 test]# diff 01 02  比较两个文件的不同之处
-bash-4.1# grep tom passwd  --corlor 
-bash-4.1# grep 't.m' passwd  --color
-bash-4.1# grep '[Tt].m' passwd  --color
-bash-4.1# grep '^tom' passwd  --color
-bash-4.1# grep 'tom$' passwd  --color
 
grep 查找 sed  修改   awk
 
[root@proxy test]# cat xx.sh      脚本编写
#!/bin/bash
#这是我的第一个脚本
date
echo $$
[root@proxy test]# ./xx.sh  #执行脚本
Sun May  3 20:32:48 HKT 2015
2600
[root@proxy test]# bash xx.sh  执#行脚本
Sun May  3 20:32:52 HKT 2015
2602
[root@proxy test]# source xx.sh  #执行脚本
Sun May  3 20:32:57 HKT 2015
1378
 
[root@proxy test]# cat xx.sh       #脚本定义变量
#!/bin/bash
#这是我的第一个脚本
read -p "请输入您的名字:" name
echo "您好 $name"
[root@proxy test]# bash xx.sh
请输入您的名字:tom
您好 tom
[root@proxy test]# declare -i bb   #数值计算
[root@proxy test]# bb=7+8
[root@proxy test]# echo $bb
15
root@proxy test]# let bb=1+8
[root@proxy test]# echo $bb
9
[root@proxy ~]# cc=$((5+8))
[root@proxy ~]# echo $cc
13
[root@proxy test]# x #返回值
-bash: x: command not found
[root@proxy test]# echo $?
127
[root@proxy test]# echo $?
0
 
数值比较     字符比较
-eq ==
-gt >
-ge >=
-lt          <
-le <=
[root@proxy ~]# [ $aa -gt $bb ]
[root@proxy ~]# echo $?
1
[root@proxy ~]# [ $aa -gt $bb ] && echo 0k    #比较两数大小
[root@proxy ~]# [ $aa -lt $bb ] && echo 0k 
0k
[root@proxy ~]# [ -f /etc/passwd ] #passwd是否存在
[root@proxy ~]# [ -r /etc/passwd ]       
[root@proxy ~]# [ -w /etc/passwd ]  #passwd是否写权限
[root@proxy ~]# [ -x /etc/passwd ]
[root@proxy ~]# echo $?
1
[root@proxy ~]# cat yy.sh      #判断用户是否存在
#!/bin/bash
grep ^$1 /etc/passwd
if [ "$?" -eq 0 ];then
        echo "$1 是存在的"
else
        echo "不存在$1"
fi
[root@proxy ~]# bash yy.sh tom
tom:x:500:500::/home/tom:/bin/bash
tom 是存在的
[root@proxy ~]# cat vv.sh
#!/bin/bash
#set -x
read -p "请输入您的年龄:" name
if [ "$name" -le 0 ] || [ "$name" -ge 150 ]; then
        echo "请重新输入您的年龄"
elif [ "$name" -gt 0 ] && [ "$name" -lt 20 ]; then
        echo "您好小孩子"
elif [ "$name" -ge 20 ] && [ "$name" -lt 50 ]; then
        echo "您好成年人"
else
        echo "您好,老年人"
fi
#case w是用做匹配用的
[root@proxy ~]# gpasswd  -a tom test     #添加tom到test组
Adding user tom to group test
[root@proxy ~]# groups tom    #查看tom属于哪些组
tom : tom test
[root@proxy /]# useradd -D     #查看默认值
[root@proxy /]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=ye
[root@centos01 ~]# usermod -u 505 tom   #修改用户的uid
 
[root@centos01 ~]# passwd -S tom  #查看用户状态
tom LK 2015-05-05 0 99999 7 -1 (密码已被锁定。)
[root@centos01 ~]# passwd  -d tom   #删除tom密码
清除用户的密码 tom。
passwd: 操作成功
[root@centos01 ~]# echo ggggufgg | passwd  --stdin tom    #修改用户密码
[root@centos01 ~]# passwd -x 20 tom    最大使用20天
 
[root@centos01 ~]# chsh -s  /sbin/nologin  tom    修改用户所在的shell
 
root@mini mnt]# cp /dev/cdrom yy.iso     直接把光盘文件转为iso文件
root@mini mnt]#mount -o loop yy.iso /mnt/ 挂载光盘到/mnt
root@mini mnt] dd if=/dev/zero of=file1 bs=1M count=1   假设,dev设备默认为0,单位为1M,取一个单位,给file1
[root@mini test]# dd if=/dev/sdb1 of=/test/uu 备份所有的sdb1所有的文件到uu 
[root@mini test]# dd if=/test/uu of=/dev/sdb1 uu文件还原到sdb1
[root@mini test]# find / -name *ifcfg* |cpio -o > ifcf.cpio  找到相关ifcf的文件打包为cpio
[root@mini test]# cpio -iu <ifcf.cpio  解压打包的文件

 

posted @ 2015-04-27 00:02  wz0314  阅读(575)  评论(0编辑  收藏  举报