Use archives within Linux CLI: Difference between revisions
From WikiMLT
m Стадий: 4 [Фаза:Авторизиране, Статус:Разработен]; Категория:Linux Server |
m Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Linux Server |
||
(7 intermediate revisions by the same user not shown) | |||
Line 22: | Line 22: | ||
<syntaxhighlight lang="shell" line="1"> | <syntaxhighlight lang="shell" line="1"> | ||
tar -xjf nextcloud-[version].tar.bz2 | tar -xjf nextcloud-[version].tar.bz2 | ||
</syntaxhighlight> | |||
=== Extract certain file from the archive directory tree === | |||
<syntaxhighlight lang="shell" line="1"> | |||
tar --strip-components=6 -xvf "data.tar.zst" \ | |||
./usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== 7zip == | == 7zip == | ||
Line 64: | Line 70: | ||
== Reference == | == Reference == | ||
* Ubuntu man pages: <code class="noTypo">[https://manpages.ubuntu.com/manpages/jammy/man1/tar.1.html tar]</code> | * Ubuntu man pages: <code class="noTypo">[https://manpages.ubuntu.com/manpages/jammy/man1/tar.1.html tar]</code> | ||
*Stack Overflow: [https://stackoverflow.com/a/845601/6543935 '''How do I untar a subdirectory into the current directory?'''] | |||
*Unix and Linux: [https://unix.stackexchange.com/q/61461/201297 How to extract specific file(s) from tar.gz] | |||
* Stack Overflow: [https://stackoverflow.com/a/28160425/6543935 7-Zip command to create and extract a password-protected ZIP file on Windows?] | * Stack Overflow: [https://stackoverflow.com/a/28160425/6543935 7-Zip command to create and extract a password-protected ZIP file on Windows?] | ||
*[http://www.putorius.net/2015/04/how-to-create-enrcypted-password.html How to Create an Encrypted (Password Protected) Tar or Zip Archive in Linux] | *[http://www.putorius.net/2015/04/how-to-create-enrcypted-password.html How to Create an Encrypted (Password Protected) Tar or Zip Archive in Linux] | ||
Line 74: | Line 82: | ||
{{devStage | {{devStage | ||
| Прндл = Linux Server | | Прндл = Linux Server | ||
| Стадий = | | Стадий = 6 | ||
| Фаза = | | Фаза = Утвърждаване | ||
| Статус = | | Статус = Утвърден | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = Spas | | РзбПт = Spas | ||
| АвтПт = | | АвтПт = Spas | ||
| УтвПт = | | УтвПт = {{REVISIONUSER}} | ||
| ИдтДт = 7.07.2022 | | ИдтДт = 7.07.2022 | ||
| РзбДт = | | РзбДт = 17.09.2022 | ||
| АвтДт = | | АвтДт = 24.09.2022 | ||
| УтвДт = | | УтвДт = {{Today}} | ||
| ИдтРв = [[Special:Permalink/27794|27794]] | | ИдтРв = [[Special:Permalink/27794|27794]] | ||
| РзбРв = [[Special:Permalink/ | | РзбРв = [[Special:Permalink/31603|31603]] | ||
| АвтРв = | | АвтРв = [[Special:Permalink/31793|31793]] | ||
| РзАРв = [[Special:Permalink/ | | РзАРв = [[Special:Permalink/31401|31401]] | ||
| РзУРв = [[Special:Permalink/ | | УтвРв = {{REVISIONID}} | ||
| РзУРв = [[Special:Permalink/31403|31403]] | |||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Latest revision as of 21:17, 24 September 2022
Tar
- Note
.tgz === .tar.gz
Create a gzip-compressed archive
tar czvf archived-file.tar.gz /my/directory/or/file_1 /my/directory/or/file_2
-c
,--create
– create a new archive,-z
,--gzip
– filter the archive through gzip,-v
,--verbose
– verbosely list files processed,-f
– use archive file or device ARCHIVE – it must be the last option, otherwise you can use--file=ARCHIVE
.
Extract a gzip-compressed archive
tar xzvf my-file.tar.gz
-x
,--extract
,--get
– extract files from an archive,- The rest options are the same as the above,
- the compression type (
-z
in this case) could be omitted, because tar will detect it automatically.
Extract bzip2-compressed archives
tar -xjf nextcloud-[version].tar.bz2
Extract certain file from the archive directory tree
tar --strip-components=6 -xvf "data.tar.zst" \
./usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
7zip
7zip is not installed by default with most Linux distributions, so on Debian based distribution you can install it by the following command.
sudo apt update && sudo apt install p7zip-full
IMO, 7zip is the best or at least the most easiest way to create password protected compressed archive within the command line.
Create a 7z-compressed archive
7z a archive.7z /directory/or/file # create 7z compressed archive
7z a archive.7z * -p # create password protected archive, enter the password in prompt
7z a archive.7z * -p'SECRET @#!' # create password protected archive, append the password to the command
a
– create archive,-p
– password protected [followed by the pass phrase].
Extract a 7z-compressed archive
7z x archive.7z # extract an archive in the current directory
7z x archive.7z -p # extract a password protected archive in the current directory
7z x archive.7z -p'SECRET @#!' # append the password to the command
7z x archive.7z -p'SECRET' -o'/otput/dir/' # set an output directory
x
– extract,-o
– output directory.
Zip and Unzip
Create an recursive archive for a directory.
zip -r "archive-name.zip" "./directory-to-be-archived/"
Extract archive.
unzip "archive-name.zip"
Rar and Unrar
Some times the Linux archive managers can't handle properly RAR archives – for example look at this topic Extract files within an .exe file. Here is how to extract such files.
sudo apt install unrar
unrar x "PracticalMalwareAnalysis-Labs.exe"
unrar x "archive-name.rar"
Reference
- Ubuntu man pages:
tar
- Stack Overflow: How do I untar a subdirectory into the current directory?
- Unix and Linux: How to extract specific file(s) from tar.gz
- Stack Overflow: 7‑Zip command to create and extract a password-protected ZIP file on Windows?
- How to Create an Encrypted (Password Protected) Tar or Zip Archive in Linux
- How to password protect gzip files on the command line?
- How do I password protect a .tgz file with tar in Unix?
7zip
destination folder-o
7z -o
(set Output directory) switch