reading filename in nested directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading filename in nested directories
# 1  
Old 09-30-2012
reading filename in nested directories

Hi all,
I have some directory structure as
Code:
$ls -ltr
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:34 650
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 652
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 640
drwxr-xr-x 1 mscprod us_msc512 May 10 09:13 654
$ cd 650/
$ls
fileabc.root

and within each directory has some file with extension *root.

I want to have all this information in a txt file in the given form
Code:
/complete path till 650/file1.root
/complete path till 652/file2.root

and so on for all directories.

Thanks in advance
# 2  
Old 09-30-2012
Quote:
Originally Posted by emily
Hi all,
I have some directory structure as
Code:
$ls -ltr
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:34 650
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 652
drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 640
drwxr-xr-x 1 mscprod us_msc512 May 10 09:13 654
$ cd 650/
$ls
fileabc.root

and within each directory has some file with extension *root.

I want to have all this information in a txt file in the given form
Code:
/complete path till 650/file1.root
/complete path till 652/file2.root

and so on for all directories.

Thanks in advance
Code:
find /path -iname "*root"

This User Gave Thanks to the_gripmaster For This Post:
# 3  
Old 09-30-2012
perfect, thanks a lot SmilieSmilie

Quote:
Originally Posted by the_gripmaster
Code:
find /path -iname "*root"

# 4  
Old 09-30-2012
Quote:
Originally Posted by emily
perfect, thanks a lot SmilieSmilie
A slight improvement

Code:
find /path -name "*.root"

# 5  
Old 09-30-2012
Quote:
Originally Posted by the_gripmaster
A slight improvement

Code:
find /path -name "*.root"


Hi,
both command seems to serve the purpose. Then what is the difference?

Thanks
# 6  
Old 09-30-2012
1) *.root means any string ending with "root" after "."
2) "*root" means any string ending with "root"

create 2 files a) abcroot and b) abc.root
and note the difference in both commands
# 7  
Old 09-30-2012
Hi,
Thanks aahish,
But that I know. I was asking for the difference in "iname" and "name".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Work on multiple directories, same filename

Can this be done and if yes how? I have 10 directories that end with the name 'cuff' eg dir1-cuff , dir2-cuff All these directories have a file named xyz.gtf How do I run the same code for each directory and print an output inside the directory something like for dir in *cuff... (3 Replies)
Discussion started by: newbie83
3 Replies

2. Shell Programming and Scripting

Need help in reading a filename

Hi Guys, I have the following input. test_junk_file__20120210092009.txt latest_file__20120210092009.txt side_load_junk_file__20120210092009.txt I need to exclude the timestamp part from the file. so, the output should be as follows. test_junk_file.txt latest_file.txt... (7 Replies)
Discussion started by: mac4rfree
7 Replies

3. Homework & Coursework Questions

Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data: I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no... (0 Replies)
Discussion started by: ds7202
0 Replies

4. Shell Programming and Scripting

Find directories that contains more than n matches of a certain filename

I need to construct a command that finds directories which contains more than n matches of a certain filename. E.g. I have many directories at different locations and want to find all directories that has 2 or more .dat-files. I thought of using find and maybe the exec parameter to issue an... (5 Replies)
Discussion started by: odyssey
5 Replies

5. Shell Programming and Scripting

searching for a filename in ALL directories

Hi, I am searching for a file named "Backup.txt" but I don't know in which directory it is. Can someone tell me, how I can search recursiv in all directories and subdirectories? thanks (2 Replies)
Discussion started by: ABE2202
2 Replies

6. UNIX for Dummies Questions & Answers

assingn a variable a filename and then reading it in

Im trying to set a filename to a variable and then read the file in using the variable but im getting a syntax error. any ideas? #!/bin/bash function scanFile() { while read $1 do echo $filename done } file1=report.log scanFile() $file1 (3 Replies)
Discussion started by: magnia
3 Replies

7. UNIX for Dummies Questions & Answers

Reading filename from directory

I am using the following code to read filename from the directory: for i in ` ls $inputDir | grep $partialName*.csv` do echo $i done But the echo is giving me the following: ls | grep cm_ctx*.csv instead of the full filename "cm_ctx_2009_07_15_17_18.csv" Any ideas anyone? I... (2 Replies)
Discussion started by: khanvader
2 Replies

8. Shell Programming and Scripting

file reading in nested loops

I have to to read files simultaneously in two nested loops,but am getting error can anyone do the needful. useridFile=userIds.txt fname=kiran.txt exec<$useridFile while read line do echo "User IDs are..$line" USER_ID=$line REMOTE_DIR_LOCATION="/home/test/$USER_ID" SOURCE_DIR=$USER_ID... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

9. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

10. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies
Login or Register to Ask a Question