LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-12-2012, 09:43 PM   #1
NickPats
Member
 
Registered: Oct 2012
Posts: 43

Rep: Reputation: Disabled
# of files.


how can i find the directory with max files. i listed the #files and name of directory in a file.
 
Old 10-12-2012, 11:22 PM   #2
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
not optimal at all, but easy to read all in one
Code:
IFS=`echo -en "\n\b"`;for dir in $(find ./ -type d -maxdepth 1); do ls -a $dir | wc -l | xargs -i echo {} $dir;done | sort -n | tail -n1
as for using your file, if the number is the first column, then just use 'sort -n'. If it is the last one, then use
Code:
 awk '{printf $NF;for (i=1;i<=NF;i++){printf $i};printf "\n"}' < myfile.txt | sort -n | tail -n1 #untested
to put the number column back in the first position. You can also use ark or perl for the whole thing too. There is a million way to do this, thinking longer about it, I probably could come up with something a lot better

EDIT: ls -> ls -a

Last edited by Elv13; 10-13-2012 at 09:17 PM.
 
Old 10-12-2012, 11:57 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
What exactly your requirement is? Do you want to find a directory with maximum number of files it contains or just want to check the size of the directory for space checking purpose?
For checking the number of files, simply use wc -l option while listing the content i.e. ls -la <directory> | wc -l
For space checking purpose, use du -Sh command
 
Old 10-13-2012, 09:06 AM   #4
NickPats
Member
 
Registered: Oct 2012
Posts: 43

Original Poster
Rep: Reputation: Disabled
though how can i print the directory name with max files in it?is this correct?

for dir in *; do
( echo $dir: $(ls "$dir" | wc -l)) > /dev/null
done

awk '{for (i=1;i<=NF;i++){printf $i};printf "\n"}' < /dev/null | sort -n | tail -n1
 
Old 10-13-2012, 09:16 PM   #5
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
Thinking about it, I made a big mistake in the first one, use "ls -a", ls without -a wont tell you the number of file, only the number of file not starting with ".". Of course, there will be 2 additional "files", '.' and '..'. So, if you want the accurate number, better use "find $dir -maxdepth 1 -type f | wc -l" this will count only file, not directories, remove the "-type f" if you want dirs too.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need to rsync only selected files (--files-from) also need to delete files on dest. ? BrianK Linux - General 5 10-22-2009 09:52 PM
ntfs hard drive mounted. but doesnt show all files , tar files ataomega Linux - Software 1 08-28-2009 12:47 PM
in copy files or ls files the command want to invert select some files how to?? hocheetiong Linux - Newbie 3 06-27-2008 06:32 AM
problem in mounting cdrom(audio files running but not reading data files) amit_usual Linux - Newbie 7 12-29-2007 05:52 AM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 02:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration