Monday, December 1, 2014

40 important Find Commands for Administrator | Find Command Examples for Administrator


1 => To find Files Using Name in Current Directory


#find . -name nirmal.jpg

2 => To find all .jpg files using name under Directory


# find /home -name nirmal.jpg

3 => To find files using name and Ignoring Case


#find /home -iname nirmal.txt
/home/nirmal/nirmal.txt
/home/nirmal/NIRMAL.TXT

4 => To find all directories using directory name in / path.


# find / -type d -name Nirmal

5 => To find all files with 777 Permissions in directory .


# find /opt -type f -perm 0777 -print

6 => To find all files without 777 Permissions in directory.


# find / -type f ! -perm 777

7 => To find all the SGID bit files whose permissions set to 654.


# find /opt -perm 2644

8 => To find all sticky bit files with 551 Permissions in /opt


# find /opt -perm 1551

9 => To find SUID files in directory


# find /opt -perm /u=s

10 => To find SGID files in directory


# find / -perm /g+s

11 => To find Read Only Files


# find / -perm /u=r

12 => To find Executable Files


# find / -perm /a=x

13 => To find all 777 permission files and use chmod command to set permissions to 644.


# find / -type f -perm 0777 -print -exec chmod 644 {} \;

14 => To find all 777 permission directories and use chmod command to set permissions to 755.


# find / -type d -perm 777 -print -exec chmod 755 {} \;

15 => To find a single file called nirmal.jpg and remove it.


# find . -type f -name "nirmal.jpg" -exec rm -f {} \;

16 => To find and remove all mp4 files


#find . -type f -name "*.mp4" -exec rm -f {} \;

17 => To find all hidden files,


# find /opt -type f -name ".*"

18 => To find all or single file called nirmal.jpg under /opt directory of owner root.


# find / -user root -name nirmal.jpg

19 => To find all files that belongs to group nirmal under /home directory.


# find /home -group nirmal

20 => To find Last 50 Days Modified Files.


# find /opt -mtime 50

21 => To find last 50-60 Days modified files


# find /opt -mtime +50 –mtime -60

22 => To find and delete all file more then 30 days old 


find /opt -type f -mtime +30 -exec rm {} \;

23 => Find Changed Files in Last 2 Hour


# find /opt -cmin -120

24 => To find all the files which are modified in last 2 hour.


# find /opt -mmin -60

25 => To find all the files which are accessed in last 1 hour.


# find /opt -amin -60

26 => To find all 50MB files in /opt.


# find /opt -size 50M

27 => To find all the files which are greater than 50MB .


# find /opt -size +50M

28 => To find all the files which are greater than 50MB and less than 100MB.


# find /opt -size +50M -size -100M

29 => To find all greater than 100MB files and delete them using one single command.


# find /opt -size +100M -exec rm -rf {} \;

30 => To find all .mp4 files with more than 100MB and delete them using one single command.


# find / -type f -name *.mp4 -size +100M -exec rm {} \;

31 => To find empty folders with find command.


#find /opt -empty -type d

32 => To find all empty files and folders with find command.


#find /opt -depth -empty

33 => To find empty files with find command.


#find /opt -f -empty

34 => To find all directory and give permission according to your need.


#find /opt/ -type d -print0 | xargs -0 chmod 3111

35 => To find last modified file date in folder .


#find /opt/ -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2-
| head

36 => To find all .jpg file and search space in filename if found remove the space from filename.


#find /home/nirmal/ -name *.jpg -exec rename "s/ //g" {} \;

37 => To find and show which file not have space in file name.


#find /home/nirmal -type f | grep -v “ “

38 => To find and show which file have space in file name.


#find /home/nirmal -type f | grep “ “

39 => To find file which have backslash in filename and remove backclash from filename .


#find /home/nirmal/ -type f -exec bash -c 'x="{}" y=$(sed "s/[\]//g" <<< "$x") && mv -v "$x" "$y"' \;

40 => To find folder which have backslash in folder name and remove backclash from folder name .


#find /home/nirmal/ -type d -exec bash -c 'x="{}" y=$(sed "s/[\]//g" <<< "$x") && mv -v "$x" "$y"' \;

41 => To search for files created on a specific date


#find /opt/lampp/htdocs/ -type f -newermt 2014-11-07 ! -newermt 2014-11-08

1 comment:

Installing Jenkins on RHEL 8 is a straightforward process. Here's a step-by-step guide

Introduction  Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines...