Tar directory into archive with the same name as the directory?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.
from:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest
to:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz
EDIT #1
The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.
linux scripting tar archive
add a comment |Â
up vote
1
down vote
favorite
Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.
from:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest
to:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz
EDIT #1
The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.
linux scripting tar archive
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.
from:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest
to:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz
EDIT #1
The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.
linux scripting tar archive
Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.
from:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest
to:
# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz
EDIT #1
The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.
linux scripting tar archive
edited Jul 5 at 17:31
slmâ¦
233k65479651
233k65479651
asked Jul 5 at 9:04
Eugene A
1155
1155
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16
add a comment |Â
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
Example
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3
$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz
add a comment |Â
up vote
0
down vote
(dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
Example
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3
$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz
add a comment |Â
up vote
2
down vote
accepted
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
Example
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3
$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
Example
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3
$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
Example
$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3
$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz
edited Jul 5 at 9:19
answered Jul 5 at 9:12
slmâ¦
233k65479651
233k65479651
add a comment |Â
add a comment |Â
up vote
0
down vote
(dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)
add a comment |Â
up vote
0
down vote
(dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)
add a comment |Â
up vote
0
down vote
up vote
0
down vote
(dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)
(dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)
answered Jul 5 at 10:19
ctrl-alt-delor
8,68331947
8,68331947
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453560%2ftar-directory-into-archive-with-the-same-name-as-the-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You say you have a solution (but it is too big). But you don't show it.
â ctrl-alt-delor
Jul 5 at 10:16