Shell程序集

Shell程序集合

bash-2.03# pkgchk -l -p /usr/local/bin/rsync 
路径名:/usr/local/bin/rsync 
类型:正规文件 
期望的模式:0755 
期望的属主:bin 
期望的组:bin 
期望的文件大小(字节):430636 
期望的内容的 sum(1):2431 
期望的上一次修改: 1月 31 11时37分26秒 2009 
由以下软件包引用: 
SMCrsync 
当前状态:已安装 
bash-3.00$ which ls 
/usr/bin/ls 
bash-3.00$ grep /usr/bin/ls /var/sadm/install/contents 
/usr/bin/ls f none 0555 root bin 27400 9595 1169666070 SUNWcsu 

http://www.debian.org/CD/netinst/ 下载netinst CD并安装,注意netinst CD只有包含基本系统,不包含图形界面。

基本系统安装完成后,安装xorg, gnome和gdm:

apt-get install xserver-xorg-core 
apt-get install gnome-core 
apt-get install gdm 

配置:

dpkg-reconfigure xserver-xorg-core 
dpkg-reconfigure gnome-core 
dpkg-reconfigure gdm 

重启即可。


怎样知道一个文件中有多少个逗号?

tr -cd ‘,’ <udev.c | wc -c 

d 表述删除


不覆盖文件的cp

yes n | cp -i bfsh-koc/test.sh ./ >& /dev/null 

是否覆盖的提示overwrite将被忽略掉。


标题: 如何将grep的结果整行的赋给一个变量

请问大家

for var in `grep -rne "aText" .` 
do 
something 
done 

如果grep结果是:

xxxx yyyyy
cccc dddd

那么var会在头一次循环中等于xxxx,第二次循环等于yyyyy。我怎么才能把这一整行赋给var呢?


-bash-3.00$ cat test0405a 
123$ 
$ 
4$ hello 
5$ 
42$ world 
43$ test 

#!/bin/bash 
typeset -i n=$(grep '4' test0405a | wc -l) 
echo $n 
typeset -i m=1 
while [ $m -le $n ] ; do 
var=$(sed -n '/4/p' test0405a | sed -n '$m p') 
echo $var 
m=$m+1 
done 

写一个shel脚本,输出文件1中有而文件2中没有的行。

-bash-3.00$ diff text text.2 | sed -n 's/< //'p 

用命令 comm 也可以

comm file1 file2 

默认是 三列输出
com1 com2 com 3

com1 = not in file1
com2 = not in file2
com3 = in both file1 && file2

输出文件1中有而文件2中没有的行

comm -23 file1 file2 

rev 命令将输入字符串反向排列。


找出当前目录下大于4K的文件

-bash-3.2$ find -size +4k 
./.nfs00000000042f00d500000022 
./a.out 
-bash-3.2$ find -size -4k 
./server.c 
-bash-3.2$ find -size 4k 
-bash-3.2$ ls -lh 
total 12K 
-rwxr-xr-x 1 yuntian member 5.8K Sep 9 16:03 a.out          
-rw-r--r-- 1 yuntian member 735 Sep 9 16:03 server.c 

统计非空白行数:

grep '.' filename | wc -l 
sed '/^$/d' filename | wc –l

――――――――――――――――――――

dd if=/dev/zero of=file.dat bs=1024k count=10 
mkfile 10m fiel.dat

――――――――――――――――――――

# tree.sh 

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 

忘了哪里看到的,显示目录树。sed ,awk什么的也真是难懂。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,967评论 19 139
  • 基础命令 主要的命令和快捷键 Linux系统命令由三部分组成:cmd + [options]+[operation...
    485b1aca799e阅读 1,125评论 0 0
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 12,237评论 2 33
  • L是小城公务员,已过中年,整个人被舒适的生活泡大了一倍,白白胖胖,十指不沾阳春水,一脸未被阳光...
    我爱笑楚宝宝阅读 350评论 13 16
  • 我拒绝更圆更美的月亮 不拒绝你 图文/吉豆加加 火辣辣的热情 这是专属辣条的你和我 止不住的兴奋 是你踏入未知的好...
    吉豆加加阅读 159评论 2 4