I'm trying to find a glob that I can use with tar
to match all files and folders, including hidden files in the current directory. I don't want to include the parent directory. I need my tar not have anything leading before the files. I also can't use shopt
I'm using a format similar to
tar --ignore-failed-read -czvf ../archive.tar.gz .[^.]* *
The --ignore-failed-read
is required if there are NO hidden files because the first glob will return an error when it doesn't match anything.
I'm considering the following types of names for hidden files:
.a
.aa
..a
I've found a few examples of globs that will work but here are the problems I have:
.[^.]*
- gets files
.a
and.aa
but misses..a
.??*
- gets
.aa
and..a
but misses.a
- Any ideas here?
- Is there any way I can remove
--ignore-failed-read
CodePudding user response:
Try this:
tar --ignore-failed-read -czvf ../archive.tar.gz .[^.]* ..?* *
CodePudding user response:
Just add a separate wildcard to cover the two dots case.
tar --ignore-failed-read -czvf ../archive.tar.gz .[^.]* ..?* *
The ?
says there needs to be at least one character after the second dot.
You'll probably want to quote these wildcards to prevent the shell from expanding them, but I'll assume you understand how to handle that correctly.