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? 解壓打包的文件
?