http://www.technicalpage.net/search/label/SQL

find command in UNIX


find command in UNIX --- searches a file or folder

find  -name  fileName.txt   --- will search the file in the current directory/folder and its sub folders.
or
find  .   -name  fileName.txt  
or
find  ./    -name  fileName.txt  
Output:
./ fileName.txt  


find  ./folder1   -name   fileName.txt  --- will search  the file in folder1  and its sub folders.
Output:
./folder1/ fileName.txt 


find   ./   -name  '*.txt'  --- displays  all the ".txt " files in the present folder and its sub folders.
or
find   -name   '*.txt'
Output:
Output will be something like this :
./file1.txt
./folder1/file2.txt
./folder1/folder2/file3.txt
. ..


find  -empty  ---  search empty files and empty directories, including hidden ones, from present folder and sub folders.
Output:
Output will be something like this :
./file1
./folder1/file2.txt
./folder1/folder2/file3.txt
./folderEmpty
. ..


find   -perm  777   ---  search file with the permission 777 in present folder and sub folders.
Output :
Output will be something like this :
./file1
./folder1/file2.txt
./folder1/folder2/file3.txt
.. ..


ignore case sensitivity :
find  -name  file1
Output  ------    ./file1

find  -name  File1
Output  ------    ./File1

find  -iname  File1
Output  ------   
./file1
./File1


find -type d   ----  finds directories only in present folder and sub folders, includes hidden also.


find -type d -name  'dir*'  --- finds directories in present folder and sub folders , name starting with "dir" , includes non hidden directories inside hidden directories  also but not hidden folder alone.


find  -type  d  -name  '. *'  --- finds  hidden directories only in present folder and sub folders.


To create hidden directory : mkdir  .folderName
To switch to hidden directory : cd .folderName
To switch back from the hidden folder : cd ..


find  -type  f   --- find only files in present folder and sub folders.


find . -type f -name "FileName1" -exec rm -f {} \;  --- deletes the file FileName1 from present directory and its sub directories.


find   -user   Ram   --- finds files and folders belonging to the user Ram in present folder and sub folders, use  " -type  f"  if you want only files.


find   -group  AAA   --- finds files and folders belonging to the group AAA in present folder and sub folders, use  " -type  f"  if you want only files.


file modified/accessed  n days before :
find   .  -type  f   -mtime   5  --- displays files modified  5 days before.
find   .  -type  f   -atime   5  --- displays files accessed   5 days before.


AND operation:
find . -type f -mtime 5  -atime 10


OR operation:
find . -type f -mtime 5  -o   -mtime 10


find   -name   '*.txt'    -o    -name    '*.out'  --- find files with extensions ".txt" or ".out"  from  current directory or sub directories


find   -newer   fileName1   ---  find files newer than fileName1

No comments:

Post a Comment