Reputation: 11
I have 2TB
of data. I want to list entire .zip
and .rar
files and files size in the directory and I want to exclude 01_Personal
Folder directory.
I tried below command but it didn't work out.
find /home -type f ( -name ".zip" -o -name ".rar" ) ! -path "01_Personal Folder*" -print0 | xargs -0 -n1 du -b | sort -n -r > winrar.txt
Any other way to find files and file sizes.
Thanks for your help
Upvotes: 0
Views: 6658
Reputation: 1
With a slight modification to @prayas-pagade 's answer, I was able to achieve it using the following command:
du -ah | grep -e "\.zip$" -e "\.rar$"
Upvotes: 0
Reputation: 14468
Recall that find
has a predicate printf
to create formatted output, including size. So you can combine the filtering and formatting together:
find /home -type f '(' -name "*.zip" -o -name "*.rar" ')' '!' -path "01_Personal Folder*" -printf '%P %k\n'
Note: remember to quote all tokens which might have special meaning. This includes the file patterns (*.zip, ...), parentheses, exclamation point which might mean somthing to the shell.
Filtering on the name/folder with find eliminate searching and size calculation on unrelated files.
Upvotes: 1
Reputation: 67
You can use the below command: du -ah | grep -e ".zip" -e ".rar"
Explanation: du shows the disk usage, -h is for human-readable size. And grep will find the match for .zip and as for multiple words we'll use -e.
Upvotes: 0
Reputation: 1
You should use find
find -iname *.zip
Example: to search for all .zip files in current directory and all sub-directories try this:
find . -iname *.zip
This will list all files ending with .zip regarding of case. If you only want the ones with lower-case change -iname to -name
The command grep searches for stings in files, not for files. You can use it with find to list all your .zip files like this
find . |grep -e ".zip$"
After you get the list of .zip files you can easily find the size of them.
Upvotes: 0