Search entire server for a certain file type larger than 1GB in size? [duplicate] - linux

This question already has answers here:
Find files with a certain extension that exceeds a certain file size
(3 answers)
Closed 3 years ago.
I have the following linux command I use to determine if a directory is larger than 1GB in size:
du -sh * | sort -hr | awk '$1 ~ /[GT]/
How would I modify this to instead search for any file that has a certain file type, such as .log filetype?

Better use find :
find . -type f -name '*.log' -size +1G

sudo find /www-data -name "*.log" -type f -size +1000000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' | sort

Related

im trying to find the largest files created or modified within the last 10 days within Linux

im trying to find the largest files created or modified within the last 10 days within Linux.
I wanted to find all files which exceed 100MB in size but were created in the last 10 days.
Almost along the lines of the below
find / -type f -size +100000k -exec ls -lShr {} ; | awk '{ print $9 ": " $5 }' | sort -k 5 -r -h
-mtime -10 -ls
You can use -printf of GNU find:
find / -size +100M -mtime -10 -printf '%s\t%p\n' | sort -n

Listing only name and size of the file with largest size (UNIX) [duplicate]

This question already has answers here:
How to find the largest file in a directory and its subdirectories?
(17 answers)
Closed last year.
How can I only list the name and the size of the largest file size in a directory I used this command but It didn't work when I tried on a different directories.
find . -type f -exec ls -lS {} \; | sort -t" " -n -k5 | cut -d" " -f5,10 | tail -n1
This should work
find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head -n 1
the number 1 after head -n means how many of the largest files it'll output and if you want to find files in sub-directories as well you can do that by removing the -maxdepth 1 or changing the number to a larger one.
for more info see the replies in this earlier post: How to find the largest file in a directory and its subdirectories?
For posts about this kind of stuff i suggest tagging them as bash, sh or shell.

How to get combined disc space of all files in a directory with help of du in linux [duplicate]

I've got a bunch of files scattered across folders in a layout, e.g.:
dir1/somefile.gif
dir1/another.mp4
dir2/video/filename.mp4
dir2/some.file
dir2/blahblah.mp4
And I need to find the total disk space used for the MP4 files only. This means it's gotta be recursive somehow.
I've looked at du and fiddling with piping things to grep but can't seem to figure out how to calculate just the MP4 files no matter where they are.
A human readable total disk space output is a must too, preferably in GB, if possible?
Any ideas? Thanks
For individual file size:
find . -name "*.mp4" -print0 | du -sh --files0-from=-
For total disk space in GB:
find . -name "*.mp4" -print0 | du -sb --files0-from=- | awk '{ total += $1} END { print total/1024/1024/1024 }'
You can simply do :
find -name "*.mp4" -exec du -b {} \; | awk 'BEGIN{total=0}{total=total+$1}END{print total}'
The -exec option of find command executes a simple command with {} as the file found by find.
du -b displays the size of the file in bytes.
The awk command initializes a variable at 0 and get the size of each file to display the total at the end of the command.
This will sum all mp4 files size in bytes:
find ./ -name "*.mp4" -printf "%s\n" | paste -sd+ | bc

Bash - Find largest file and print its path [duplicate]

This question already has answers here:
How to find the largest file in a directory and its subdirectories?
(17 answers)
Closed 5 years ago.
I need to find the largest file of chosen directory and sub-directories and print the path of that file
I can find the biggest file (I think so)
find . -type f | wc -l
However, I'm stuck on printing the path
find . -type f | xargs ls -l | sort -nk 5 | tail -n1 | awk '{print $NF}'
What i would do :
find . -type f -exec du {} \; | sort -n | awk 'END{$1=""; print}'

How to use du to take the paths from stdin and calculate the total size? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Get total size of folders with find & du
I can use du like this to get the file size of each file from stdin
find . -name "*.java" -exec du -h {} \;
But I can't get the total size.. Does anyone have ideas about that?
Thanks!
Answered here:
How to get total size of folders with find and du?
Use xargs(1) instead of -exec:
find . -name bak -type d | xargs du -ch
executes the command for each file found (check the find(1) documentation). Piping to xargs lets you aggregate those filenames and
only run du once.
In your case it would be:
find . -name "*.java" | xargs du -ch
Options:
-c, --total
produce a grand total

Resources