General :: Recursive Searching Files In Directory Matching Given Name?
Apr 16, 2010
I am writing a shell script that finds all files named <myFile> in a directory <dir> or any of its subdirectories, recursively. I also need to take care of symbolic links that may form cycles, to avoid infinite loops. I am not supposed to use find command for the same
I started writing the code but got stuck. I thought using recursion may be a smart way, but its not working.
Code:
#!/bin/sh
findFiles()
{
thisDIR=$1
#cd $thisDIR
code....
View 5 Replies
ADVERTISEMENT
Apr 3, 2010
I'm searching within Java files for some occurrence of a phrase:
find . -name '*.java' | xargs grep -l 'string'
How do I change this command to print to the shell all of the lines which contain a match?
View 4 Replies
View Related
Jul 22, 2010
What is the best and simplest way to compare two directory structures without actually comparing the data in files. This works fine:
diff -qr dir1 dir2
But it's really slow because it's comparing files too. Is there a switch for diff or another simple cli tool to do this?
View 4 Replies
View Related
Apr 20, 2011
I was trying to develop a script which needs to check the count of files on hourly basis and if it find any addition it has to sftp and send a email on the status with filenames and number of files copied via sftp. I will put it on cron to run every hour.
I'll use ls /abc|wc -l to count the no. of lines for the first time and from then whenever a new file will be inserted it'll copy that file to another location or I'll take the date of the files and whichever is having a new date that will be copied to another location.
View 7 Replies
View Related
Nov 20, 2010
I am a member of a group which has written a program whose source code is being held in a specific directory (~cs252/Assignments/basicAsst/project) and we want to go through and change the parameters for the function "sequentialInsert." My job is to find all occurances of the function call to "sequentialInsert" and to also list the files from where the code came from. Also, I have to be in the commandsAsst directory when I do this. I have tried grep and find combined together, and I am at a lost.
View 1 Replies
View Related
Jan 2, 2011
If I runls -R1I get a recursive listing of all files under the current directory.However, if I dols -R1 *.avi, ie I want to search only for files with the file descriptor .avi, I get an errorQuote:ls: cannot access *.avi:No such file or directorySo it seems I am using ls incorrectly. What's the correct way to use wild card pattern matching when using the -R switch? Or maybe that isn't possible?
View 2 Replies
View Related
Mar 23, 2011
I would like to make a cronjob who makes a tag.gz of everything inside a directory in a recursive way. BUT there is a HUGE directory full of jpg's. I don't want this one in the backup.Additional points if it can backup symbolic links.
View 2 Replies
View Related
Oct 28, 2009
find out a command to search among all *.dat files in a certain path (including subdirectories) looking for the following text in them:
Code:
--------------------------------------------------------------------------------
Elements with small area
Element Adjusted nodes
--------- --------------
16294 NO
17889 NO
and getting the list of elements with small area printed in a file "ErrorEl.txt". The output should have this form:
"/path/01/A.dat
bad-el#01
bad-el#02
[code]....
I know already how to find out the dat files containg a certain string
Code:
c=/path/
grep -R --include="*.dat" "Elements with small area" $c | cut -d: -f1>> ErrorEl.txt
but I don't know then how to get the element numbers(16294 and 17889 in the example above)
View 11 Replies
View Related
Mar 4, 2011
I would like to be able to recursively delete specific various files from a directory and sub-directories. For example:
Dir/
|_sub1/
|
|_ _rm *file1 *file2 *file3
[code]....
View 11 Replies
View Related
Oct 19, 2010
I have a directory that has a large number of files, around 1.5 million at this point. If I go to the directory and type in "ls filename" for a filename that I know exists, ls just hangs. I have let it run for over 20 minutes and it never does anything. Up until yesterday the directory was working fine through samba serving up files, but now it doesn't return anything. How to proceed from here?
View 7 Replies
View Related
Jan 18, 2011
How do I recursively generate a text file which has a list of all files on my server which contain a specific string anywhere in the files?
I know the following command can be used to replace a string recursively
find /var/www -type f -print0 | xargs -0 sed -i 's/old string/new string/g'
I do not want to replace the string, I just want a list of all files which contain the string.
View 4 Replies
View Related
May 17, 2010
I would like to search a specific directory and pull out filenames that have this pattern: "_bsc_" Then I want to do some processing and move the file to another directory
View 5 Replies
View Related
Mar 13, 2011
I have a requirement to list files using find command My folder contains below list of files with out extention.I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.
View 7 Replies
View Related
Feb 22, 2010
How can I remove all .swp files in all of my subdirectories under Linux?
View 4 Replies
View Related
Jul 19, 2011
If I wanted to copy all *.so files from src to dst I'd do:
cp src/*.so dst
However, I want to copy all *.so files from src and it's subdirs into dst.
View 2 Replies
View Related
Oct 18, 2009
I'm trying to do something very basic in bash. It's a kind of cross-reference matching between 2 files. I have a file1.txt. It's like this:
Code:
item1
item3
item4
...
I Have a file2.txt. It's like this:
Code:
item1 "Properties of item1"
item2 "Properties of item2"
item3 "Properties of item3"
item4 "Properties of item4"
item5 "Properties of item5"
...
My goal is to print out the lines in file2 that contains lines present in file1. I do:
Code:
for i in $(cat file1.txt); do grep $i file2.txt; done but I get no output. Will someone please tell me where am I mistaking?
View 3 Replies
View Related
Jun 29, 2010
is there a recursive shell or Perl script to delete files with the same name as the parent folder? i wish to include the starting folder name as argument to the script.
View 2 Replies
View Related
May 4, 2011
I have a file with joker character patterns:
./include/*
./src/*
etc.
From the current directory I would like to recursively get the list of files that do not match these patterns.
View 2 Replies
View Related
Feb 11, 2011
I have 2 massive duplicate dirs of the same format as below:
dir1
subdir1
file1
subdir2
file1
subdir3
file1
...
Dir2 is the same, but it has some newer files of the same name. I want to copy all file1's from Dir2 to the same name and folders in dir1. So basically something like:
cp -pr bkpDir1/*/*-big.gif Dir2/*/*-big.gif
This works for singular cases:
cp -pr bkpDir1/uniquesubdir/*-big.gif Dir2/uniquesubdir/*-big.gif
But not for wildcards:
cp -pr bkpDir1/subdir*/*-big.gif Dir2/subdir*/*-big.gif
Anyway the aim is to do the first cp above, I have tried a few options using find. In trying to show an example stumbled upon a way that worked, while in dir2:
find */*-big.gif | xargs -i cp -rp {} ../dir1/{}
Sure there are better ways also...
View 1 Replies
View Related
Sep 13, 2011
I have many files in a folder for example
Kiran.txt
Kiran1.txt
Kiran221.txt
Kiran144.txt
Time.csv
[Code]...
From this directory, I want to know how I could use grep to display files based on part of their filename - for example those starting with "Account" or those ending in ".sh".
View 4 Replies
View Related
May 18, 2011
I'm having problems with compiling recursive Makefiles in my directory structure:
My folder layout is:
top/|- one/|- one.c (With main function)|- zero.c|- two/|- two.cin my top folder the make file looks like:
Code:
MAKE_DIRECTORIES = one two
.PHONY: all
all: $(MAKE_DIRECTORIES)
.PHONY: $(MAKE_DIRECTORIES)
$(MAKE_DIRECTORIES):
@echo $@
$(MAKE) --directory=$@
in my one and two folder I have the following Makefile:
Code:
.PHONE: all
all:
@echo $@
$(CC) $(CFLAGS) *.c
But when I compile it from top folder: make
I get following output:
Code:
one
two
Which states that directory statement by echo in main Makefile is ok but the files are not compiled in one and two.
View 5 Replies
View Related
Nov 2, 2010
I am looking for all the files that contain the text string 'moo.sql'. I ran the following:
find . -name '*.php' | grep -lir 'moo.sql' *
Unfortunately it seems to return non-php files in addition to php files. I thought the find portion of this would filter the file names so grep would only search php files.
View 3 Replies
View Related
May 5, 2010
I'm a frequent user of grep. I know that I can recursively search a directory using the -r flag:
Code:
// will recursively search all files
grep -r 'some string' *
However, if I want to limit my search to PHP files, the -r flag is suddenly useless:
Code:
// for some reason, this only searches the PHP files in the current dir
grep -r 'some string' *.php
Any good way to recursively search a directory and its subdirs for a string but ONLY look at PHP or HTML files (and possibly TXT files too) ? I'm really hoping for a nice, short command that doesn't involve using an exclude file and which isn't really painful to type. I do this kind of search very frequently and have resorted to either searching EVERY file which is really slow (TAR and ZIP files really slow it down) OR typing repeated commands to search *.php, */*.php, etc.
View 6 Replies
View Related
Mar 3, 2011
Is it possible to search ALL files on a system for a specific text string? I've been messing around with grep without any luck.
View 2 Replies
View Related
Feb 28, 2011
I know grep can search recursively (ie through all subdirectories to the bottom of the directory tree), but is it possible to ask grep to only search say, 3 levels down? That means the current directory, any directories in the current directory, and within any directories within those?
View 1 Replies
View Related
Jan 31, 2011
I have word like initialize_my_var:in sample.php and I included three library files, take it as a.php, b.php, c.php ,I really don't know where my label(initialize_my_var:)definition is present in my library files, is it possible with a pattern matching string to find which library file really have the exact term "initialize_my_var:" , I'm really looking for an exact pattern match.
View 1 Replies
View Related
Jun 27, 2011
I just want to know if we can search for a particular string in all files of a particular folder in linux. if a folder has 100files only that hundred files needs to be checked for a particular string.
View 5 Replies
View Related
Dec 31, 2010
I am looking for a way to search for large numbers in text files and print the nearby lines.
For example if I had a text file like:
Event: 11
blah: 3
blah: 41 bleh: 19
Event: 2
blah: 31
[Code].....
View 1 Replies
View Related
Sep 11, 2009
I am trying to do a find/grep/wc command to find matching files, print the filename and then the word count of a specific pattern per file. Here is my best (non-working) attempt so far:
wc `find . ( -name "*.as" -o -name "*.mxml" ) -exec grep -H HeightResizableList {}` ;
View 10 Replies
View Related
May 16, 2010
Way to test permissions on all files/folders into a folder recursive, then if those are not user:user then do :
Code:
chown user:user thatconcernedfile
The problem with that
Code:
chown user:user -R /folder
is that it is doing changes on file permissions whihch are already ok. If you wanna maintain a specific permission on a folder this is really not good this :
Code:
while [ 1 ] ; do
chown user:user -R /folder
# /folder contains 6.0 Tb
sleep 2s
done
View 1 Replies
View Related