10/22/2023 0 Comments Bash find file name spaces![]() # caveat: you can't have it compressed (you can't add to a compressed archive) # proper way to invoke tar: with -r (which append to an existing tar file, whereas c would overwrite it) # as the last invocation of tar by xargs overwrote the previous one(s) # in my own machine, I end up with only the 60 last filenames, # will invoke tar several time as it can'f fit 10000 long filenames into 1 $ seq 1 10000 | sed -e "s/^/long_filename_/" | xargs tar czvf archive.tgz $ seq 1 10000 | sed -e "s/^/long_filename_/" | xargs touch Proof of the problem on cygwin: $ mkdir test type f -print0 | xargs -0 tar -rvf backup.tar May end up overwriting "file.tgz" at each invocation of "tar" by xargs, and you end up with only the last invocation! (the chosen solution uses a GNU -T special parameter to avoid the problem, but not everyone has that GNU tar available) Xargs will try to fit "as many arguments as possible" after "something", but then you may end up with multiple invocations of "something". Tar -cPp -T $listOfFilesPath | pv -s $sizeForProgress | gzip > $archivePathīig warning on several of the solutions (and your own test) : #tar -czvf $archivePath -T $listOfFilesPath # simple with dump of all files currently archived # Make a list of files/directories to archiveĮcho "$/drupal_root/sites/" -name "files" -type d > $listOfFilesPathĬat $listOfFilesPath | while read nextFile do ListOfFilesPath=$backupOutPath$backupFileName.filelist The best solution seem to be to create a file list and then archive files because you can use other sources and do something else with the list.įor example this allows using the list to calculate size of the files being archived: #!/bin/shīackupFileName="backup-big-$(date +"%Y%m%d-%H%M")"ĪrchivePath=$backupOutPath$ Needed -ignore-failed-read in-case there were no new PDFs for today. I would like to add, that I was also able to use essentially use the same command in my comment, just using tar itself: tar -czvf /archiveDir/ -newer-mtime=0 -ignore-failed-read *.pdf -czvf create archive, filter the archive through gzip, verbosely list files processed, archive name.If you are able to decide what format to use for the output of find then it is normally better to use '\0' as a terminator than to use newline, as file names can contain white space and newline characters. This is not the same quoting mechanism as the one used for -ls and -fls. This quoting is performed in the same way as for GNU ls. printf "%f\0" Regular -print0 OR -printf "%f" did NOT work for me. ![]() mtime 0 look for files created in last 24 hours name "*.pdf" look for pdfs (or any file type) name "*.pdf" -type f -mtime 0 -printf "%f\0" | tar -czvf /dir/ -null -T. Would add a comment to Kehlet post but need 50 rep (RIP).įor anyone that has found this post through numerous googling, I found a way to not only find specific files given a time range, but also NOT include the relative paths OR whitespaces that would cause tarring errors.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |