Linux Tar Description
DESCRIPTION:
Tar stores and extracts files from a tape or disk archive.
How to use:
The first argument to tar should be a function (list the Most commonly used)
- -c create a new archive
- -x extract files from an archive
- -f use archive file or device ARCHIVE
- -v verbosely list files processed
- -z gzip
- -j bzip2
- -J xz
Examples:
- Create archive.tar from files foo and bar,the archive.tar is the same size of the files
tar -cf archive.tar foo bar
- Create archive.tar by using gzip from files foo and bar,z means zip,the sizes decreases
tar -czf archive.tar foo bar
- performs the function above but verbosely list files
tar -czvf archive.tar foo bar
- this is identical to above except that the files are extracted instead of archived
tar -zxvf archive.tar
My One Task:
Send the document in 2017 to another server and keep the dir structure fixed.Hovever,there are thousands of small files ,so I should archived all the files located in 2017 directories before transfering for the purpose to Maximum utilization ofnetwork throughput.
Directories:
FutureDB/
├── DCE
│ ├── Day
│ │ ├── 2017.01.29
│ │ ├── …
│ │ ├── 2016.01.29
│ │ ├── …
│ ├── DB
│ └── Night
│ ├── 2017.01.29
│ ├── …
│ ├── 2016.01.29
│ ├── …
├── SHFE
│ ├── Day
│ │ ├── 2017.01.29
│ │ ├── …
│ │ ├── 2016.01.29
│ ├── DB
│ └── Night
│ ├── 2017.01.29
│ ├── …
│ ├── 2016.01.29
└── ZCZE
├── Day
│ ├── 2017.01.29
│ ├── …
│ ├── 2016.01.29
├── DB
└── Night
├── 2017.01.29
├── …
It is very convenient by using this command to archive
tar czvf /mnt/FutureDBDay.tar $(find /mnt/FutureDB/ -maxdepth 3 -name '2017.*' ) &
How to extract more than one tars
ls *.tar.gz | xargs -n1 tar xzvf