Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My requirement is like this, in my folder i have lot of files
i have to find the biggest file. my folder contains lots of sub folders also......
i think i gave a clear picture about my requirment...
You could have given us some info about which Linux distro you are using, and also how big is your hard drive, etc.
If you are using the KDE desktop, then open the Start menu and click on Home to open the File Manager. Then click on the Size tab at the top of the second column twice, and a little black arrow should appear pointing up. This will sort directories and files with the biggest at the top. Now you just have to go through all the directories and sub-directories by hand.
You could view the directory using a GUI file manager like konqueror under KDE, nautilus under Gnome, Thunar under XFCE, select detailed listing and then sort on the size and look at the top/bottom of the list.
The same approach works for the ls program in the terminal - sort and take the top or bottom of the list.
From the ls manual page:
Quote:
-S sort by file size
What it doesn't say explicitly is that the list will be in descending order, so you can take the top of the list to see the largest (I just found it by trying it and seeing what order it was using).
This will just print the name of the largest file:
Code:
ls -S |head -1
Or if you want to see the details, add an l (lower case L):
find ./ -type f -printf "%s %p\n" | awk 'BEGIN {max=0} {
if ($1>max) {max=$1; maxfile=$2 }
}
END {print max maxfile}'
The find program will print the size of the largest file in the current directory and its subdirectories. The awk program will print out just the largest file.
Code:
ls -lR * | tr -s ' ' | sed -n '/^-/p' | cut -d' ' -f5,9 | sort -nr | head
This oneliner A) lists all of the files B) truncates the extra spaces B) filters out directories C) performs a reverse numeric sort D) prints out the first few lines.
If you have a large amount of files, "ls -lR" might fail. If that is the case, use the find command.
This will just print the name of the largest file:
Code:
ls -S |head -1
if the requirement is to find the largest file including subfolders, then have to include -R and do some extra processing to get rid of extraneous lines.
Quote:
Or if you want to see the details, add an l (lower case L):
Code:
ls -lS |head -1
if the -l is added, then head -1 will give the "total <size>" string..got to get the second line instead.
if the requirement is to find the largest file including subfolders, then have to include -R and do some extra processing to get rid of extraneous lines.
if the -l is added, then head -1 will give the "total <size>" string..got to get the second line instead.
Code:
# ls -lS| sed -n '2p'
Including the -R argument will cause each folder to list the largest files first, but won't list the largest file of all directories on the top.
Code:
du -ab /path/*|sort -rn|head -1
This has promise but will list a directories as well.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.