show all text files in directories and subdirectories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers show all text files in directories and subdirectories
# 1  
Old 02-06-2012
show all text files in directories and subdirectories

Hi!

I am trying to find all text files in my home directory that contain the string "C-d" so I tyied this :
Code:
cd ~

find . -type f -exec grep -l "C-d" {} +

but it took very long so I tryed this :
Code:
 ls -aR | xargs file |grep text

but it didn't descend in the directories and it said :

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

What do I have to do to see all text files in my home directory?

Thanks,

Miha

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data
# 2  
Old 02-06-2012
I bet the reason its taking so long is that it is checking ALL files for your string, not just text files. If your text files have a common extension, try this:
Code:
find . -name "*.txt" -type f -exec grep "C-d" {} \;

# 3  
Old 02-06-2012
They don't.
# 4  
Old 02-06-2012
Code:
find . -type f -exec grep -l "C-d" {} +

Looks ok to me providing all the files found by "find" are to be searched.

If you have a significant proportion of non-text files or irrelevant large files then it can be worth checking each file with the "file" command and/or using the "-size +limit" parameter to "find".
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Zip all the files including directories - subdirectories

Hi, Is is possible to zip a folder and all its contents within the folder ( including sub-directories and files) into a zip file? and can regain the same structure if unzipped? Thanks (6 Replies)
Discussion started by: rudoraj
6 Replies

2. UNIX for Dummies Questions & Answers

Find directories without subdirectories

Hello, I have to find all directories, which contain files, but dont have subdirectories. For example if i have tree like: ├── kat11 │ ├── kat21 │ │ └── Dokument\ bez\ nazwy │ └── kat22 │ ├── kat31 │ │ └── Dokument\ bez\ nazwy │ └── kat32 │ └──... (13 Replies)
Discussion started by: eValker
13 Replies

3. UNIX for Dummies Questions & Answers

Help with untarring multiple files from tarred directories and subdirectories

Hi, I want to untar all log files from following tarred directory hierarchy Log_files.tar.gz/subject*.tar.gz/project*/*.log It means there are subject1.tar.gz to subject9.tar.gz and in those tarred subect directories there are project1 - project5 directories and in those directories there... (2 Replies)
Discussion started by: rv_trojan
2 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripts - Show all directories with full information ( and no files)

Hello all, i'm stumped.... I need to list all directories with all there info and exclude the files, then vice versa. I am not sure if I need to string several ls commands together or how to even do that. I believe I need to do some variation of ls -l but need to figure out how to take out the... (5 Replies)
Discussion started by: citizencro
5 Replies

5. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies

6. Shell Programming and Scripting

backup of directories and subdirectories

Hello I'm new to the area Bash scripting and that is why I have a search script that is run on my unix server and always when I start the server or every 24 hours The script will create backups of directories and subdirectories I never found what I'm here make a new thread ... (1 Reply)
Discussion started by: HansWurst
1 Replies

7. Shell Programming and Scripting

Listing directories and subdirectories

How can list the directories and the subdirectories in a folder. It is possible with a single UNIX command. For example i have a folder named "archive" and another folder named "0808" and then multiple folders are there ... Can i list all the directories and subdirectories in the folder... (6 Replies)
Discussion started by: karansachdeva
6 Replies

8. Shell Programming and Scripting

Display only subdirectories from given directories

Hi Genius, I would like to display all the subdirectories only with timestamp. For exmple: Given Directory : orabkup /orabkup total 11365112 drwxr-xr-x 9 oracle oradba 256 Jan 03 16:01 db1 /orabkup/db1: total 0 drwxr-xr-x 2 oracle oradba 256 Jan 03 16:01... (8 Replies)
Discussion started by: HAA
8 Replies

9. UNIX for Dummies Questions & Answers

Permissions for Directories and Subdirectories

Is it possible to have a directory owned (by root) with permissions drwx------ and then have a sub directory of rwxrwxrwx. I know that this may be soo simple but I had no luck googling it. Thanks for your help (1 Reply)
Discussion started by: clancymf
1 Replies

10. Shell Programming and Scripting

How to Remove Ctrl M characters in files from directories and its subdirectories

Hi, How to recursively remove Ctrl M characters in files from a directory and its sub directory ? I know unix2dos command is there but to remove in bunch of files ... ? Thanks (7 Replies)
Discussion started by: skdp
7 Replies
Login or Register to Ask a Question