Linux / UNIX: tar Command Stay In Local / File System When Creating Archive

To create a tar archive and keep the files in the local file system, you can use the -C option to change to the directory where the files are located before creating the archive.

For example, if you have a directory called myfiles that you want to archive, and you want to create the archive in the same directory, you can use the following command:

tar -czvf myfiles.tar.gz -C /path/to/myfiles .

In this command, the -c option creates a new archive, the -z option compresses the archive using gzip, the -v option prints the names of the files being added to the archive, and the -f option specifies the name of the archive file.

The -C option is used to change to the directory /path/to/myfiles before creating the archive. The dot at the end of the command (.) specifies that all files in the current directory should be included in the archive.

After running this command, the myfiles.tar.gz archive will be created in the same directory where myfiles is located, and all files in the myfiles directory will be included in the archive while staying in the local file system.

(www.keppnerboxing.com)

Leave a Comment