Posts

Showing posts from January, 2018

How to find smallest and largest directories and files in linux

Image
How to find smallest and largest directories and files in linux. Commands to know: there is no single command to find the largest directories and files. However, we can use some combination of commands to achieve this task. 1. du -a | sort -n -r | head -n 10 du -ah | sort -n -r | head -n 10 - human readable format. it shows files in ascending order  Where, du  : Disk usage command that estimates file space usage -a  : Displays all directories and files sort  : Sort lines of text files -n  : Compare according to string numerical value -r  : Reverse the result of comparisons head  : Output the first part of files -n 10  : Print the first 10 2. du -ah /var/log | sort -n -r | head -n 10  to show file sizes in ascending order in /var/log in human readable format 3.  Let us find out the largest files in the current working directory and its sub-directories: find -printf  '%s%p \n' | sort -nr | head -10 Also, you can skip the d

Usage of find command

 Usage of find command The Linux  Find Command  is one of the most important and much used command in Linux sytems. Find command used to search and locate list of files and directories based on conditions you specify for files that match the arguments. Find can be used in variety of conditions like you can find files by  permissions ,  users ,  groups ,  file type ,  date ,  size  and other possible criteria. 1. find files using name (in current directory) find . -name neelu.txt ./neelu.txt find /home -name neelu.txt (in home directory) 2. find files using name and ignore case. find /home -iname techmint.txt 3. find directories using name (done by inserting flag -type d) find /var/log -type d -name divya 4. find file types using name (done by inserting flag -type f) find /var/log -type f -name web.php (find php files) 5. find files with 777 permissions find /etc -type f -perm 777 -print 6. find files without 777 permissions find /

How to find size of directory in linux

Image
How to find size of directory in linux Commands to know: To find out the size of a directory, we will use  ‘du’  command. du stands for  d isk  u sage. Syntax: du  <option>  <filename> du  <option>  --files0-from=F for ex see log directory: du /var/log you can use du -h to see files size in human readable format du -k for kilo bytes du -m for megabytes  1. To find which sub-directories consume how much disk size.  du -h --max-depth=1 | sort -hr sort -hr to display o/p in descending order you can change the value of --max-depth=x x= 0,1,2  etc  To display the disk usage of all items including files and directories, use  -a  flag. ex: du -ah /var/log 2. display the size of multiple directories at once as shown below. du <directory1> <directory2> 3.  to check the total disk space used by a particular directory, use the  -s  flag. du -sh /var