How to find the largest file in a directory and its subdirectories?

unix find largest files in directory
find largest files in directory recursive
find largest directories terminal
linux find files larger than 1gb
linux find large files exclude directory
list top 10 files in unix
aix list largest files in directory
how to find largest files unix

We're just starting a UNIX class and are learning a variety of Bash commands. Our assignment involves performing various commands on a directory that has a number of folders under it as well.

I know how to list and count all the regular files from the root folder using:

find . -type l | wc -l

But I'd like to know where to go from there in order to find the largest file in the whole directory. I've seen somethings regarding a du command, but we haven't learned that, so in the repertoire of things we've learned I assume we need to somehow connect it to the ls -t command.

And pardon me if my 'lingo' isn't correct, I'm still getting used to it!

Quote from this link-

If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories

$ find . -printf '%s %p\n'|sort -nr|head

To restrict the search to the present directory use "-maxdepth 1" with find.

$ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

And to print the top 10 largest "files and directories":

$ du -a . | sort -nr | head

** Use "head -n X" instead of the only "head" above to print the top X largest files (in all the above examples)

How To Find The Size Of A Directory In Linux, How do I find the size of a directory wise in Linux? Find the largest file in a directory and its subdirectories using the find command Type the following GNU/find command: ## Warning: only works with GNU find ## find / path / to / dir / -printf '%s %p ' | sort -nr | head -10 find .

To find the top 25 files in the current directory and its subdirectories:

find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 25

This will output the top 25 files by sorting based on the size of the files via the "sort -nr -k5" piped command.

Same but with human-readable file sizes:

find . -type f -exec ls -alh {} \; | sort -hr -k5 | head -n 25

How to find the largest file in a directory and its subdirectories , . The largest sub-directories will be displayed on the top. I'm trying to find the 50 largest file in a directory named /sasdb and its' subdirectories. I'm using the find command and a pipe to awk Not sure if I'm actually getting the largest files from this directory and its subdirectories.

find . -type f | xargs ls -lS | head -n 1


-rw-r--r--  1 nneonneo  staff  9274991 Apr 11 02:29 ./devel/misc/test.out

If you just want the filename:

find . -type f | xargs ls -1S | head -n 1

This avoids using awk and allows you to use whatever flags you want in ls.

Caveat. Because xargs tries to avoid building overlong command lines, this might fail if you run it on a directory with a lot of files because ls ends up executing more than once. It's not an insurmountable problem (you can collect the head -n 1 output from each ls invocation, and run ls -S again, looping until you have a single file), but it does mar this approach somewhat.

How To Find Largest Top 10 Files and Directories On Linux / UNIX , Quote from this link-. If you want to find and print the top 10 largest files names (​not directories) in a particular directory and its sub directories. If you’re more of a geeky person, you can use the Command Prompt utility to retrieve a list of all the files larger than a specified size value. The files list can be exported to a text file for you to then actually find those files on your machine. Press Windows + R, type in cmd, and hit Enter to launch the utility.

This lists files recursively if they're normal files, sorts by the 7th field (which is size in my find output; check yours), and shows just the first file.

find . -type f -ls | sort +7 | head -1

The first option to find is the start path for the recursive search. A -type of f searches for normal files. Note that if you try to parse this as a filename, you may fail if the filename contains spaces, newlines or other special characters. The options to sort also vary by operating system. I'm using FreeBSD.

A "better" but more complex and heavier solution would be to have find traverse the directories, but perhaps use stat to get the details about the file, then perhaps use awk to find the largest size. Note that the output of stat also depends on your operating system.

Quickest way to find the largest file in a directory and subdirectories , Find the largest file in a directory and its subdirectories using the find command. Type the following GNU/find command:  Linux find largest file in directory recursively using find. The procedure to find largest files including directories in Linux is as follows: Open the terminal application; Login as root user using the sudo -i command; Type du -a /dir/ | sort -n -r | head -n 20; du will estimate file space usage; sort will sort out the output of du command; head will only show top 20 largest file in /dir/ Linux find a biggest files in /

How to find the largest file in a directory?, GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters: find . -type f -printf "%s  du is to Estimate file space usage. sort is to sort lines of text files or given input data. head is to output the first part of files i.e. to display first 10 largest file. find is to Search file. How to find the largest file in a directory and its subdirectories using the find command? find /path/to/dir/ -printf '%s %p '| sort -nr | head -10

list largest files in a directory & its subdirectories, The best way is to use ls , sorted by size: ls -S. To get the biggest one, use head : ls -S | head -1. In this guide, we will cover how to display the total number of files in the current working directory or any other directory and its subdirectories on a Linux system. We will use the find command which is used to search for files in a directory hierarchy together with wc command which prints newline, word, and byte counts for each file

How to Find Out Top Directories and Files (Disk Space) in Linux, I need to find the largest files in a directory & it's subdirectories. I'm not sure what options on ls -l will work to give me this. or is there another way to do this? When you’re trying to clean up your filesystems and reclaim some space, one of the first things you’ll want to do is to confirm the largest directories and individual files you have. This can be easily done using two Unix commands: find command and du command. Find files larger than a certain size

How to find the largest files on Linux, This brief tutorial describes how to find the largest files, directories and sub directories disk usage in the Linux file system using du and find  How to Find Biggest Files and Directories in Linux Run the following command to find out top biggest directories under /home partition. # du -a /home | sort -n -r | head -n 5

  • If you know of a command, but aren't sure how to use it then try typing in man followed by the command you are interested in. Up will pop a nice manual entry for that command (press q to get back to command line).
  • related:…
  • Why does "du -a . | sort -nr | head" return double the number of KB than the actual file size?
  • Ah, you need to add the 'k' option or it shows multiples of 512 bytes rather than of 1024. du -ak
  • for the first one, how do you get the size in a human readable format?
  • @Bluz I'd try replacing '%s %p\n' with '%p\n' and adding |xargs ls -lh to the end
  • The first solution didn't work on OS X for me, so i ended up using a quick hack to filter out the directories from the third solution: du -am . | sort -nr | grep '\..*\.' | head. The m is to display file size in megabytes and used grep to show lines with at least two dots, the first is in the ./ in the path, the second is in the file extension, e.g. .mov.
  • i'm sorry xargs, i have neglected you +1
  • to handle filenames with spaces, use find . -type f -print0 | xargs -0 ls -lS | head -n 1
  • This finds the biggest files in only the first batch xargs has executed. To fix it add sorting: find . -type f -print0 | xargs -0 ls -lS | sort -rk 5 | head -n 10. Worked on OSX for me.
  • What is the +7 arg meant to be doing? On my machine sort just complains that it can't find a file called +7.
  • @Dunes - As I said, check the man page for sort on your system. I'm using OS X 10.4 at the moment, where usage derives from FreeBSD's sort: sort [-cmus] [-t separator] [-o output-file] [-T tempdir] [-bdfiMnr] [+POS1 [-POS2]] [-k POS1[,POS2]] [file...] ... Note the +POS [-POS2]. This works in current versions of FreeBSD too.