Finding files in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding files in directory
# 1  
Old 08-07-2010
Finding files in directory

Hi,

I need help in writing shell script to accomplish the following.

1.I've one text file which contains list of batch numbers like b1.dat,b2.dat,b3.dat...

2.I've the same files along with other files present in some directory.i.e 1.dat,2.dat,3.dat,4.dat,5.dat... present in some directory.

3.I need to write shell script which will find the files present in the step1 text file under the directory of files in Step2 for every 1 hour and if the same files are found copy the files to some other location and delete the entry of that file in the step1 text file.

Please advise if any body has any solution.

Thanks,
Kumar
# 2  
Old 08-07-2010
What have you tried so far?
# 3  
Old 08-07-2010
I'm not 100% sure what you're asking for but I think you're saying you have a file structure that looks like:

directory
- 1.dat file
- 2.dat file
- b1.dat file
- b2.dat file

And you want to grab only the b{1,2}.dat ?

OR

Are you saying you want to see if b1.dat and 1.dat are alike and if they are just remove the b1.dat and keep the 1.dat (IF a similar file exists).

Really having a hard time understanding your requirements

---------- Post updated at 08:20 AM ---------- Previous update was at 08:20 AM ----------

I'm not 100% sure what you're asking for but I think you're saying you have a file structure that looks like:

directory
- 1.dat file
- 2.dat file
- b1.dat file
- b2.dat file

And you want to grab only the b{1,2}.dat ?

OR

Are you saying you want to see if b1.dat and 1.dat are alike and if they are just remove the b1.dat and keep the 1.dat (IF a similar file exists).

Really having a hard time understanding your requirements
# 4  
Old 08-09-2010
Code:
CurDir=/PATH1
OtherDIR=/PATH2

cd $Curdir

for file in $(cat step1.text.txt)
do 
  if [ -f $OtherDIR/$file ] ; then
      cp $file $OtherDIR/$file
      rm $file 
  fi
done

test with sample files first, then put it in cronjob.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Finding files older than x days within directory with spaces

Hi, I am trying to run a command that finds all files over x amount of days, issue is one of the directories has spaces within it. find /files/target directory/*/* -type f -mtime +60 When running the above the usual error message is thrown back + find '/files/target\' 'directory/*/*' -type... (1 Reply)
Discussion started by: Ads89
1 Replies

2. Shell Programming and Scripting

Finding non-existing words in a list of files in a directory and its sub-directories

Hi All, I have a list of words (these are actually a list of database table names separated by comma). Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories. Sample list of words:... (8 Replies)
Discussion started by: Bhanu Dhulipudi
8 Replies

3. Shell Programming and Scripting

Finding files in directory with similar names

So, I have a directory tree that has many files named thusly: X_REVY.PDF I need to find any files that have the same X portion (which can be nearly anything) as any another file (in any directory) but have different Y portions (which can be any number from 1-99). I then need it to return... (3 Replies)
Discussion started by: Kamezero
3 Replies

4. UNIX for Dummies Questions & Answers

Finding the same pattern in three consecutive lines in several files in a directory

I know how to search for a pattern/regular expression in many files that I have in a directory. For example, by doing this: grep -Ril "News/U.S." . I can find which files contain the pattern "News/U.S." in a directory. I am unable to accomplish about how to extend this code so that it can... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

Finding the executable files of a directory using Grep

Hi guys, Can you please help me print all the executable files of a directory(in this case /home) using grep? All i know is that this command should do it but it doesnt... ls -l ~ | grep -..x it shows me the following mesage grep: invalid option -- '.' Χρήση: grep ... ΥΠΟΔΕΙΓΜΑ ... (3 Replies)
Discussion started by: jimas13
3 Replies

6. Shell Programming and Scripting

finding the 5 newest files in a directory

I have a folder that has new files created everyday, is there a way i can filter them so that only the 5 newest files are displayed? I'm hoping this can be done by a one liner without a script. for example my directory contains -rw-r--r-- 1 root root 0 Jun 24 08:34 file112 -rw-r--r-- 1 root... (2 Replies)
Discussion started by: zerofire123
2 Replies

7. Shell Programming and Scripting

Finding all the files in a directory

I need to find all the files with a given file name present in the sub directories and execute a script on each file For example In the directory source , I need to find all the files named test and execute the script run.sh Can anyone please help me on this (4 Replies)
Discussion started by: prav076
4 Replies

8. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

9. Shell Programming and Scripting

finding 0 byte files in current directory only

Hi Gurus, I have a directory A, which has some 0 byte files in it. This directory also has a subdirectory B which also has some 0 byte files in it. The problem: I only need to find out the names of the 0 byte files in the directory A. I'm using the following command find . -name *.zip... (6 Replies)
Discussion started by: ramky79
6 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question