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


-rw-r--r--. 1 root root K Feb 17 20:16 services.gz



Download 1.85 Mb.
View original pdf
Page25/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   21   22   23   24   25   26   27   28   ...   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
-rw-r--r--. 1 root root K Feb 17 20:16 services.gz
[root@rhel-instance tmp]# gunzip services.gz
[root@rhel-instance tmp]# ls -lh services
-rw-r--r--. 1 root root K Feb 17 20:16 services
Now, we can combine the two of them, packing and compressing them:
[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
[root@rhel-instance
]# gzip etc-backup.tar

[root@rhel-instance
]# ls etc-backup.tar.gz

etc-backup.tar.gz
[root@rhel-instance
]# ls -lh etc-backup.tar.gz

-rw-r--r--. 1 root root M Feb 17 20:20 etc-backup.tar.
gz
This way, we pack and compress in two steps.
The tar command is smart enough to be able to perform packing and compression in a single step:
[root@rhel-instance
]# rm -f etc-backup.tar.gz

[root@rhel-instance
]# tar -czf etc-backup.tar.gz /etc/

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

-rw-r--r--. 1 root root M Feb 17 20:22 etc-backup.tar.
gz

Basic Commands and Simple Shell Scripts -z This compresses the newly created tar file with gzip. It is also usable for decompression.
We may want to review that same option when decompressing:
[root@rhel-instance
]# cd tmp/

[root@rhel-instance tmp]# rm -rf etc
[root@rhel-instance tmp]# tar -xzf ../etc-backup.tar.gz
[root@rhel-instance tmp]# ls
etc
As you can see, it’s very easy to pack and compress files using tar and gzip. There are other available compression methods with higher ratios, such as bzip2 or xz, that you may want to try, too. Now, let’s move onto combine all the commands that we have learned into a powerful way to automate – by creating shell scripts.

Download 1.85 Mb.

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




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

    Main page