Skip to content

Commit d2890f7

Browse files
committed
updated tar.md
1 parent 0d73473 commit d2890f7

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tar.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
1+
# `tar`
12

2-
3-
# Make a `.tar.gz` file of each directory
3+
## Make a `.tar.gz` file of each directory
44

55
```bash
66
find . -maxdepth 1 -mindepth 1 -type d -exec tar cvzf {}.tar.gz {} \;
77
```
88

9+
---
10+
## Backing up the current user's HOME
11+
12+
An approach to backing up the current user's HOME, using `tar(1)` and Gzip compression. Permissions (modes) will be preserved. The filename format will be: `UID:GID_DATE.tgz`
13+
14+
Replace 'DEVICE' with whichever device is applicable to you, but note that it must be in the `/media/USER` (where `USER` is the username) directory, else this won't work, unless you edit the formatting section of `printf`.
15+
16+
```bash
17+
tar -czvpf "$(printf '/media/%s/%s/%d:%d_%(%F)T.tgz' "$USER" 'DEVICE' ${UID:-`id -u`} ${GID:-`id -g`} -1)" "$HOME"
18+
```
19+
---
20+
## `tar` commands
21+
22+
To extract an uncompressed archive:
23+
`tar -xvf /path/to/foo.tar`
24+
25+
To extract a .tar in specified directory:
26+
`tar -xvf /path/to/foo.tar -C /path/to/destination/`
27+
28+
To create an uncompressed archive:
29+
`tar -cvf /path/to/foo.tar /path/to/foo/`
30+
31+
To extract a .tgz or .tar.gz archive:
32+
`tar -xzvf /path/to/foo.tgz`
33+
`tar -xzvf /path/to/foo.tar.gz`
34+
35+
To create a .tgz or .tar.gz archive:
36+
`tar -czvf /path/to/foo.tgz /path/to/foo/`
37+
`tar -czvf /path/to/foo.tar.gz /path/to/foo/`
38+
39+
To list the content of an .tgz or .tar.gz archive:
40+
`tar -tzvf /path/to/foo.tgz`
41+
`tar -tzvf /path/to/foo.tar.gz`
42+
43+

0 commit comments

Comments
 (0)