In Linux, how do I find find directory with the most subdirectories or files? [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How can I find the directory with the largest number of files/subdirectories in it on the system? Obviously the clever answer is /, but that's not what I'm looking for.
I’ve been told the filesystem is out of nodes, so I suspect that somewhere there are a lot of files/directories which are just garbage, and I want to find them.
I’ve tried running this:
$ find /home/user -type d -print | wc -l
to find specific directories.

starting from the current directory, you could try
find . -type d | cut -d/ -f 2 | uniq -c
This will list all directories starting from the current one, split each line by the character "/", select field number "2" (each line starts with "./", so your first field would be ".") and then only outputs unique lines, and a count how often this unique line appears (-c parameter).
You could also add an "sort -g" at the end.

Related

"Find" command: highlight matching literal parts [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I use find a lot, generally using the -name or -iname parameters.
I would like it to highlight the matching part in the files it finds (like grep does).
For example: find . -iname "*FOO*" would highlight instances for FOO
I know I could pipe it into grep but I'd rather not write two commands each time.
Is there a simple way to do it?
eg. like this:
find /home/ -type f | grep -i --color=always *.cpp

Linux/Unix Command Needed for finding files on a particular date [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I need help finding files in a directory which contain a word/string and on a particular date.
Currently I am using this command:
find . -exec grep -l .string. {} \;
This command returns all the files containing that string in that directory. I would like to get those files on from a particular date, for example 12/24/2013.
You can use:
find . -type f -exec grep 'string' {} \; -exec ls -l {} \; | grep 'Dec 24'
Which will search any files which contain the string string, and then execute ls -l on only those files, and finally, grep out any that match Dec 24.
This works because find will apply it's arguments in order, so only those that match previous results will be passed on.
Maybe this could help you with grep:
find /path/to/find -type d -atime -7
The last parameter is days here 7 days before you can modify to particular dat ,atime is the file access time ,'d' is directory search for directory for find a file replace 'd' with 'f' give the path where to find and then finally make pipeline this with grep to string to search

List of All Folders and Sub-folders [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
In Linux, I want to find out all Folder/Sub-folder name and redirect to text file
I tried ls -alR > list.txt, but it gives all files+folders
You can use find
find . -type d > output.txt
or tree
tree -d > output.txt
tree, If not installed on your system.
If you are using ubuntu
sudo apt-get install tree
If you are using mac os.
brew install tree
find . -type d > list.txt
Will list all directories and subdirectories under the current path. If you want to list all of the directories under a path other than the current one, change the . to that other path.
If you want to exclude certain directories, you can filter them out with a negative condition:
find . -type d ! -name "~snapshot" > list.txt
As well as find listed in other answers, better shells allow both recurvsive globs and filtering of glob matches, so in zsh for example...
ls -lad **/*(/)
...lists all directories while keeping all the "-l" details that you want, which you'd otherwise need to recreate using something like...
find . -type d -exec ls -ld {} \;
(not quite as easy as the other answers suggest)
The benefit of find is that it's more independent of the shell - more portable, even for system() calls from within a C/C++ program etc..

Change filenames to lowercase in Ubuntu in all subdirectories [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I know it's been asked but what I've found has not worked out so far.
The closet I came is this : rename -n 'y[A-Z]/[a-z]/' *
which works for the current directory. I'm not too good at Linux terminal so what
should I add to this command to apply it to all of the files in all the sub-directories from which I am in, thanks!
Here's one way using find and tr:
for i in $(find . -type f -name "*[A-Z]*"); do mv "$i" "$(echo $i | tr A-Z a-z)"; done
Edit; added: -name "*[A-Z]*"
This ensures that only files with capital letters are found. For example, if files with only lowercase letters are found and moved to the same file, mv will display the are the same file error.
Perl has a locale-aware lc() function which might work better:
find . -type f | perl -n -e 'chomp; system("mv", $_, lc($_))'
Note that this script handles whitespace in filenames, but not newlines. And there's no protection against collisions, if you have "ASDF.txt" and "asdf.txt" one is going to get clobbered.

Find size of directories/subdirectories [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
How do I find the total size of directories and sub directories within my current directory that are more than 2 years old or less than 2 years old
Thanks
touch -d "2010-02-06" 20120206.file
du -ks `find . -type d -anewer 20120206.file` | awk '{s+=$1} END {printf("%20i\n",s)}'
du -ks `find . -type d ! -anewer 20120206.file` | awk '{s+=$1} END {printf("%20i\n",s)}'
might work for you. The first du... prints the newer than dirsize sum.
1st command created the file 20120206.file with the specified creation date (two years ago)
2nd and 3rd command parts:
the ` encapsulated find searches for every directory (-type d) from the current directory (.), and checkes if the directory is newer than the specified file, if so prints its name
du -ks prints its arguments size (and names) in kilobytes
the awk reads the previously printed output and summarizes the first column
Please do read man awk, man find, man du.

Resources