Chinaunix首页 | 论坛 | 博客
  • 博客访问: 547548
  • 博文数量: 201
  • 博客积分: 7734
  • 博客等级: 少将
  • 技术积分: 1994
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-09 19:18
文章分类

全部博文(201)

文章存档

2011年(28)

2010年(173)

分类: LINUX

2010-06-17 23:11:05

I/O 输入和输出
默认的:
STDIN  来自键盘的标准输入
STDOUT 来自terminal窗口的输出
STDERR 标准的错误输出 terminal
>输出重定向   将正确的信息导入一个文件里  错误的显示在终端
2>错误输出重定向  将错误的信息导入一个文件里   正确的显示在终端
&>将所有信息输导入一个文件里
>>追加
$find /etc/ -name passwd 2> /dev/null  将错误的信息丢掉
$find /etc/ -name passwd > find.out 2> find.err 将错误的和正确的信息分别导入不同的两个文件里

pipe: |  管道
将第一个命令的结果 传输到第二个命令中
 
find /etc/ -name passwd | mv {} password

错误信息不能传给管道。

$echo "test email" | mail -s "test"

ps auo %cpu,%mem,pid,com |
 sort -r |mail -s "cpu" root
ps auo %cpu,%mem,pid,comm |sort -r|head -n 11 |mail -s "cpu" root
$ echo "test print"|lpr -P printer_name  (-P指定打印机)

2>&1  :    将错误的信息输出到屏幕上

$(cal 2007 ; cal 2008) |less

把每个管道的内容都输出到各自的文件里。用tee
$command1 | tee file1 |command2 |tee file2
把command1的结果放到file1中。将command2的结果放到file2中
$ls -lR /etc/ |tee stage1.out |sort |tee stage2.out |uniq -c |tee stage3.out |tee sort -r |stage4.out |less
uniq -c 把重复的东西只保留一个

输入重定向:
$tr 'A-Z' 'a-z' <.bash_profile
$cat .bash_profile | tr 'A-Z' 'a-z'
<< 将键盘的多次输入一次输出。
mail -s "Please Call " <>hi
> please give me a call when you
>to do some
>END
当起始和结束一样的时候。系统就认为完成了。
%post  安装后运行的程序。叫开机后的脚本。  kickstart.cfg
%post
ntpdate -b 192.168.0.254  
hwclock --systohc -utc
cat > /etc/ntp.conf <restrict default ignore
restrict 127.0.0.1
restrict 192.168.0.254
restrict server 192.168.0.254
END

wget    下载命令。
 
for loop 循环语句:
--------------------------------------------------
for NAME in joe jane julie
do
ADDRESS="
"
MESSAGE'Project are due today!'
echo $MESSAGE |mail -s Reminder $ADDRESS
done
------------------------------------------------
-----------------------------------------------
for USER in user2 user3 user4
>do
>useradd $USER
>echo  password |passwd --stdin $USER
>done
---------------------------------------------------
for num in $(seq 1 10)

for file in *.txt
------------------------------------------------------
#!/bin/bash
#useradd.sh
for num in $(seq 1 10)
>do
>/usr/sbin/useradd user$num
>echo password |passwd --stdin $user$num
>done
-------------------------------------------------------
----------------------------------------------
num=$(seq 1 10)
USER=user$num

-----------------------------------------------
#!/bin/bash
for n in {1..20}; do
 host=192.168..0.$n
 ping -c2 $host &> /dev/null
 if [ $? = 0 ] then
 echo "the $host is up"
else
 echo "the $host is down"
fi
done
-------------------------------------------------
cat 是一 次性显示全部的文件。用来和grep一起用很好用。
nl 在显示的时候,自动的加上行号。
head 显示文件的前十行
tail 显示文件的后十行
实时的看到一个数据:
tail -f /var/log/secure

显示文件的第十行到第二十行:
head -n 20 /etc/passwd |tail >/tmp/passwd.txt
============================================================
grep匹配指定的关键字(以行为单位)
$grep 'john' /etc/passwd
$grep --color=auto redhat1 /etc/passwd  给关键字加颜色。
$date --help |grep --color=auto year |wc

-i 忽略大小写 。很有用的一个参数
-n 显示在文件里的第几行数
-A5 过滤的下五行也显示出来
-B5 过滤的上五行也显示出来
ls -lR /proc/sys |grep ip_forward 查看文件夹下是否存在某个文件
=====================================================================
cut 以列为单位匹配关键字。
cut -d: -f1 /etc/passwd |mail -s "useraccount" boss
grep root /etc/passwd |cut -d: -f7
last |cut -d' ' -f1

ifconfig eth0|grep 'inet addr'|cut -d: -f2 |cut -d' ' -f1
==================================================================
wc (word count)  做文本统计
-l 统计行数
-w 统计单词数
================================================
sort  默认查看每行的每一个字符  数字的优先级大于字符

-n 通过数字来排  如果没有-n参数。将把数字当字符排
-f  忽略大小写
-u  删除重复行
-k 第几行
-t 什么做为分隔符
========================================================
diff 比较文本  patch 打补
diff -u vsftpd.conf /etc/vsftpd/vsftpd.conf >vsftpd.patch
patch -b /etc/vsftpd/vsftpd.conf vsftpd.patch
=========================================================
aspell 语法检查
tr  大小写转换
=========================================================
sed  替换文件里的某些内容
sed 's/dog/cat/g' pets  g是全局替换的参数
sed '1,3s/dog/cat/g' pets
sed '/linux/,/redhat/s/dog/cat/gi' pets  gi:真正的全局替换
从linux到redhat中的dog替换成cat.
=============================================
for i in $(ls *.txt|awk -F. '{ print $1 }')
 

do
mv $i.txt $i.doc
done                          把后缀为txt的文件改为doc
==============================================
-i  真正替换
-e  多个参数一起用
-f  使用文件里的语法来替换
[abc] 匹配a 或b或c
[^abc]不匹配a or b or c
阅读(563) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~