在linux系统上查看rev的作用
NAME
rev — reverse lines of a file or files
SYNOPSIS
rev [-V] [-h] [file ...]
DESCRIPTION
The rev utility copies the specified files to standard output, reversing
the order of characters in every line. If no files are specified, stan‐
dard input is read.
-V, --version
Output version information and exit.
-h, --help
Output help and exit.
上面已经说明得很清楚,其作用是反序一个文件或者多个文件的每一行。如果存在识别不是文件的情况,它就是从标准输入流中读取。先看两个文件的开头内容
test.sh的文件内容
lhj@lhj-virtual-machine:~$ cat test.sh
#!/bin/bash
a=$(pwd)
echo ${a}
test.php的文件开头的内容
lhj@lhj-virtual-machine:~$ head test.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| File and Directory Modes
|--------------------------------------------------------------------------
|
| These prefs are used when checking and setting modes when working
| with the file system. The defaults are fine on servers with proper
| security, but you may wish (or even need) to change the values in
使用rev反序单个文件
lhj@lhj-virtual-machine:~$ rev test.sh
hsab/nib/!#
)dwp($=a
}a{$ ohce
使用rev反序多个文件
lhj@lhj-virtual-machine:~$ rev test.sh test.php
hsab/nib/!#
)dwp($=a
}a{$ ohce
;)'dewolla ssecca tpircs tcerid oN'(tixe ))'HTAPESAB'(denifed ! ( fi php?<
*/
--------------------------------------------------------------------------|
sedoM yrotceriD dna eliF |
--------------------------------------------------------------------------|
|
gnikrow nehw sedom gnittes dna gnikcehc nehw desu era sferp esehT |
reporp htiw srevres no enif era stluafed ehT .metsys elif eht htiw |
ni seulav eht egnahc ot )deen neve ro( hsiw yam uoy tub ,ytiruces |
hcae rof ssecorp etarapes a gninnur ehcapA( stnemnorivne niatrec |
dluohs seulav latcO .).cte ,CEXEus ehcapA htiw IGC rednu PHP ,resu |
.yltcerroc edom eht tes ot desu eb syawla |
反序不是文件的
lhj@lhj-virtual-machine:~$ echo $a
1 2 3 4 5
lhj@lhj-virtual-machine:~$ echo ${a}|rev
5 4 3 2 1