I have the following directory structure and files:
test:
total 16
drwxr-xr-x 2 db2root1 db2iadm1 4096 Jan 18 16:52 archive
-rw-r--r-- 1 db2root1 db2iadm1 34 Jan 18 16:38 file1.txt
-rw-r--r-- 1 db2root1 db2iadm1 34 Jan 18 16:38 file2.txt
drwxr-xr-x 2 db2root1 db2iadm1 4096 Jan 18 17:04 subdir
test/archive:
total 0
test/subdir:
total 4
-rw-r--r-- 1 db2root1 db2iadm1 34 Jan 18 16:38 file3.txt
Now I want to create a tar file in the directory archive without the directory archive and the file file1.txt with the following command:
tar --remove-files --exclude file1.txt --exclude archive -cvzf /test/archive/test.tar.gz /test
I put the --exclude and --remove-files options to different places but always get the following error message:
tar: Removing leading `/' from member names
/test/
/test/subdir/
/test/subdir/file3.txt
/test/file2.txt
tar: /test: Cannot rmdir: Directory not empty
tar: Exiting with failure status due to previous errors
How can I prevent the error regarding the base directory /test?