LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-18-2006, 02:46 PM   #1
paledread
LQ Newbie
 
Registered: Aug 2003
Distribution: debian
Posts: 22

Rep: Reputation: 15
how to recurse a cat?


I can cat all files in the current directory by a simple cat *

But how can I make this recursive so that it cats not only the files in the current directory but also those in all subdirectories of the current directory?
 
Old 05-18-2006, 02:53 PM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Code:
find . -type f | xargs cat
 
Old 05-18-2006, 06:37 PM   #3
paledread
LQ Newbie
 
Registered: Aug 2003
Distribution: debian
Posts: 22

Original Poster
Rep: Reputation: 15
thanks muchly
 
Old 05-20-2006, 11:02 AM   #4
paledread
LQ Newbie
 
Registered: Aug 2003
Distribution: debian
Posts: 22

Original Poster
Rep: Reputation: 15
OK, that works beautifully for "normal" files.

Sorry to be a pain, but now I have another problem. For several reasons my file names start with a numeral, and the names have one or more spaces between words. I don't like doing this, but in this case I need to leave the spaces. The first couple of entries in the directory are :

-rw-r--r-- 1 cdqs cdqs 2996 May 15 16:51 .zim.history
-rw-r--r-- 1 cdqs cdqs 849 May 20 10:32 00 today

When I run,

find . -type f | xargs cat

it gives me,

cat: ./00: No such file or directory
cat: today: No such file or directory
and so on for the rest of the files.

then cats the .zim.history file (binary)

then on closing the shell, gives
-bash: 1: command not found
-bash: 2c: command not found

I'm guessing this is all caused by the spaces in the file names, but despite examination of man cat and man xargs I can't decipher a workaround to overcome the problem.

Help would be welcome.
 
Old 05-20-2006, 11:30 AM   #5
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
It's indicated in the man pages, you need to use the null character to indicate the end of the file name, instead of the space character. Both find and xargs have provision for this:
Code:
find . -type f -print0 | xargs -0 cat
 
Old 05-20-2006, 11:31 AM   #6
meng
Member
 
Registered: Apr 2005
Location: Rochester, MN
Distribution: Ubuntu 7.04
Posts: 127

Rep: Reputation: 15
How to recurse a cat?

Damn you, puss!
Damn you again!

See, easy?
 
Old 05-20-2006, 11:34 AM   #7
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Quote:
Originally Posted by meng
Damn you, puss!
Damn you again!

See, easy?
Meaning???
 
Old 05-20-2006, 11:41 AM   #8
meng
Member
 
Registered: Apr 2005
Location: Rochester, MN
Distribution: Ubuntu 7.04
Posts: 127

Rep: Reputation: 15
Just a joke. Not a particularly funny joke, though. If I explained it, it would seem even less funny.
 
Old 05-20-2006, 11:42 AM   #9
paledread
LQ Newbie
 
Registered: Aug 2003
Distribution: debian
Posts: 22

Original Poster
Rep: Reputation: 15
uselpa, thanks for this.

The complexity of the find and xargs man pages is kind of overwhelming for an occasional user. Your guidance was welcome.
 
Old 05-20-2006, 12:30 PM   #10
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Quote:
Originally Posted by paledread
The complexity of the find and xargs man pages is kind of overwhelming for an occasional user. Your guidance was welcome.
You're welcome. BTW, another solution, maybe more simple and flexible:
Code:
find . -type f -exec cat "{}" \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp recurse but NOT overwrite? Goog Linux - Software 3 12-04-2012 09:55 PM
Recurse a directory Peter Shepard Linux - General 1 12-23-2005 03:42 PM
recurse through subdirs? Axion Linux - Software 4 02-16-2004 09:12 PM
cat notsoevil Linux From Scratch 3 02-14-2002 11:16 AM
regarding cat gui10 Linux - Security 6 12-07-2001 09:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration