How to list the names of the files from all the subdirectories?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to list the names of the files from all the subdirectories?
# 1  
Old 10-18-2014
How to list the names of the files from all the subdirectories?

Hi, I'm currently trying to print the names of all the .txt files in the subdirectories that contain the string I'm searching.

I tried with this code, but it seems that it searches for the names that matches the string instead of searching for the string in the individual files and printing the name of that file that contains the string
Code:
find . -type f | grep "12/15/2001"

I also tried this code but nothing happens.
Code:
find . type f | grep -Ril "12/15/2001"

Can anyone help me?Smilie

---------- Post updated at 06:13 PM ---------- Previous update was at 06:07 PM ----------

Also, I tried this code and it seems to work, but only if the argument is "2010"
If I use "11/27/2010" as arguments it doesn't print anything.Smilie

Code:
grep "11/27/2010" * -lR

# 2  
Old 10-18-2014
Code:
 grep "12/15/2001" $(find . -type f)

Consider this:
Code:
grep "12/15/2001" *

or
Code:
 grep -r "12/15/2001" *

This User Gave Thanks to Aia For This Post:
# 3  
Old 10-18-2014
Thanks you're the best!
Also, I just found out the last code I put out works and the reason it didn't print anything was because the string didn't exist in any of the files lol
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

List all files in subdirectories which are modifiled recently.

Hello, I wanted to list all files in subdirectories which are modifiled recently. need to display all files with full details like hpw it display with ls -l ( date, size,..) Thanks Bala (3 Replies)
Discussion started by: balareddy
3 Replies

2. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

3. Shell Programming and Scripting

How to list all Subdirectories and files with its full path in a parent directory?

How to list all Subdirectories and files with its full path in a parent directory? (1 Reply)
Discussion started by: johnveslin
1 Replies

4. Shell Programming and Scripting

Remove files from subdirectories given a list of filenames

Dear all, I have a dir structure like main_dir At_nn Ag_js Nf_hc .... mcd32 mgd43... mcd32 mgd43... mcd32 mgd43... and each subdir (e.g. mcd32, mgd43) contains files. Now, i... (15 Replies)
Discussion started by: yogeshkumkar
15 Replies

5. Shell Programming and Scripting

Help with moving files with same names from subdirectories?

I was wondering if someone could help me with this: I have multiple directories and subdirectories with files in them. I need to move all files from all directories and subdirectories into one root directory. However, when i do find /home/user -mindepth 1 -iname "*" -type f -exec mv {} . \; ... (3 Replies)
Discussion started by: r4v3n
3 Replies

6. Shell Programming and Scripting

how to copy files followed by list of names of all the files in /etc?

....... (2 Replies)
Discussion started by: pcbuilder
2 Replies

7. Shell Programming and Scripting

Filter only gz files from list of subdirectories

Hi, I have a very big directory structure that consists of many sub-directories inside.There are around 50 ".gz" files under this dir structure. I want to copy all the gz files alone to a seperate location. Plz help me. (2 Replies)
Discussion started by: villain41
2 Replies

8. UNIX for Dummies Questions & Answers

show a list of files whose names begin

How do I show a list of files whose names begin with c and are two characters long. ls {2\} ? thanks (10 Replies)
Discussion started by: JudoMan
10 Replies

9. UNIX for Dummies Questions & Answers

list the files but exclude the files in subdirectories

If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also proj/code/test.sh proj/code/test1.c proj/code/unix... (8 Replies)
Discussion started by: shyjuezy
8 Replies

10. UNIX for Dummies Questions & Answers

list largest files in a directory & its subdirectories

I need to find the largest files in a directory & it's subdirectories. I'm not sure what options on ls -l will work to give me this. or is there another way to do this? Thanks, igidttam (6 Replies)
Discussion started by: igidttam
6 Replies
Login or Register to Ask a Question