您的位置:首页 > 运维架构 > Linux

the diary of homework of script check dir in linux

2017-04-17 11:41 405 查看

to make a script to check a directory?

#!/usr/bin/bash
#check the information of a directory
#Asha 2017/4/17

if [ ! -d $1 ]
then
echo there is no this directory.
exit
fi 

echo we have `ls -p $1 | grep '[^/]$' | sed 's/\s\s*//g' | wc -w` files inside this directory.

echo we have `ls -p $1 | grep '[/]$' | sed 's/\s\s*//g' | wc -w` directories inside this directory.

echo the biggest file `ls -l
$1| tail -n +2 | sed 's/\s\s*/ /g' | cut -d ' ' -f 5,9 | sort -n | cut -d ' ' -f 2| tail -1`.

echo the latest modification file or directory is `ls -l -t$1| tain -n +2 | head -1`.

echo the owners of files or directories inside this directory is/are `ls -l $1 | tail -n +2 | sed 's/\s\s*/ /g' | cut -d ' ' -f 3 | uniq`.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: