LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 746|回复: 6

一周一练,shell script[基本解决]

[复制链接]
发表于 2004-4-20 01:03:26 | 显示全部楼层 |阅读模式
. who you are(your login id) ,when you logged on, and your full name.

. the number of files(only) in the current directory, including hidden files.

. a list of the files(only),including hidden files,in the current direcory sorted bye size (largest to smallest), and displayed in a three-column format.

. the number of directories in the current directory, including hidden directories, but not including the directories.





http://www.linuxsir.cn/forum.php?mod=viewthread&tid=97285
 楼主| 发表于 2004-4-21 04:55:36 | 显示全部楼层
Up
发表于 2004-4-21 09:21:26 | 显示全部楼层
1,in ur ~/.bash_profile,add:echo $LOGNAME
2,ls -la|grep ^-
3,ls -laS|awk '/^-/{print $5,$9}'
4,for file in $(ls -d .*);do [[ -d $file ]] && echo $file;done
 楼主| 发表于 2004-4-21 12:06:57 | 显示全部楼层
请问这是什么意次?print $5,$9
发表于 2004-4-21 12:17:14 | 显示全部楼层
最初由 shaoping 发表
请问这是什么意次?print $5,$9

用ls -l 可以看出来,(大多数情况下)
-rw-r--r--    1 root     root          958 10月  4  2003 tcplog
 楼主| 发表于 2004-4-22 12:10:34 | 显示全部楼层
1 echo my login ID: $(whoami). I am logged on: $( finger |grep zli15 |
tr -s " "|cut -c23-). My full name is: $(cat /etc/passwd |grep zli15 |cut -d: -
f5 )           

2 echo The number of files in the current directory,including hidden f
iles: $(ls -la|grep ^- |wc -l)        


3 ls -la |grep '^-.*'|tr -s " " |cut -d' ' -f9|xargs ls -as |sort -r |
cut -c6-|pr -t -3-

4 ls -la |grep '^d.*'|sed -e /[\.]$/d |sed -e /[\.\.]$/d |wc -l   

这是我自己做的. 不知对不对。
发表于 2004-4-22 12:26:36 | 显示全部楼层
最初由 shaoping 发表
1 echo my login ID: $(whoami). I am logged on: $( finger |grep zli15 |
tr -s " "|cut -c23-). My full name is: $(cat /etc/passwd |grep zli15 |cut -d: -
f5 )           

2 echo The number of files in the current directory,including hidden f
iles: $(ls -la|grep ^- |wc -l)        


3 ls -la |grep '^-.*'|tr -s " " |cut -d' ' -f9|xargs ls -as |sort -r |
cut -c6-|pr -t -3-

4 ls -la |grep '^d.*'|sed -e /[\.]$/d |sed -e /[\.\.]$/d |wc -l   

这是我自己做的. 不知对不对。

自己验证一下,不就知道正确否?
像你的grep,有了^d 就没有必要再加 .* 了,而且sed可以连写,避免使用过多的管道符,其实linux每个命令都很强大实用,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表