tar command not working

I'm trying to figure out why is the following tar command not working -

I've tried the following 2 versions & both don't work -

Version 1

tar -c --use-compress-program=pigz -f /home/jhonst/data_lake/1m/UX.tar -C '/home/jhonst/data_lake/1m/*.UX.csv'

The error I see is

tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.

Version 2

tar -c --use-compress-program=pigz -f /home/jhonst/data_lake/1m/UX.tar -C '/home/jhonst/data_lake/1m/*.UX.csv' .

The error I see is

    tar: 
/home/jhonst/data_lake/1m/*.UX.csv: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

Please could someone guide me on what I am doing wrong


Your question doesn't quite give enough details to allow for a precise answer (your question needs to be more specific, more detailed, and contain more explanation of what you are trying to achieve) but I think I get the general idea.

The -C argument to tar means 'change to the directory following this option', but you are not giving it a directory name after the option, you are trying to give it the list of files.

Also, you are enclosing the wildcard in quotes which means the shell will not expand it to match the files. (It is often confusing to novice users that although you are using the tar command to make the archive, the processing of the argument list is actually done by the shell and not the tar command).

It would be simplest to change to the working directory first and then run the tar command.

Entering this at a shell command prompt should do the trick (note the lack of quotes):

cd /home/jhonst/data_lake/1m && tar -c --use-compress-program=pigz -f UX.tar *.UX.csv

If you want a separate archive in each of your subdirectories (your question is not entirely clear on this) then a bash loop like this would work:

cd /home/johnst/lake_data
for d in *; do
   cd $d && && tar -c --use-compress-program=pigz -f UX.tar *.UX.csv
   cd /home/johnst/lake_data
done

If you want the directory name in the tar archive then you could use -f UX_${d}.tar in the tar command rather than -f UX.tar