We receive a 7z file and we want to extract it on the command line. We search on Google and we are confused because some examples use 7z and some others use 7za.
We can use both 7z or 7za or even 7zr as long as the format for the archive is 7z.
From Arch Linux Wiki:
7z uses plugins to handle archives.
7za is a stand-alone executable. 7za handles fewer archive formats than 7z, but does not need any others.
7zr is a stand-alone executable. 7zr handles fewer archive formats than 7z, but does not need any others. 7zr is a “light-version” of 7za that only handles 7z archives.
Create an archive of the current directory:
7z a filename.7z
Create an archive of a specific directory:
7z a filename.7z /path-to-dir
Extract a 7z archive in the current directory with full path:
7z x filename.7z
Extract a 7z archive in the current directory without directory names:
7z e filename.7z
You should not have a “-” before a or x. It will not work, a will “Add files to archive” and x will extract an archive with full path.
If you have 7za binary, you can use it as well. In CentOS 7, 7z binary is available only after installing p7zip-plugins.
rpm -qf `which 7za`
rpm -qf `which 7z`
Whereas in Mac, brew install p7zip installs 7z, 7za and 7zr.
This will create a 7-zip archive of the current directory protected by a password
7z a filename.7z -pPASSWORD
where a stands “Add files to archive” and PASSWORD is the password. To archive a different directory use:
7z a filename.7z -pPASSWORD /path/dir
To extract this file
7z x filename.7z -pPASSWORD
where x stands for extract. You can use 7za where 7z binary is not available.
As opposed to fork or other means that creates a new process, exec will replace the process that calls it.
In computing, exec is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable. This act is also referred to as an overlay. It is especially important in Unix-like systems, although exists elsewhere. As a new process is not created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program.
exec is implemented in several programming languages. In Linux, we have an exec system call as well as a bash builtin.
exec is a shell builtin
Let’s do a simple example to understand what it means to replace the calling process. Continue reading
The kernel is hard coded to load init. From Kernel source init/main.c:
if (!try_to_run_init_process("/sbin/init") ||
If you have a Kernel source locally:
root [ /sources/linux-4.7.2 ]# find ./ -name main.c | xargs -IA grep -H run_init_process A
./init/main.c:static int run_init_process(const char *init_filename)
./init/main.c:static int try_to_run_init_process(const char *init_filename)
./init/main.c: ret = run_init_process(init_filename);
./init/main.c: ret = run_init_process(ramdisk_execute_command);
./init/main.c: ret = run_init_process(execute_command);
./init/main.c: if (!try_to_run_init_process("/sbin/init") ||
./init/main.c: !try_to_run_init_process("/etc/init") ||
./init/main.c: !try_to_run_init_process("/bin/init") ||
If systemd is used, init is symlinked to systemd.
[root@localhost ~]# ll /sbin/init
lrwxrwxrwx. 1 root root 22 Dec 21 03:54 /sbin/init -> ../lib/systemd/systemd