Archiving and Compression
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
Archiving and compression involve managing and reducing the size of files and directories. Archiving tools combine multiple files into a single archive, while compression tools reduce the size of files for efficient storage and transfer. These processes are essential for data management, backup, and distribution.
1 - Archiving Tools
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
These tools are used to combine multiple files into a single archive file, making it easier to manage and transfer large sets of files. They do not compress the files but simply bundle them together. Archiving is often used for backup purposes and to maintain directory structures.
1.1 - 🖥️bzip2recover
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the bzip2recover command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗██╗██████╗ ██████╗ ██████╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
# ██╔══██╗╚══███╔╝██║██╔══██╗╚════██╗██╔══██╗██╔════╝██╔════╝██╔═══██╗██║ ██║██╔════╝██╔══██╗
# ██████╔╝ ███╔╝ ██║██████╔╝ █████╔╝██████╔╝█████╗ ██║ ██║ ██║██║ ██║█████╗ ██████╔╝
# ██╔══██╗ ███╔╝ ██║██╔═══╝ ██╔═══╝ ██╔══██╗██╔══╝ ██║ ██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██╗
# ██████╔╝███████╗██║██║ ███████╗██║ ██║███████╗╚██████╗╚██████╔╝ ╚████╔╝ ███████╗██║ ██║
# ╚═════╝ ╚══════╝╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
# Extracts blocks from damaged .bz2 files
bzip2recover damaged_file_name
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command bzip2recover in a clear format. This allows users to quickly access the needed information for bzip2recover without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for bzip2recover are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1.2 - 🖥️dar
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the dar command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ █████╗ ██████╗
# ██╔══██╗██╔══██╗██╔══██╗
# ██║ ██║███████║██████╔╝
# ██║ ██║██╔══██║██╔══██╗
# ██████╔╝██║ ██║██║ ██║
# ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
# dar
# (disk archive), command-line archiving tool intended as a replacement for tar
# Create an archive of everything below source_dir
dar -R source_dir -c archive
# Extract an entire archive to a destination
dar -x archive dest_dir
# List the files in an archive
dar -l archive
# Extract a specific file from an archive into the
# current directory
dar -x archive -g file
# multiple files
dar -x archive -g file1 -g file2 -g file3
# For troubleshooting:
# --dry-run
# --verbose
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command dar in a clear format. This allows users to quickly access the needed information for dar without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for dar are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1.3 - 🖥️deb
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the deb command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗██████╗
# ██╔══██╗██╔════╝██╔══██╗
# ██║ ██║█████╗ ██████╔╝
# ██║ ██║██╔══╝ ██╔══██╗
# ██████╔╝███████╗██████╔╝
# ╚═════╝ ╚══════╝╚═════╝
# Extract contents of a .deb file
$ ar vx foo.deb # -> data.tar.gz
$ tar xf data.tar.gz
#==============================##==============================#
# CMD deb #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command deb in a clear format. This allows users to quickly access the needed information for deb without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for deb are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1.4 - 🖥️mpack
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the mpack command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
# ████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
# ██╔████╔██║██████╔╝███████║██║ █████╔╝
# ██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
# ██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
# ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
# send email with a file
mpack -s subject file [email protected]
# Unfortunately mpack does not recognize '-' as an alias for stdin. But the following work, and can easily be wrapped in an (shell) alias or a script:
mpack -s subject /dev/stdin [email protected] < file
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command mpack in a clear format. This allows users to quickly access the needed information for mpack without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for mpack are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1.5 - 🖥️tar
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the tar command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ████████╗ █████╗ ██████╗
# ╚══██╔══╝██╔══██╗██╔══██╗
# ██║ ███████║██████╔╝
# ██║ ██╔══██║██╔══██╗
# ██║ ██║ ██║██║ ██║
# ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/
# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz
# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/
# To list the content of an .gz archive:
tar -ztvf /path/to/foo.tgz
# To extract a .bz2 archive:
tar -xjvf /path/to/foo.tgz
# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/
# To list the content of an .bz2 archive:
tar -jtvf /path/to/foo.tgz
# To create a .gz archive and exclude all jpg,gif,... from the tgz
tar czvf /path/to/foo.tgz --exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/
# To use parallel (multi-threaded) implementation of compression algorithms:
tar -z ... -> tar -Ipigz ...
tar -j ... -> tar -Ipbzip2 ...
tar -J ... -> tar -Ipixz ...
#==============================#
# CMD TAR - Archive
#==============================##==============================#
tar czf bar.tar.gz foo
# tar and gzip directory foo
tar xzvf = Xtract Ze Vucking Files [said in thick German accent]
# Option Mnemonics
tar pcvvf Stash{.tar.xz,} |tee Stash.idx
# Create tar called Stash.tar.xz of Stash and use 2 v options to long list and write to idx file
tar -zcvf archive-name.tar.gz directory-name
# Compress files in a directory
tar -C . -cf - "$dirname" | ssh [email protected] "tar -C /www/ -xvf -; # other commands.."
# Open a subshell remotely - Suppose you want a script that create a tar, copy and unzip it on a server...
# A typical use is when you are working on a web site locally and you want to deploy it to a server.
# furthermore you can add whatever command you want, like chmod for your files permissions..
######################
tar command examples in Linux
# Unix tar command line options
# ---------------------------------------
# In this section of UNIX tar command tutorial, we will see some useful options of tar command in Linux and we will use this options in our example to understand the usage of this option along-with tar command.
c -- create, for creating tar file
v -- verbose, the display name of files including,excluding from tar command
f -- following, used to point name of tar file to be created. it actually tells tar command that name of the file is "next" letter just after options.
x -- extract, for extracting files from the tar file.
t -- for viewing the content of tar file
z -- zip, tells tar command that creates tar file using gzip.
j –- another compressing option tells tar command to use bzip2 for compression
r -- update or adds file or directory in already existed .tar file
wildcards -- to specify patters in Unix tar command
# How to create tar archive or tar file in Unix
#-------------------------------------------------------
# tar command in unix linux examples
# Most of the use either WinZip or WinRAR in windows machine to zipping or creating archives of content so when we move to command line interface like Unix or Linux we struggle without those tools. UNIX tar command is similar to WinZip or WinRAR and you can use UNIX tar command to create both compressed or uncompressed (zipped) archives in UNIX.
# In this example of tar command, we will create tar file including all the files and directories or selected files and directories in Unix.
# here is our directory
ls -lrt
total 0
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxrwxrwx+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
# it has two files and one directory. now we will create a tar file with all these contents.
tar -cvf trading.tar *
currency
equity
stocks/
stocks/online_stock_exchanges.txt
# You see unix tar command is creating tar file with name "trading" with contents shown above. just to review here "-c" is used to create tar file "v" is used to be verbose and "f" is used to tell tar file name. You can see the tar file here
ls -lrt
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxrwxrwx+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
-rw-r--r-- 1 stock_trader Domain Users 10K Jul 18 12:29 trading.tar
# How to view contents of tar file in Unix or Linux
#-------------------------------------------------------------
# In earlier example of tar command in Unix or Linux we have created a uncompressed tar file called "trading.tar" now in this example we will see the actual content of that tar file.
tar -tvf trading.tar
-r--r--r-- stock_trader/Domain Users 0 2011-07-15 15:30 currency
-r--r--r-- stock_trader/Domain Users 0 2011-07-15 11:42 equity
drwxrwxrwx stock_trader/Domain Users 0 2011-07-15 14:33 stocks/
-rwxrwxrwx stock_trader/Domain Users 0 2011-07-15 14:33 stocks/online_stock_exchanges.txt
# here option "t" is used to display content of tar file in unix while options "v" and "f" are for "verbose" and "following". now you can clearly see that all the files which we wanted to be included in tar file are there.
# How to extract contents from a tar file in Unix
#-----------------------------------------------------------
# In this example of unix tar command we will see how to extract files or directories from a tar file in unix or Linux. We will use same trading.tar file created in earlier example. In this example we will create a directory "trading" and extract contents of trading.tar on that directory.
ls -lrt
total 12K
-rw-r--r-- 1 stock_trader Domain Users 10K Jul 18 12:37 trading.tar
# Now the directory is empty just trading.tar file
tar -xvf trading.tar
currency
equity
stocks/
stocks/online_stock_exchanges.txt
# This unix tar command will extract content of trading.tar in current directory. "x" is used for extracting. "v" is again for verbose and optional parameter in all our example.
ls -lrt
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxr-xr-x+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
-rw-r--r-- 1 stock_trader Domain Users 10K Jul 18 12:37 trading.tar
# Now you can see that all the files and directories which were included in tar file (stocks, equity and currency) has been extracted successfully.
# How to create tar file in Unix with just specified contents
#-------------------------------------------------------------------------
#In above example of tar command in unix we have created tar file with all the contents available in current directory but we can also create tar file with selective content as shown in above example.
# Now in our current directory we have both files and directories and we just want to include two files equity and currency in our tar file.
ls -lrt
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxrwxrwx+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
-rw-r--r-- 1 stock_trader Domain Users 10K Jul 18 12:29 trading.tar
drwxr-xr-x+ 1 stock_trader Domain Users 0 Jul 18 12:46 new/
tar -cvf equitytrading.tar equity currency
equity
currency
# you see only two files equity and currency are included in our tar file.
# How to create compressed tar file using gzip in Unix
#------------------------------------------------------------------
# In our previous example of Linux tar command we have created uncompressed tar file but most of the time we also need to create compressed tar file using gzip or bzip2. In this example of tar command in Linux we will learn about creating tar file using gzip.
tar -zcvf trading.tgz *
currency
equity
stocks/
stocks/online_stock_exchanges.txt
# you see creating tar file with gzip is very easy just use "-z" option and it will crate a gzip tar. .tgz or tar.gz extension is used to denote tar file with gzip. size of a compressed tar file is far less than uncompressed one.
ls -lrt
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxrwxrwx+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
-rw-r--r-- 1 stock_trader Domain Users 219 Jul 18 13:01 trading.tgz
# you can also view contents of gzip tar file by using earlier command in combination of "z" option and same is true for extracting content from gzip tar. below examples of unix tar command will show how to view contents of .tgz or .tar.gz file in unix.
tar -ztvf trading.tgz
-r--r--r-- stock_trader/Domain Users 0 2011-07-15 15:30 currency
-r--r--r-- stock_trader/Domain Users 0 2011-07-15 11:42 equity
drwxrwxrwx stock_trader/Domain Users 0 2011-07-15 14:33 stocks/
-rwxrwxrwx stock_trader/Domain Users 0 2011-07-15 14:33 stocks/online_stock_exchanges.txt
# Similarly we can extract contents from a .tgz or .tar.gz file as shown in below example of unix tar command :
tar -zxvf trading.tgz
currency
equity
stocks/
stocks/online_stock_exchanges.txt
ls -lrt
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 11:42 equity
drwxr-xr-x+ 1 stock_trader Domain Users 0 Jul 15 14:33 stocks/
-r--r--r-- 1 stock_trader Domain Users 0 Jul 15 15:30 currency
-rw-r--r-- 1 stock_trader Domain Users 219 Jul 18 13:07 trading.tgz
# How to create compressed tar file using bzip2 in Unix
#--------------------------------------------------------------------
# bzip2 is another compression option we have which we can use with unix tar command. its exactly similar with our earlier option of compressing using gzip but instead of "z" option we need to use "j" tar option to create bzip2 file as shown in below example of tar command in unix.
tar -jcvf trading.tar.bz2 *
currency
equity
stocks/
stocks/online_stock_exchanges.txt
ls -lrt trading.tar.bz2
-rw-r--r-- 1 stock_trader Domain Users 593 Jul 18 13:11 trading.tar.bz2
# .tar.bz2 is used to denote a tar file with bzip2 compression. for viewing contents of bzip2 tar file and extracting content we can use as shown in example of UNIX tar command with gzip compression, just replace "-z" with "-j" for bzip2.
# How to extract a particular file form .tar, .tar.gz or .tar.bzip2
#----------------------------------------------------------------------------
# In previous examples of extracting contetns from tar file we have extracted everything. sometime we just need a specific file from tar file. in this example of unix tar command we will extract a particular file from a tar archive.
tar -jxvf trading.tar.bz2 equity
equity
# its simple just specify name of file in this case its "equity". if your tar file is gzip one then use "-z" that is it. You can also use combination of grep and find command with tar to get more dynamic use.
# How to extract group of file or directory from form .tar, .tar.gz or .tar.bzip2 in UNIX
#---------------------------------------------------------------------------------------------------
# you can extract a group of file form .tar, .tar.gz or .tar.bzip2 in Unix by specifying a matching pattern and using option "--wildcards". let us show an example of tar command in unix with --wildcards
tar -jxvf trading.tar.bz2 --wildcards "s*"
stocks/
stocks/online_stock_exchanges.txt
In above example of UNIX tar command we are extracting all files or directory which names starts with "s".
# How to update existing tar file in Linux
#----------------------------------------------
# You can also update or append new files in already created tar file. option"-r" is used for that. Let’s see an example of updatating tar file using tar command in UNIX:
tar -cvf sample.tar equity currency
equity
currency
tar -rvf sample.tar gold
gold
tar -tvf sample.tar
-r--r--r-- stock_trader/Domain Users 0 2011-07-15 11:42 equity
-r--r--r-- stock_trader/Domain Users 221 2011-07-18 13:10 currency
-rw-r--r-- stock_trader/Domain Users 0 2011-07-18 13:30 gold
# Apparently can not update compressed archives.if you try to do you will get error "tar: Cannot update compressed archives"
# Calculating size of tar file in UNIX
#-------------------------------------------
#Some time its useful to know the size of tar file before creating it and you can get it by using unix tar command as shown in below example:
tar -cf - * | wc -c
20480
# Size shown here is in KB and you can also calculate size for compressed tar file by using "z" for gzip and "j" for bzip2
tar Jpcvvf Stash{.tar.xz,} |tee Stash.idx
# Create(c) tar called (f) Stash.tar.xz of Stash with xz compression (J) and use 2 v options to long list and write to idx file. Brace expansion creates the tar file arg and the directory arg.
tar ztvf large.tar.gz | awk '{s+=$3}END{print s}'
# Use awk to sum up the sizes of the files inside a compressed archive file. Unfortunately you can't use gzip -l on files where the uncompressed data is greater than 4GB.
#########################
{ find /one; find /two; } | tar zcvf one-and-two.tar.gz -T -
# You can use a bracketed command to pipe two find outputs into one tar.
# Create an encrypted tar file with openssl
tar c paths_to_files_and_dirs | gzip -c | openssl des3 > encrypted.tar.gz
# Explanation: Decrypt with: openssl des3 -d < encrypted.tar.gz | tar zx
# Create .tar.bz2
tar -cvjf output.tar.bz2 ./
# List contents of tar file
tar --list -f items.tar
tar tvf backup.tar | grep -v "/$" | wc -l
# Count the number of files, but not directories, stored in a tar file.
#==============================##==============================#
# CMD TAR - Archive
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command tar in a clear format. This allows users to quickly access the needed information for tar without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for tar are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1.6 - 🖥️unzip
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the unzip command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██╗ ██╗███╗ ██╗███████╗██╗██████╗
# ██║ ██║████╗ ██║╚══███╔╝██║██╔══██╗
# ██║ ██║██╔██╗ ██║ ███╔╝ ██║██████╔╝
# ██║ ██║██║╚██╗██║ ███╔╝ ██║██╔═══╝
# ╚██████╔╝██║ ╚████║███████╗██║██║
# ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝╚═╝
# Extract archive
unzip archive.zip
# Test integrity of archive
unzip -tq archive.zip
# List files and directories in a file
unzip -l archive.zip
# Clean up the garbage an accidental unzipping makes - List out all the names from the zip file and pass it to xargs utility to delete each one of them
unzip -Z -1 <filename.zip> | xargs -I{} rm -v {}
#==============================##==============================#
# CMD UNZIP #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command unzip in a clear format. This allows users to quickly access the needed information for unzip without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for unzip are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2 - Compression Tools
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
Compression tools reduce the size of files by encoding data more efficiently. This is useful for saving disk space and reducing the time required to transfer files over networks. Compression can be lossless, preserving the original data, or lossy, where some data is discarded to achieve higher compression ratios.
2.1 - 🖥️7z
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the 7z command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ███████╗███████╗
# ╚════██║╚══███╔╝
# ██╔╝ ███╔╝
# ██╔╝ ███╔╝
# ██║ ███████╗
# ╚═╝ ╚══════╝
A file archiver with highest compression ratio
Args:
a add
d delete
e extract
l list
t test
u update
x extract with full paths
Example:
7z a -t7z -m0-lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1
-t7z 7z archive
-m0=lzma lzma method
-mx=9 level of compression = 9 (ultra)
-mfb=64 number of fast bytes for lzma = 64
-md=32m dictionary size = 32 Mb
-ms=on solid archive = on
7z exit codes:
0 normal (no errors or warnings)
1 warning (non-fatal errors)
2 fatal error
7 bad cli arguments
8 not enough memory for operation
255 process was interrupted
#==============================##==============================#
# CMD 7z #
#==============================##==============================#
7z l philip-glass-linux-0.8-minimal.iso
# 7zip can also list the contents of iso images and extract them too. No need to mount the image.
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command 7z in a clear format. This allows users to quickly access the needed information for 7z without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for 7z are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2.2 - 🖥️bzip2
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the bzip2 command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗██╗██████╗ ██████╗
# ██╔══██╗╚══███╔╝██║██╔══██╗╚════██╗
# ██████╔╝ ███╔╝ ██║██████╔╝ █████╔╝
# ██╔══██╗ ███╔╝ ██║██╔═══╝ ██╔═══╝
# ██████╔╝███████╗██║██║ ███████╗
# ╚═════╝ ╚══════╝╚═╝╚═╝ ╚══════╝
#==============================#
# CMD BZIP2
#==============================##==============================#
# compress foo -> foo.bz2
bzip2 -z foo
# decompress foo.bz2 -> foo
bzip2 -d foo.bz2
# compress foo to stdout
bzip2 -zc foo > foo.bz2
# decompress foo.bz2 to stdout
bzip2 -dc foo.bz2
#==============================#
# CMD BZIP2
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command bzip2 in a clear format. This allows users to quickly access the needed information for bzip2 without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for bzip2 are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2.3 - 🖥️gunzip
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the gunzip command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ██╗ ██╗███╗ ██╗███████╗██╗██████╗
# ██╔════╝ ██║ ██║████╗ ██║╚══███╔╝██║██╔══██╗
# ██║ ███╗██║ ██║██╔██╗ ██║ ███╔╝ ██║██████╔╝
# ██║ ██║██║ ██║██║╚██╗██║ ███╔╝ ██║██╔═══╝
# ╚██████╔╝╚██████╔╝██║ ╚████║███████╗██║██║
# ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝╚═╝
Gunzip
# gzip compresses,
# gunzip decompresses.
# gunzip is the same as gzip -d.
Files compressed with gzip command can be restored to their original form using the gunzip command.
gunzip file1.gz
# Installed packages:
gunzip -c /var/log/apt/history.log.*.gz | grep 'apt-get install' | cut -f4- -d" " | tr ' ' $'\n' | sort -u
# IBM AIX: Extract a .tar.gz archive in one shot
gunzip -c file.tar.gz | tar -xvf -
#==============================##==============================#
# CMD gunzip #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command gunzip in a clear format. This allows users to quickly access the needed information for gunzip without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for gunzip are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2.4 - 🖥️gzip
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the gzip command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗██╗██████╗
# ██╔════╝ ╚══███╔╝██║██╔══██╗
# ██║ ███╗ ███╔╝ ██║██████╔╝
# ██║ ██║ ███╔╝ ██║██╔═══╝
# ╚██████╔╝███████╗██║██║
# ╚═════╝ ╚══════╝╚═╝╚═╝
# To create a *.gz compressed file
gzip test.txt
# To create a *.gz compressed file to a specific location using -c option (standard out)
gzip -c test.txt > test_custom.txt.gz
# To uncompress a *.gz file
gzip -d test.txt.gz
# Display compression ratio of the compressed file using gzip -l
gzip -l *.gz
# Recursively compress all the files under a specified directory
gzip -r documents_directory
# To create a *.gz compressed file and keep the original
gzip < test.txt > test.txt.gz
gunzip
# decompresses. gunzip is the same as gzip -d.
# Show the process in a tree format, search for gzip and show 8 lines of pre-match context to see its "family". The [] around the g in gzip is a regex trick to avoid matching the grep process itself.
ps auxwf | grep -B8 "[g]zip"
# Create a compressed tar file that rsync will transfer efficiently
GZIP='--rsyncable' tar cvzf bobsbackup.tar.gz /home/bob
# Explanation: rsync works by comparing files on the local and remote machine and only sending those parts of the file that have changed. The normal way compression works, it results in everything after the modification changing, meaning lots of data ends up going over the network when you try to rsync compressed files.
# The --rsyncable option to gzip changes the compression scheme so that modifications to the input file only affect the part of the file where they're located. This allows rsync to work its magic. In this one-liner, the z option to tar calls gzip, which recognizes and uses any options specified in the GZIP environment variable.
# Limitations: Using the --rsyncable option results in a slightly larger compressed file. Not all versions of gzip include this feature - use the --help option to see if it's available on your system.
#==============================##==============================#
# CMD GZIP #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command gzip in a clear format. This allows users to quickly access the needed information for gzip without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for gzip are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2.5 - 🖥️zip
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the zip command with important options and switches using examples.
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ███████╗██╗██████╗
# ╚══███╔╝██║██╔══██╗
# ███╔╝ ██║██████╔╝
# ███╔╝ ██║██╔═══╝
# ███████╗██║██║
# ╚══════╝╚═╝╚═╝
# Create zip file
zip archive.zip file1 directory/
# To list, test and extract zip archives, see unzip
cheat unzip
# Bash command to zip some content - This command will zip the file file.txt and all the sh files contained in setup folder in a zip named myzip.zip.
# Then adds the file Third/otherfile.txt in then same archive with the last command
ZIP_NAME="myzip.zip"
zip "$SETUP_ZIP_DIR"/$ZIP_NAME setup/*.sh file.txt
zip -g "$SETUP_ZIP_DIR"/$ZIP_NAME Third/otherfile.txt
# Recreate or update an existing zip file and remove files that do not exist anymore
zip --filesync -r /path/to/out.zip /path/to/dir
# Explanation: zip does not have an explicit option to overwrite/recreate an existing zip file. If the specified destination file already exists, zip updates it. The problem is that files you did not specify to add to the zip but they already existed in the zip, will not be removed.
# For example let's say you created a zip file from a directory with the command:
zip -r /path/to/out.zip /path/to/dir
# Next you delete some files from the directory and repeat the command to recreate the zip. But that will not recreate the zip, it will only update it, and so the file you deleted from the directory will still be there in the zip.
# One way to recreate the zip is to delete the file first. Another, better way is to use the --filesync or -FS flag. With this flag zip will remove files from the zip that do not exist anymore in the filesystem. This is more efficient than recreating the zip.
# zip-dir - zip directories
# Zip all top level directories
for i in */; do if [ ! -f "${i%/}.zip" ]; then zip -r "${i%/}.zip" "$i"; fi done
#==============================##==============================#
# CMD ZIP #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command zip in a clear format. This allows users to quickly access the needed information for zip without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for zip are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░