I am trying to create a tar file of an existing file or directory (file_dir_name
) in a specified directory (dir_path
). I need the tar file to be named new_name.tar
in the new directory. However, when I execute the below command, the tar file is saved in the directory I am currently in. Can anyone help me fix this?
tar -cvf "$new_name.tar" "$file_dir_name" -C "$dir_path"
-C $dir_path
only there to try forcing the creation of the tarball indir_path
? If you are using GNUtar
, it should be warning you that the-C
option has no effect as the last argument. Are you trying to do the equivalent oftar cvf "$name.tar" "$file_or_dir" && mv "$name.tar" "$dir_path/"
- wherefile_or_dir
is an absolute path or a path relative to the current directory (not todir_path
)?