Recursively cat files in a directory with filename printed first.
I want to recursively cat the content of files in a directory e.g.
But I want it to print the file name first and then the content. For example let's say /etc/statetab and /etc/colord.conf will be printed first then I want the output to look something like;
---------- Post updated at 09:09 AM ---------- Previous update was at 08:59 AM ----------
Note: In standard form, find in combination with pipe and xargs will not work with filenames with spaces...
A loop will, but then a while read loop should be used instead of a for loop and the file references should have double quotes around them, for example..
Last edited by Scrutinizer; 10-22-2012 at 06:43 AM..
Note: In standard form, find in combination with pipe and xargs will not work with filenames with spaces...
And that's an understatement. The approach also won't work if a filename contains a tab, single quote, double quote, or backslash. There is also the remote possibility that a file name of a single underscore could be problematic.
Quote:
Originally Posted by Scrutinizer
WARNING: Pedantic piconit (of which you are probably aware) ahead.
That will still have problems with leading/trailing spaces and backslashes. Misinterpretation of such filenames manifests as an inability to find a file that exists or as reading the wrong file.
To remedy those shortcomings:
Regards,
Alister
---------- Post updated at 12:50 PM ---------- Previous update was at 12:45 PM ----------
Quote:
Originally Posted by lewk
Alternatively, the task can be accomplished with multiple -exec's (which properly handles every allowable filename character):
However, I would suggest following Scrutinizer's advice. The while-read loop approach is both robust and readable.
Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
[..]
WARNING: Pedantic piconit (of which you are probably aware) ahead.
That will still have problems with leading/trailing spaces and backslashes. Misinterpretation of such filenames manifests as an inability to find a file that exists or as reading the wrong file.
To remedy those shortcomings:
Regards,
Alister
[..]
Indeed you are correct. I did not want to overcomplicate things, but file names with spaces occur quite frequently so I felt that was the most important note to make...
To complete the quest for the most robust solution we should probably also use printf rather than echo, since not all echoes are immune to special characters:
This User Gave Thanks to Scrutinizer For This Post:
I need to copy a complete directory structure into a new location. But I want to have all files copied into one directory and leave out the directory structure. So all files must be placed in one directory. (4 Replies)
Hi.
I found many scripts in the web of achieving this.
But I like to use this one
find /EDWH-DMT03 -xdev -size +10000 -exec ls -la {} \;|sort -n -k 5 > LARGE.rst
But the problem is, why it still list out files with 89 bytes as the output? Is there anything wrong with the command?
My... (7 Replies)
I love the -newerct flag for the Cygwin find command on windows.
Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
This should recursively walk through all dirictories and
search for a specified string in all present files, if found
output manicured content (eg some regex) with CAT into
a specified directory (eg /tmp/)
one by one, keeping the original names
This is what I have so far, which seems to... (1 Reply)
I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Display the number of files in a directory and recursively in each subdirectory
To look something like below, for example
/var 35
/var/tmp 56
/var/adm 46Any ideas how can we do this?
Got a sun cluser global mount point which takes ages to mount everytime, need to understand... (5 Replies)
I have a script which generates recursively some files in folders for a given root folder.
I have checks for permissions and it works for all folders except one(i have 777 permission on it). When i try calling the script in problematic folder(problematic folder being root folder), script works as... (2 Replies)
Hi,
I need to concatenate data files with a .mp extension that are stored in directories by year. I want to keep the same filename as an output for example:
for the file name p030.mp, which resides in the following subdirectories:
/2000/p030.mp
/2001/p030.mp
/2002/p030.mp
I want to:... (4 Replies)
I have to write a shell script which can delete all the files and directories recursively inside the specified directory but should not delete the specified directory.
Please some body help me in writing the script. (3 Replies)
Hi
I am a shell-script newbie and am looking to synchronize certain files in two directory structures.
Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over.
I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)