The tr command is used to replace characters in text files in the form of "tr [original character] [target character].
In many cases, we want to quickly replace some words in the text, or replace the whole text content.
In other words, if we do manual replacement, it will inevitably take too much work. Especially when we need to deal with large quantities of content, manual replacement is more important.
It's unrealistic. At this point, you can use the cat command to read the text to be processed, and then through the pipe character (see Chapter 3 for details).
Pass these text contents to the tr command for replacement. For example, replace all the English in a text.
[root@localhost ~]# cat anaconda-ks.cfg | tr [a-z] [A-Z] #VERSION=DEVEL # SYSTEM AUTHORIZATION INFORMATION AUTH --ENABLESHADOW --PASSALGO=SHA512 # USE CDROM INSTALLATION MEDIA CDROM # USE GRAPHICAL INSTALL GRAPHICAL # RUN THE SETUP AGENT ON FIRST BOOT FIRSTBOOT --ENABLE IGNOREDISK --ONLY-USE=VDA # KEYBOARD LAYOUTS KEYBOARD --VCKEYMAP=CN --XLAYOUTS='CN' # SYSTEM LANGUAGE LANG ZH_CN.UTF-8 # NETWORK INFORMATION NETWORK --BOOTPROTO=STATIC --DEVICE=ETH0 --GATEWAY=192.168.1.1 --IP=192.168.1.6 --NAMESERVER=192.168.1.1 --NETMASK=255.255.255.0 --IPV6=AUTO --ACTIVATE NETWORK --HOSTNAME=LOCALHOST.LOCALDOMAIN # ROOT PASSWORD ROOTPW --ISCRYPTED $6$.W1Y5LCJA2PGKDQI$WJWUSXHSRSW.JUJIBSGZQC0TQHTCW3YMTMFYMIGZRIQY5A1BXCE2K2ACWCBMLV.U1IEJROF747TB92IO9DXLZ/ # SYSTEM TIMEZONE TIMEZONE ASIA/SHANGHAI --ISUTC USER --NAME=JINGPAN --PASSWORD=$6$KUDWINSUFYZ1.ULB$RG3WSHGF5SUZHGGZPSTNDGIX4ZKVGUGFLVZUJW7L7N8KFHCOUYK3QUKMDIFA1YHKBAPNUZP7XMNIPNF5OR9IS. --ISCRYPTED --GECOS="JINGPAN" # SYSTEM BOOTLOADER CONFIGURATION BOOTLOADER --APPEND=" CRASHKERNEL=AUTO" --LOCATION=MBR --BOOT-DRIVE=VDA AUTOPART --TYPE=LVM # PARTITION CLEARING INFORMATION CLEARPART --NONE --INITLABEL %PACKAGES @^MINIMAL @CORE @DEVELOPMENT KEXEC-TOOLS %END %ADDON COM_REDHAT_KDUMP --ENABLE --RESERVE-MB='AUTO' %END
The WC command is used to count the number of lines, words and bytes of the specified text in the form of "wc [parameter] text".
- l) Display only rows
- w. Show only the number of words
- c. Display only the number of bytes
In Linux system, passwd is a file used to save system account information. It is necessary to count how many passwd files are in the current system.
Users, can use the following commands to query, is it amazing: uuuuuuuuuuu
[root@localhost ~]# wc -l /etc/passwd 40 /etc/passwd
The stat command is used to view the specific storage information and time of the file in the format of "stat file name".
The stat command can be used to view file storage information and time information, and the command stat anaconda-ks.cfg will display
Three time states of the file (bolded): Access, Modify, Change.
[root@localhost ~]# stat anaconda-ks.cfg File: "anaconda-ks.cfg" Size: 1441 Blocks: 8 IO Block: 4096 Ordinary documents Device: 801h/2049d Inode: 262153 Links: 1 Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2018-08-04 10:27:17.372963432 +0800 Modify: 2017-11-06 11:50:09.013998957 +0800 Change: 2017-11-06 11:50:30.084998941 +0800
The cut command is used to extract text characters by column in the form of cut [parameter] text.
In Linux system, how to extract the most desired data accurately is also what we should focus on. commonly
For example, it is relatively simple to extract data in line-based way, just need to set up the keywords to search. however
If you search by column, you need to use not only the - f parameter to set the number of columns you need to see, but also the - d parameter to set the interval symbol.
passwd saves user data information, and each value of user information is separated by a colon. Next, we use the colon.
The following command attempts to extract the username information in passwd file, that is, extract the first column with a colon (:) as an interval symbol:
[root@localhost ~]# head -n 2 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin [root@localhost ~]# cut -d: -f1 /etc/passwd root bin daemon adm lp sync shutdown halt mail uucp operator games gopher ftp nobody dbus usbmuxd rpc rtkit avahi-autoipd vcsa abrt rpcuser nfsnobody haldaemon ntp apache saslauth postfix gdm pulse sshd tcpdump jingpan radvd qemu nignx nginx test rich
The diff command is used to compare the differences between multiple text files in the form of "diff [parameter] files".
When using the diff command, you can not only use the -- brief parameter to confirm whether the two files are different, but also use the - c parameter.
It is absolutely a powerful artifact for judging whether a document has been tampered with. For example, first
Use the cat command to view the contents of diff_A.txt and diff_B.txt files respectively, and then compare:
Next, the diff --brief command is used to display the results of the comparison to determine whether the file is the same:
[root@localhost ~]# diff --brief diff_A.txt diff_B.txt Files diff_A.txt and diff_B.txt differ
Finally, diff commands with - c parameters are used to describe the specific differences in file contents:
[root@localhost ~]# cat diff_B.txt Welcome tooo linuxshell.com Red Hat certified Free Linux LeSSonS /////////......//////// Professional guidance Linux Course [root@localhost ~]# diff -c diff_A.txt diff_B.txt *** diff_A.txt 2018-08-04 10:53:55.793962098 +0800 --- diff_B.txt 2018-08-04 10:58:14.587961708 +0800 *************** *** 1,5 **** ! Welcome to linuxshell.com Red Hat certified ! Free Linux Lessons Professional guidance Linux Course --- 1,7 ---- ! Welcome tooo linuxshell.com ! Red Hat certified ! Free Linux LeSSonS ! /////////......//////// Professional guidance Linux Course
The touch command is used to create a blank file or set the time of the file in the format "touch [options] [files].
In terms of creating blank text files, this touch command is fairly straightforward, so straightforward that there is no need to spread it out.
For example, the touch linuxprobe command can create a blank text file called linuxprobe. To touch life
To say, the difficult operation is mainly reflected in setting the file content modification time (mtime), file permissions or attributes.
Change time (ctime) and file read time (atime) above.
- a only modifies atime
- m only modifies "mtime"
-d Modify atime and mtime at the same time
Next, we use the ls command to view the modification time of a file, then modify the file, and finally touch it.
The command sets the time of the modified file to the time before the modification (which many hackers do):
[root@localhost ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1441 11 Month 62017 anaconda-ks.cfg [root@localhost ~]# echo "Visit the linuxshell.com to learn linux skills" >> anaconda-ks.cfg [root@localhost ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1488 8 Month 411:10 anaconda-ks.cfg [root@localhost ~]# touch -d "2017-11-06 15:00" anaconda-ks.cfg [root@localhost ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1488 11 Month 62017 anaconda-ks.cfg
The DD command is used to copy or convert files according to the specified size and number of data blocks in the format of "dd [parameters].
The dd command is an important and distinctive command that allows users to specify size and number.
Data blocks are used to copy the contents of files. Of course, if you want, you can also transform the data in the replication process. Linux
There is a device file named / dev/zero in the system, which is full of philosophical theory when it is explained in class. because
This file does not take up system storage space, but it can provide endless data, so you can use it as dd
The input file of the command to generate a file of specified size. The parameters and functions of the dd command are as follows.
if) Enter the name of the file
Output file name
bs) Set the size of each "block"
Set the number of blocks to copy
For example, we can use the dd command to extract a 560 MB block from the / dev/zero device file, and then
Save as a file named 560_file. After understanding this command, you can create files of any size at will:
[root@localhost e]# dd if=/dev/zero of=560_file count=1 bs=560M Record 1 + 0 reads Write down 1 + 0 587202560 bytes (587 MB) have been copied, 88.8811 seconds, 6.6 MB/seconds
The dd command is not limited to copying files. If you want to make the CD-ROM in the CD-ROM device into iso lattice
Mirror files in Windows system need the help of third-party software, but they can be directly used in Linux system.
Use the dd command to suppress the CD-ROM image file and turn it into an instant iso image:
[root@linuxprobe ~]# dd if=/dev/cdrom of=RHEL-server-7.0-x86_64-LinuxProbe.Com.iso
7311360+0 records in
7311360+0 records out
3743416320 bytes (3.7 GB) copied, 370.758 s, 10.1 MB/s
Considering that some readers will struggle with the relationship between the size of bs blocks and the number of count s, here's an example of eating
Explain. Assuming Xiao Ming's meal quantity (i.e. demand) is a fixed value, the size of the spoon used to serve the meal is the size of the bs block.
And the number of times a spoon serves a meal is the number of count s. Xiao Ming needs a spoon size (bs block) if he wants to be full.
Balance size with the number of counts served with a spoon. The bigger the spoon, the fewer times the spoon is used to serve the meal. As can be seen from the above, bs and count are used to specify the size of the capacity, as long as they can meet the needs, they can be arbitrarily combined with each other.