3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel



Download 1.85 Mb.
View original pdf
Page24/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   20   21   22   23   24   25   26   27   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
Using tar and gzip
Sometimes, we want to pack a full directory (including files) into a single file for backup purposes or to simply share it more easily. The command that can help aggregate files into one is tar.
First, we need to install tar:
[root@rhel-instance
]# yum install tar -y

We can try by creating (as root) a backup of the etc directory branch:
[root@rhel-instance
]# tar -cf etc-backup.tar /etc

tar: Removing leading '/' from member names
[root@rhel-instance
]# ls -lh etc-backup.tar

-rw-r--r--. 1 root root M Feb 17 20:08 etc-backup.tar
Let's check the options used -c Short for create. tar can put files together but also unpack them -f Short for file. We specify that the next parameter will be working with a file.
We can try to unpack it:
[root@rhel-instance
]# mkdir tmp

[root@rhel-instance
]# cd tmp/

[root@rhel-instance tmp]# tar -xf ../etc-backup.tar
[root@rhel-instance tmp]# ls
etc
Let’s check the new options used -x for extraction. It unpacks a tar file.
Observe that we created a directory called tmp to work on and that we pointed to the parent directory of tmp by using the .. shortcut (which refers to the parent directory of the current working directory).

Using tar and gzip
91
Let’s use gzip to compress a file. We can copy /etc/services and compress it:
[root@rhel-instance tmp]# cp /etc/services .
[root@rhel-instance tmp]# ls -lh services
-rw-r--r--. 1 root root K Jun 23 2020 services
[root@rhel-instance tmp]# gzip services
[root@rhel-instance tmp]# ls -lh services.gz
-rw-r--r--. 1 root root K Feb 17 20:16 services.gz
Please note that when using gzip, this will compress the specified file, adding the .gz extension to it, and the original file will not be kept. Also, be aware that the newly created file is one fifth of the size of the original file.
To recover it, we can run gunzip:

Download 1.85 Mb.

Share with your friends:
1   ...   20   21   22   23   24   25   26   27   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page