find

 

basic use

find . -name Makefile

=> zoekt al de files met de naam Makefile,vervang (deel) van Makefile door * om resultaat uit te breiden

Zoek in huidige dir naar filenames:
find ./ -type f -iname "FCSWriteDome.c"

md5sum bepalen recursief

find . -type f -exec md5sum {} >md5sum.txt \;

 

How to remove files with special characters in Linux


To remove a file with dashes, slashes or other special characters, the easiest way is to access the file using its inode.
To get the inode of a file, just do a ls -li. When you have that number, use find to delete the file using the following command:

 find . -inum [inode] -exec rm -i {} \;

 

Remove entire line containing string in a file

Q I need to grep for a particular 'string' in a file and remove the entire line where the occurrence of the string is found. I want it to work across with a collection of files. Can you help?
 
A It is possible to use grep for this: grep -v string file will output all lines that do not contain the string. But sed is a more suitable tool for batch editing.
 sed --in-place '/some string/d' myfile

 will delete all lines containing 'some string' To process a collection of files, you need to use a for loop (or find) because sed 's --in-place option only works on single files.
 One of these commands will do it:
 
  for f in *.txt; do sed --in-place '/some string/d'
 "$f"; done
 find -name '*.txt' -exec sed --in-place=.bak '/some
 string/d' "{}" ';'
 
Adding =.bak in the latter example makes sed save a backup of the original file before modifying it.

 

Is there a way to check if there are any symlinks pointing to a particular folder?

I'd use the find command.
find . -lname /particular/folder

 That will recursively search the current directory for symlinks to /particular/folder. Note that it will only find absolute symlinks. A similar command can be used to search for all symlinks pointing at objects called "folder":
find . -lname '*folder'

 From there you would need to weed out any false positives.

Zoek in huidige dir naar alle files die een bepaalde string bevatten :

find . -type f -print0 | xargs -r0 grep -F 'LogC'

Met
---
-type f       regular file

-print0

True; print the full file name on the standard output, followed by a null character (instead of the newline character that '-print' uses).
This allows file names that contain newlines or other types of white space to be correctly interpreted by programs that process the find output. 
This option corresponds to the '-0' option of xargs.
 vb.  [root@E-DBS2 unl_051009]# find . -name "NS" -print
  ./NS
  ./NS/NS
  [root@E-DBS2 unl_051009]# find . -name "NS" -print0
  ./NS./NS/NS[root@E-DBS2 unl_051009]# ll
  total 4
  drwxr-xr-x 7 root root 4096 Oct  5 14:55 NS
  [root@E-DBS2 unl_051009]#

xargs   build and execute command lines from standard input

Because  Unix filenames can contain blanks and newlines, this default behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs.
In these situations it is better to use the '-0' option, which prevents such problems:
 --null, -0
 Input  items  are  terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is
 taken literally).Disables the end of file string, which is treated like any other argument.
 Useful when input items might contain white space,quote marks,or backslashes.
 The GNU find -print0 option produces input suitable for this mode.

--no-run-if-empty, -r
If the standard input does not contain any nonblanks, do not run the command.  Normally, the command is run once even if there is no input.
This option is a GNU extension.

grep  print lines matching a pattern
  -F, --fixed-strings.Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.

 

Zoek in huidige dir EN DE SUBDIRS ERVAN naar alle dirs die een bepaalde dirnaam bevatten

find ./ -type d -iname "*omca*"

Examples

find -name 'mypage.htm'

In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory.

find / -name 'mypage.htm'

In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root.

find -name 'file*'

In the above example the system would search for any file beginning with file in the current directory and any subdirectory.

find -name '*' -size +1000k

In the above example the system would search for any file that is larger then 1000k.

[root@E-DBS2 ~]# find / -name *schema-cs-commercial_services.xsd*
/from_bck/ns/nsisc/webapps/schemas/1.0/schema-cs-commercial_services.xsd
/software/nsisc/webapps/schemas/1.0/schema-cs-commercial_services.xsd
/project/nsisc/webapps/schemas/1.0/schema-cs-commercial_services.xsd
/project/nsisc_prev/webapps/schemas/1.0/schema-cs-commercial_services.xsd
/var/lib/tomcat5/webapps/schemas/1.0/schema-cs-commercial_services.xsd


Zoek in een path (bvb .) naar alle files die de string Rtap bevatten en druk de locatie af.

[root@DS2 nsisc]# find . -type f -exec grep -H "RtapEnv" {} \;
./scripts/backup.sh:RTAPFILES="RtapDiskDb RtapEnvTable RtapHdrSnap0 RtapHdrSnap1 RtapRamSnap0 RtapRamSnap1 RtapSnapCtrl"
Binary file ./bin/EnableSnap matches
Binary file ./bin/Wdb matches
Binary file ./bin/RCE_ward matches
Binary file ./bin/CFIlock matches
Binary file ./bin/FcsSendMsg matches
Binary file ./bin/RCE_leffe matches
Binary file ./bin/RtapLoader matches
Binary file ./bin/Rdb matches
Binary file ./bin/DisableSnap matches
Binary file ./bin/VideoSelProc-1.3 matches
Binary file ./bin/FcsDisplayer matches
Binary file ./bin/RtapWDInterface matches
Binary file ./bin/RtapExtractor matches
./env/RtapEnvTable: 0 0 Y P N A N 32767 128 RtapEnvLookup
./env/RtapEnvTable:# 0 0 Y P N A N 32767 128 RtapEnvLookup


Vind alle stationsnamen terug die aan het criterium " hebben een stationsnaam " voldoen:

=> find randstadnoord/ -maxdepth 2 -type f -print0 | xargs -r0 grep -A 5 'stationsNaam' > rn_lijst

met:

find -maxdepth omdat anders te diep wordt vertakt (ook de NKzuilen,AIZuilen,etc. worden meegenomen)
grep -A 5 neemt de vijf lijnen erna mee


Tel het aantal files in een bepaalde directory en alle subdirectories.

find ./dir -type f |wc -l

=====================================================================================
files wissen mbv find

cd ~ns/env
find .  ! -newer analoog.rep -exec rm -rf {} \;

Als je zo'n commando's zou gebruiken: zeer goed opletten dat je niet per ongeluk het verkeerde wist!
Desnood eers tls -l ipv rm -rf of een backup van directory waar je mee bezig bent.
Altijd checken in welke dir je bezig bent.