Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux tr command

Linux tr command

Linux Command Reference Linux Command Reference

The Linux tr command is used to translate or delete characters in a file.

The tr command reads data from standard input, translates the string, and outputs the result to standard output.

Syntax



tr [-cdst][--help][--version][第一字符集][第二字符集]  

tr [OPTION]…SET1[SET2] 

Parameter Description:

Character set ranges:

Example

To convert all lowercase letters in the file testfile to uppercase, you can use the following command:



cat testfile |tr a-z A-Z 

The contents of the file testfile are as follows:



$ cat testfile         #testfile原来的内容  

Linux networks are becoming more and more common, 

but scurity is often an overlooked  

issue. Unfortunately, in today’s environment all networks 

are potential hacker targets,  

fro0m tp-secret military research networks to small home LANs.  

Linux Network Securty focuses on securing Linux in a 

networked environment, where the  

security of the entire network needs to be considered

rather than just isolated machines.  

It uses a mix of theory and practicl techniques to 

teach administrators how to install and  

use security applications, as well as how the 

applcations work and why they are necesary. 

After case conversion with the tr command, the following output is obtained:



$ cat testfile | tr a-z A-Z #转换后的输出  

LINUX NETWORKS ARE BECOMING MORE AND MORE COMMON, BUT SCURITY IS OFTEN AN OVERLOOKED  

ISSUE. UNFORTUNATELY, IN TODAY’S ENVIRONMENT ALL NETWORKS ARE POTENTIAL HACKER TARGETS,  

FROM TP-SECRET MILITARY RESEARCH NETWORKS TO SMALL HOME LANS.  

LINUX NETWORK SECURTY FOCUSES ON SECURING LINUX IN A NETWORKED ENVIRONMENT, WHERE THE  

SECURITY OF THE ENTIRE NETWORK NEEDS TO BE CONSIDERED RATHER THAN JUST ISOLATED MACHINES.  

IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO TEACH ADMINISTRATORS HOW TO INSTALL AND  

USE SECURITY APPLICATIONS, AS WELL AS HOW THE APPLCATIONS WORK AND WHY THEY ARE NECESARY. 

Case conversion can also be achieved with the [:lower][:upper] parameters. For example, use the following command:

cat testfile |tr [:lower:] [:upper:] 

The output is as follows:



$ cat testfile | tr [:lower:] [:upper:] #转换后的输出  

LINUX NETWORKS ARE BECOMING MORE AND MORE COMMON, BUT SCURITY IS OFTEN AN OVERLOOKED  

ISSUE. UNFORTUNATELY, IN TODAY’S ENVIRONMENT ALL NETWORKS ARE POTENTIAL HACKER TARGETS,  

FROM TP-SECRET MILITARY RESEARCH NETWORKS TO SMALL HOME LANS.  

LINUX NETWORK SECURTY FOCUSES ON SECURING LINUX IN A NETWORKED ENVIRONMENT, WHERE THE  

SECURITY OF THE ENTIRE NETWORK NEEDS TO BE CONSIDERED RATHER THAN JUST ISOLATED MACHINES.  

IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO TEACH ADMINISTRATORS HOW TO INSTALL AND  

USE SECURITY APPLICATIONS, AS WELL AS HOW THE APPLCATIONS WORK AND WHY THEY ARE NECESARY. 

Linux Command Reference Linux Command Reference