7z Command Tutorial With Examples To Compress And Extract Files In Linux

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/7z-command-tutorial-examples-compress-extract-files-linux/
PINTEREST
PINTEREST
INSTAGRAM

7zip is popular tool and compression format. 7zip supports wide range of  platforms and operations systems like Windows , Linux , BSD, MacOS etc.

Syntax

Help

Help

Help

Commands

While using 7z there are two component as we can see in the syntax. One of them is commands. Commands are used to specify the operations like:

  •  a : Add files to archive
  •  b : Benchmark
  •  d : Delete files from archive
  •  e : Extract files from archive (without using directory names)
  •  h : Calculate hash values for files
  •  i : Show information about supported formats
  •  l : List contents of archive
  •  rn : Rename files in archive
  •  t : Test integrity of archive
  •  u : Update files to archive
  •  x : eXtract files with full paths

Switches

Switches are used to specify some minor options like create SFX archive, compress shared files, set output log level. Here are some of them

  •   -- : Stop switches parsing
  •  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  •  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  •  –ao{a|s|t|u} : set Overwrite mode
  •  -an : disable archive_name field

Compress Files and Folders

7z can compress files and folders. We will use a command to create new archive. The new archive file name will be mybackup.7z and we will put files named a.out , body.txt and folder cups . Here the

Compress Files and Folders

Compress Files and Folders

Here while starting 7z applications shows some information about the 7z application like build number, version, developer.

LEARN MORE  Linux tar Command and How To Tar A Directory

And than provided files and folders are scanned and the scan result is printed like 56 folders, 1550 files and total 142 MB.

After that the archive creation starts. Total items those will be compresses are show as 1606. Compression takes some time. 

After compression is completed new archive size is printed as 96 MB.

Add Files To The Archive

In previous example we have created the archive file. Some time we need to add new files to the existing archive file. In this situations we will use same a option to add files.

Add Files To The Archive

Add Files To The Archive

In this operation mybackup.7z archive file all ready exists. Some information about the file is printed like path, compression type, size etc.

Than new file is added to the existing archive or compressed file named mybackup.7z .

Delete Files From Archive

Another useful operation is removing one or more files from an existing archive file. We will use d command with file we want to delete. In this example we want to remove file named fruits.txt from archive file mybackups.7z .

Delete Files From Archive

Delete Files From Archive

Extract Files

All files can be extracted with x command.

Extract Files

Extract Files

As we can see from screenshot there are some existing files which will be over write. There question whether we want to over write, skip, rename etc. We answer this as Always .

After extraction some statistical information like total folder count, file count size, compressed size is printed.

LEARN MORE  Gzip Command Tutorial With Examples For Linux

List Contents of Archive

We can also list files of an archive with l command. We will list all files of mybackup.7z archive.

List Contents of Archive

List Contents of Archive

In the output we can see that files and folders are listed. While listing information like date, time , attributes, size  and name are provided.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/7z-command-tutorial-examples-compress-extract-files-linux/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

1 Response

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)