Psychz - Amol
Votes: 0Posted On: Aug 01, 2019 06:04:49
In Linux operating system, the 'find' command allows you to search for files. Even if you know the approximate filenames. The simplest form of the command searches for files in the current directory and recursively through its subdirectories that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria.
If you want to search for folders/directories you can use following descriptor that you can use to specify the type of file are here:
# find / -type d -name "folder_name"
In the above case we have performed search for a directory under root directory '/'
Now we will see how to find the largest folders in the Linux file system using 'du' command.
root@user1:# du -a /home | sort -n -r | head -n 10
Output
53999 /home/user1
53999 /home
49755 /home/user1/scripts
49751 /home/user1/scripts/democontent
40111 /home/user1/scripts/democontent/rest-Api
39367 /home/user1/scripts/democontent/tools/modules
23252 /home/user1/scripts/democontent/tools/modules/npm
19753 /home/user1/scripts/democontent/tools/modules/npm/node_modules
8444 /home/user1/scripts/democontent/.git
7564 /home/user1/scripts/democontent/.git/objects/pack
root@user1:#
The Parameters used above and their usage/significance
du : Estimate file space usage.
a : Displays all files and folders.
sort : Sort lines of text files (the output in this case)
-n : Compare according to string numerical value.
-r : Reverse the result of comparisons.
head : Output the first part of files.
-n : Print the first ‘n’ lines. (In our case, We displayed first 10 lines).
| (known as pipe) : lets you use two or more commands such that output of one command serves as input to the next.
Hope you find above information helpful and informative. Kindly upvote this response if you like it.