In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
A method for packing, compressing and decompressing files in a Linux system, and a super utility command that enables users to search for matching information in text files based on a keyword and search for specific files in the entire file system based on a specified name or attribute.
The tar command is used to package, compress or extract files in the format of "tar [options] [files]".
The most common compression formats in Windows systems are .rar and .zip bar, while there are many common formats in Linux systems, but they mainly use .tar or .tar.gz or .tar.bz2 formats. Students don't have to worry about too many formats to remember. In fact, most of these are done by the tar command. Let me tell you the most important parameters. First of all, the "- c" parameter is used to create compressed files. The "- x" parameter is used to extract the file, so the two cannot be used together at the same time. Secondly, the "- z" parameter specifies that the Gzip format is used to compress and extract the file, and the "- j" parameter specifies the use of the bzip2 parameter to compress and extract the file. During decompression, we decide what the format parameter is according to the suffix of the file, and some packaging operations take hours. If there is no output on the screen, you will certainly doubt whether the computer has crashed, and it is difficult to judge the progress of packaging. It is highly recommended to use the "- v" parameter to continuously display the compression or decompression process to the user. The "- C" parameter is used to specify the specified directory to be extracted, and the "- f" parameter is particularly important. It must be placed in the last bit of the parameter, representing the name of the package to be compressed or decompressed. So usually I will use the "tar-czvf package name. Tar.gz to package the directory" command to package the specified files, then decompress is the "tar-xzvf package name .tar.gz" command, let's demonstrate the operation of packaging compression and decompression one by one.
Use the tar command to package and compress the files in the / etc directory in gzip format, and name the files etc.tar.gz:
[root@linuxprobe ~] # tar czvf etc.tar.gz / etctar: Removing leading `/ 'from member names/etc//etc/fstab/etc/crypttab/etc/mtab/etc/fonts//etc/fonts/conf.d//etc/fonts/conf.d/65-0-madan.conf/etc/fonts/conf.d/59-liberation-sans.conf/etc/fonts/conf.d/90-ttf-arphic-uming-embolden.conf/etc/fonts/conf.d/59-liberation-mono .conf / etc/fonts/conf.d/66-sil-nuosu.conf... Omit part of the compression process.
Extract the compressed package file you just packaged to the / root/etc directory:
[root@linuxprobe ~] # mkdir / root/etc [root@linuxprobe ~] # tar xzvf etc.tar.gz-C / root/etcetc/etc/fstabetc/crypttabetc/mtabetc/fonts/etc/fonts/conf.d/etc/fonts/conf.d/65-0-madan.confetc/fonts/conf.d/59-liberation-sans.confetc/fonts/conf.d/90-ttf-arphic-uming-embolden.confetc/fonts/conf.d/59-liberation-mono.confetc/fonts/conf.d/66 -sil-nuosu.confetc/fonts/conf.d/65-1-vlgothic-gothic.confetc/fonts/conf.d/65-0-lohit-bengali.confetc/fonts/conf.d/20-unhint-small-dejavu-sans.conf
The find command is used to find files in the format "find [find path] find conditional action".
Everything in the Linux system is a file. The search in the Linux system is generally done through the find command, which can be used as a match according to different file characteristics (such as file name, size, modification time, permissions, etc.). Once the match is reached, the user will be displayed on the screen by default. For the basic matching items, please see the table below. I will mainly explain the important role of the "--exec" parameter. This parameter is used to hand over the results found by the find command to subsequent commands for further processing, very similar to the pipe character technique that we will talk about in the next chapter.
The configuration files in the Linux system are saved to the / etc directory according to the FHS protocol (Chapter 6 is detailed). If we want to get all the files in this directory that begin with host, we can do this:
[root@linuxprobe ~] # find / etc-name "host*"-print/etc/avahi/hosts/etc/host.conf/etc/hosts/etc/hosts.allow/etc/hosts.deny/etc/selinux/targeted/modules/active/modules/hostname.pp/etc/hostname
To search the entire system for files that include SUID permissions in all permissions, simply use the minus sign-4000:
[root@linuxprobe] # find /-perm-4000-print/usr/bin/fusermount/usr/bin/su/usr/bin/umount/usr/bin/passwd/usr/sbin/userhelper/usr/sbin/usernetctl
Elevate the topic: find all the files belonging to linuxprobe users in the entire file system and copy them to the / root/findresults directory.
The focus of this question is "- exec {}\;" where {} represents the file by file searched by the find command, and remember that the command must end with\
[root@linuxprobe ~] # find /-user linuxprobe-exec cp-arf {} / root/findresults/\
The grep command is used to search and match keywords for text content in the format of "grep [options] [file]" (not in real time).
Grep command can be regarded as the most widely used text search and matching tool. Although there are many parameters, they are basically not needed. I have used nearly seven years of work and teaching experience to put forward the writing idea of "getting rid of impracticality" at the core of this book. It is absolutely not nonsense for a Linux lecturer to write a book at the level of a "technical porter" rather than a refiner of real quality technical knowledge. That will definitely hurt a big wave of students, so Mr. Liu only talks about the two most commonly used parameters here, as long as he can use the "- n" parameter to display the line number of the searched information. Using the "- v" parameter to deselect information (that is, all lines of information that do not contain keywords) will almost complete 80% of your future work needs. As for the other hundreds of parameters, in case your work encounters in the future It's not too late to check again with the "man grep" command.
The / etc/passwd file in the Linux system is a file that holds all the user information, and once the user's login terminal is set to "/ sbin/nologin", it is no longer allowed to log in to the system, so we can use the grep command to match all the user information in the current system that is not allowed to log in to the system:
[root@linuxprobe ~] # grep / sbin/nologin / etc/passwdbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.