command that search for certain files and then give the file size of the search files

umcpgrad

2[H]4U
Joined
Apr 2, 2004
Messages
2,800
thanks in advance, I am trying to search for certain files and then find out the total size of the files
 

ameoba

Supreme [H]ardness
Joined
Jan 9, 2001
Messages
6,413
du prints out the size of files. Using the -m flag (if supported) gives file size in MB. The -c flag gives you the total size of all file.

find finds files. you could "find . -name '*.jpg' -or -name '*.jpeg' " to find all your jpg/jpeg files (in the current directory or below). This thing has lots of options so it can find damned near anything you want to specify.

The ` (back-tick) operator takes the output of a previous command and makes it the command-line for another.

Stringing this together, you get :
Code:
du -mc `find . -name '*.jpg' -or '*.jpeg'`
which will list all jpeg files & then their total size. If you just want the total, you can add a "| tail -1" to pipe (route) the output of that command through tail, which will only show the last line of its input.

Unix commands are like Legos, there's only a few of them but you can connect them in all sorts of crazy ways to make different things.
 

Cali3350

Supreme [H]ardness
Joined
Mar 22, 2002
Messages
4,701
Alternaltively you can use du -h instead of du -mc to get files in a general human readable form.
 
Top