开发者

To list files based on size in unix

开发者 https://www.devze.com 2023-02-19 00:15 出处:网络
GOAL : To fetch list of files occupying more space in unix using the below command ssh serverName du /folderName/* | grep -v \'cannot\' | sort -nr | head -10

GOAL : To fetch list of files occupying more space in unix

using the below command

ssh serverName du /folderName/* | grep -v 'cannot' | sort -nr | head -10

Using sort -nr to consider as numeric and sort in reverse (To开发者_如何学编程 get files occupying more space)

Using the grep -v 'cannot' because there is no access to few folders and these lines must be ignored before sorting

Below is the sample output

624    /folder1/folder2/conf
16     /folder1/folder2/error/include
192    /folder1/folder2/error
284    /folder1/folder2/htdocs
264    /folder1/folder2/icons/small
du: cannot read directory `/folder1/folder2/file1': Permission denied
du: cannot read directory `/folder1/folder2/file3': Permission denied

Facing issues with grep and sort commands, as the error messages are not getting filtered


You need to redirect stderr to stdout using 2>&1 so that you can grep out the error messages. You should also escape the wildcard so that it gets expanded on the remote machine, not on the local one.

ssh serverName du /folderName/\* 2>&1 | grep -v 'cannot' | sort -nr | head -10


You don't need the grep if you close stderr.

ssh serverName du /folderName/\* 2>&- | sort -nr | head -10

Note that the wildcard is escaped.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号