Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
deleted 16 characters in body
Source Link
Caleb
  • 12.2k
  • 4
  • 39
  • 49

I would like to create a tarball that contains files from a directory that have a ctimectime of less than 30 days. Most tutorials I have found have basically recommended doing something like this:

tar cvf foo.tar $(find ~/POD -type f -ctime -30) 

The problem is that a lot of the files that I want to tar up contain spaces in their name. This means that the tartar command will delimit based on a spaces, which means that the full file paths will be broken up.

So now I'm trying to make the "find"find command return a list of quoted file paths. So here's what I have tried:

find . -type f -ctime -30 | xargs printf "\"%s\"\n" 

But this command also broke up all of the file names based on spaces. So then I tried this:

oldifs=$IFS IFS=\n find . -type f -ctime -30 | xargs printf "\"%s\"\n" IFS=$oldifs 

But this gave me the same results.

Is there a way I can pass the full path names to tartar and have everything work with spaces in their names?

Thanks in advance!

I would like to create a tarball that contains files from a directory that have a ctime of less than 30 days. Most tutorials I have found have basically recommended doing something like this:

tar cvf foo.tar $(find ~/POD -type f -ctime -30) 

The problem is that a lot of the files that I want to tar up contain spaces in their name. This means that the tar command will delimit based on a spaces, which means that the full file paths will be broken up.

So now I'm trying to make the "find" command return a list of quoted file paths. So here's what I have tried:

find . -type f -ctime -30 | xargs printf "\"%s\"\n" 

But this command also broke up all of the file names based on spaces. So then I tried this:

oldifs=$IFS IFS=\n find . -type f -ctime -30 | xargs printf "\"%s\"\n" IFS=$oldifs 

But this gave me the same results.

Is there a way I can pass the full path names to tar and have everything work with spaces in their names?

Thanks in advance!

I would like to create a tarball that contains files from a directory that have a ctime of less than 30 days. Most tutorials I have found have basically recommended doing something like this:

tar cvf foo.tar $(find ~/POD -type f -ctime -30) 

The problem is that a lot of the files that I want to tar up contain spaces in their name. This means that the tar command will delimit based on a spaces, which means that the full file paths will be broken up.

So now I'm trying to make the find command return a list of quoted file paths. So here's what I have tried:

find . -type f -ctime -30 | xargs printf "\"%s\"\n" 

But this command also broke up all of the file names based on spaces. So then I tried this:

oldifs=$IFS IFS=\n find . -type f -ctime -30 | xargs printf "\"%s\"\n" IFS=$oldifs 

But this gave me the same results.

Is there a way I can pass the full path names to tar and have everything work with spaces in their names?

Source Link
Tom Purl
  • 569
  • 1
  • 4
  • 14

Returning A List Of Quoted Files Paths Using Find

I would like to create a tarball that contains files from a directory that have a ctime of less than 30 days. Most tutorials I have found have basically recommended doing something like this:

tar cvf foo.tar $(find ~/POD -type f -ctime -30) 

The problem is that a lot of the files that I want to tar up contain spaces in their name. This means that the tar command will delimit based on a spaces, which means that the full file paths will be broken up.

So now I'm trying to make the "find" command return a list of quoted file paths. So here's what I have tried:

find . -type f -ctime -30 | xargs printf "\"%s\"\n" 

But this command also broke up all of the file names based on spaces. So then I tried this:

oldifs=$IFS IFS=\n find . -type f -ctime -30 | xargs printf "\"%s\"\n" IFS=$oldifs 

But this gave me the same results.

Is there a way I can pass the full path names to tar and have everything work with spaces in their names?

Thanks in advance!