benathon
benathon

Reputation: 7653

Glob pattern for tar to match all files in current directory without parent folder and without shopt

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:

I've found a few examples of globs that will work but here are the problems I have:

.[^.]*

.??*

  1. Any ideas here?
  2. Is there any way I can remove --ignore-failed-read

Upvotes: 1

Views: 1032

Answers (2)

tripleee
tripleee

Reputation: 189699

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.

Upvotes: 1

M. Nejat Aydin
M. Nejat Aydin

Reputation: 10133

Try this:

tar --ignore-failed-read -czvf ../archive.tar.gz .[^.]* ..?* *

Upvotes: 1

Related Questions