1

in my Linux machine under /var/Recording directory.

I have hundreds directories and each directory there are also directories and files include hard links and soft link .

I want to compress all directories under /var/Recording directory to create one compressed file.

With which command I can create the best compressed file? - tar or cpio (regarding I have hard links and softlink files).

second what the right syntax of the tar/cpio command?

  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1034
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1033
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1038
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1037
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1036
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1041
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1040
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1039
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1044
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1043
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1042
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1047
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1046
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1045
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1049
  drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1048
  .
  .
  .
  .
  .
bwDraco
  • 45,747
  • 43
  • 165
  • 205
maihabunash
  • 489
  • 2
  • 6
  • 15
  • Interesting discussion of tar and cpio behavior regarding hardlinks. Can still use either one, but it's good background on internals: https://github.com/libarchive/libarchive/wiki/Hardlinks – glallen Nov 23 '14 at 12:09

1 Answers1

0

I'm a fan of tar. It will preserve hardlinks and softlinks. The command you can use for your situation is as follows.

cd /var
tar cvzf ~/Recording.tgz Recording

That creates a gzipped file called Recording.tgz with verbose output of the directory Recording. Paths will be preserved. There are lots of options that go with tar that you can review in the man pages. To restore your files, change to the directory were you want to put them and run tar again using the following command.

tar xvzf ~/Recording.tgz

To see what the file has in it prior to untarring, simply type

tar tvzf ~/Recording.tgz
R Schultz
  • 2,843
  • 2
  • 15
  • 19
  • can you explain please why you choose the tar and not cpio? – maihabunash Nov 24 '14 at 07:02
  • Since cpio can create tar archives also, I'm not sure it matters other than, IMO it is by far more widely used across the net etc. When you go to download a package, you don't see many .cpio files around but .tar and .tgz. files are all around. Wider user base means there is a larger group of people to get help from should you need it and a greater chance of having bugs resolved should they arise. There may be a large group of cpio users around, I just haven't seen it. Also, looking at the man page for cpio, tar seems more straightforward to use. Though this could be 20 years of bias. :) – R Schultz Nov 24 '14 at 22:19