I have a directory I want zipped into itself, minus the zip file of course. Actually I’m using tar which results in a ‘.tar’ file. For background, I needed to backup some symlinks to a remote machine but rysnc didn’t want to handle symlinks that lead to nowhere on the remote machine … as a result I had to compress the folder with the symlinks then do the remote backup (when I go to restore, hopefully never, I’ll have to extract the symlinks into their proper directory).
My goal:
/media/files/symlinks/ -> into -> /media/files/links/directory_tar/backup_symlinks.tar
What worked:
tar -cf /media/files/links/directory_tar/backup_symlinks.tar –exclude=./directory_tar -C /media/files/ symlinkslinks
How this worked
tar -> linux command
Then there is a space
-cf -> the ‘c’ is ‘create a new archive’, the ‘f’ is ‘following is a file name for this archive”
Then there is a space
-> The directory and file name for the archive
Then there is a space
–exclude -> we need to exclude the tar file which is in ./directory_tar … by using the ./ we simplify the exclude directory. This does not exclude the directory structure (the directory /directory.tar is included in the tar file but not any files in it).
Then there is a space
-C -> means to change to the directory we want to backup. This is done so we don’t have a lot of unnecessary folder structures in the tar file, otherwise every directory from root on up would be included in the tar file (no content, but a long way to click to get to what we want)
Then there is a space
->Now we put in the directory we want to switch to
Then there is a space
-> Now we put in the directory we want to backup without leading or trailing backslashes.
When we open the resulting archive we first see the folder ‘directory_tar’ and within that are all our files and directories except for the tar file itself which has been excluded.