Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1932  / 3 Years ago, mon, may 24, 2021, 6:24:55

I am fairly new using tar having used zip files in the past.


I want to just create the tar file without the directories being included.


I went here, but found it a bit confusing.


https://www.baeldung.com/linux/tar-archive-without-directory-structure


# Backup crontab
crontab -l > /home/andy/bin/crontab_backup.txt
tar -cvf /home/andy/bin/crontab_backup.tar /home/andy/bin/crontab_backup.txt

More From » 20.04

 Answers
2

With GNU tar you can use the -C option to change directory partway through the command. Filenames are still recorded relative to the current directory, so it means so you can do this:


tar -cvf /home/andy/bin/crontab_backup.tar -C /home/andy/bin crontab_backup.txt

and if you wanted to collect two files from different directories, you could do this:


tar -cvf /home/andy/bin/crontab_backup.tar -C /home/andy/bin crontab_backup.txt -C /home/andy other_file.txt

[#127] Tuesday, May 25, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rialhirt

Total Points: 422
Total Questions: 113
Total Answers: 120

Location: France
Member since Sun, May 15, 2022
2 Years ago
rialhirt questions
Tue, May 10, 22, 21:43, 2 Years ago
Thu, Feb 16, 23, 16:32, 1 Year ago
Mon, Jun 13, 22, 03:02, 2 Years ago
Tue, Jun 15, 21, 12:40, 3 Years ago
;