How to simplify 7z file compression with Bash Alias
There are many ways and tools you can use to shrink your files, to reduce the space they take up or send them as packets to a contact. Of these, 7-Zip won the No. 1 position in the hearts of most users, thanks to a unique combination of performance and great compression level at zero cost.
All the forms of compression in this format are actually more complex than the approach we will see here. At least most users use compression to package everything in a directory and its subfolders into compressed packages.
So let's see how Bash combines alias support with the command line version 7z to create packages for files with a simple command.
Using Bash Alias simply compresses the file
- Install p7zip
- Create Bash alias
- Make 7-Zip information handy
- Create super compression alias
- Replicate and cut down the alias
- Activate your alias
Install p7zip
As the most popular compression tool, 7-Zip is most likely already installed in your Linux distribution. To test it, try the command 7z
in a terminal. If not already installed, you can install it in Ubuntu / Debian-based distributions using the command:
sudo apt-get install p7zip-full
Create Bash alias
Bash aliases allow you to map multiple commands or even strings of commands into single words. An easy way to add aliases to Bash is to insert them at the end of the '~ / .bashrc' file. For the sake of convenience and to keep things organized, it's best to put them in a separate file.
It is possible that this file already exists and the Bash configuration includes a reference to it. Check if that is true by opening '~ / .bashrc' in your favorite word processor and search:
if [-f ~/.bash_aliases]; then . ~/.bash_aliases Fi
If not, add it to the end of the file after everything is available.
Make 7-Zip information handy
You can run 7-Zip in a terminal to see a list of its command line options. For comprehensive information, visit the user guide: https://sevenzip.osdn.jp/chm/cmdline/index.htm or the program's man page with:
man 7z
These will help you set up your own compression commands. Most likely, the ones mentioned here will also meet your needs. So you can copy and paste them into your own .bash_aliases file.
Create super compression alias
Open the file '~ / .bash_aliases' in your favorite word processor (article using nano ). Enter the following command:
alias 75='7z a -r -t7z -m0=lzma2 -mx=9 -myx=9 -mqs=on -ms=on'
alias 75
says we want to create the '75' command, which we will use from now on to compress all files and folders in a folder into a 7-Zip package. The reason the example applies this special name to the command is because it is a brief version of '7zip compression level 5' , so easy to remember.
7z
is the compression itself. a
follows it means that we want to add the files to a new compressed package. -r
indicates that p7zip is not bound to the directory where it runs, but should include the final zipped package and all its subfolders, along with all its contents.
-t7z -m0 = lzma2
indicates that we want to create 7zip packages mainly using the LZMA2 algorithm to compress files. This usually yields the best compression result for almost any file type.
-mx=9 -myx=9
corresponds to the level of compression and the "effort level" 7-Zip will take into account the content analysis of the compressed files to find the best compression strategy. The higher their value, the greater the compression and the smaller the output package.
Finally, -mqs=on -ms=on
determines that we want the level of hard compression (solid). This means that p7zip compresses similar files in a single block of data, achieving even better results. The reason they exist as an option you can disable is because they are useful, but they also come with 2 drawbacks. They extend the compression time and make it impossible for users to extract files independently from the final package created by the compression tool. With the level of hard compression, you can not perform the extraction of a single file from the zip file, and must extract the entire package to access its contents.
Replicate and cut down the alias
The article started with the command to achieve the maximum possible compression level instead of expanding it with more elements, for example being able to go back, remove parameters, and reduce the values set.
Start by copying the existing order 5 more times, placing each command in a separate line. Leave the first line, as it has reached the highest possible compression level. Modify the rest, in order, by removing additional options and reducing the level of compression as you see below. Remember to change their alias to accommodate lower compression levels.
You can always copy the following items and paste it into your ~ / .bash_aliases instead.
alias 75='7z a -r -t7z -m0=lzma2 -mx=9 -myx=9 -mqs=on -ms=on' alias 74='7z a -r -t7z -m0=lzma2 -mx=9' alias 73='7z a -r -t7z -m0=lzma2 -mx=7' alias 72='7z a -r -t7z -m0=lzma2 -mx=5' alias 71= '7z a -r -t7z -m0=lzma2 -mx=3' alias 70='7z a -r -t7z -m0=lzma2 -mx=1'
Activate your alias
Save the changes to the file and return to the terminal. To load and activate new aliases, use the following command:
source ~/.bashrc
New compression commands are active. P7zip works by default on all files in the directory where it runs, if you don't explicitly specify what you want to compress as a parameter. So all you need to do from now on when you want to compress the contents of the folder into package 7z is to enter the command:
75 archive_name
Here, " 75" is an alias for the highest compression level from before and 'archive_name' is the name of the compressed package. You can replace 75 with one of the other aliases (from 75 to 70 ) for gradual but faster compression and use whatever name you want for the final file.
If you have any questions, feel free to leave your comments in the comment section below!
Hope you are succesful.
You should read it
- Instructions for accessing Ubuntu Bash files on Windows
- Create a temporary name using ALIAS in SQL
- Difference between Zsh and Bash
- What is 'Bash' in Linux?
- Add new, delete, edit Outlook Email Alias like?
- How to Install and Run Bash on Windows 11
- Ubuntu Bash tutorial on Windows 10
- How to Create a Shortcut (Alias) for a File or Folder on Mac
May be interested
- Ubuntu Bash tutorial on Windows 10the windows 10 anniversary update update was released this summer, adding the ability to use bash to run linux applications according to the command. microsoft has provided a trial version of some of the features of anniversary update in build 14316 including bash in windows 10.
- What is Bash in Linux? What can it be used for?writing bash scripts is one of the best ways to increase your linux expertise, but learning it can be intimidating.
- Add new, delete, edit Outlook Email Alias like?first of all, outlook.com supports the ability to create multiple alias, or in a way like the old yahoo messenger can create many virtual nick in a real account. and these alias still use the same outlook, inbox, contact list and other settings ...
- Shortcuts to copy - paste coming soon on Windows 10's Bash Consolethere is a very desirable feature, which is to use keyboard shortcuts to copy and paste on windows 10 bash.
- Everything you can do with the new Windows 10 Bash Shellyou can install the linux environment and the bash shell on any version of windows 10. today's article will summarize what you can do in the new windows 10 bash shell.
- How to compress data on Cloudpressocloudpresso will compress images, videos, document files, apk files for free with a download capacity of up to 1gb.
- Test evaluation of 2 WinRar and 7Zip compression toolscurrently there are 2 tools of compression and decompression that are rated equally with each other are winrar and 7zip. have you ever wondered which software is better? of course, all comparisons are lame because each software has its advantages and disadvantages. let's tipsmake.com try doing the test with 2 tools offline.
- Top 10 best file compression and decompression softwarethe following article will introduce you to the best file compression and decompression software available today, helping you compress files to save storage space on your computer and share easily, as well as allowing you to easily easily decompress one or more files to file compression formats such as zip, rar, 7z and more.
- How to Install and Run Bash on Windows 11after installing wsl, you can run any linux tools on your pc easily. so, if you want to run bash on your windows 11, here's how to do it in detail.
- Top 5 best free PDF compression softwareshare 5 best free pdf compression software 2021, with these file compression software to help you compress pdf files extremely easy and completely free