Copy and crear tar.gz at the same time.
I need to create a bash thata copy some folder and make a tar.gz file.
How can I create it? Code:
cp -rf /some/folder /backup/name.tar.gz |
Hi, have you tried
Code:
tar zcvf /backup/name.tar.gz /some/folder |
It can be easily done as:
Code:
bash# cp /path/to/source /path/to/target |
But this way first I copy the folder and later I make it tar.
Is there way to copy and make it tar at the same time and only one command - one line? Problem is that I want to change the name to (Year-Month-Day-hour) and create a variable for that. |
Define a variable such as timestamp as follow:-
Code:
timestamp=$(date +%Y%m%d%H%M) Code:
cp /path/to/source /path/to/target.$timestamp Code:
cp /path/to/source /path/to/target ; tar -cvf sample.tar /path/to/file(s) |
If you really want to, you can make a pipeline that unpacks the tar file on-the-fly to do the copy function:
Code:
tar -czf - /path/to/files | tee /backup/name.tar.gz | tar -C /path/to/target -xzf - |
Quote:
Very simple and work. Why do I need 2 times tar. Code:
z, --gzip |
Quote:
Quote:
|
All times are GMT -5. The time now is 10:08 PM. |