Aakash Kushwaha Aakash Kushwaha - 10 months ago 45
Bash Question

using tr command to read permission

Following commands have been executed by me

[root@gblabvl31 Aakash]# cat > file1.txt
[root@gblabvl31 Aakash]# cat file1.txt |tr '[-rwx]' '[0421]' > file2.txt
[root@gblabvl31 Aakash]# cat file2.txt

I could not understand why the expected output which is


is not achieved

Answer Source

tr is a little special and expects its parameters to already be character classes, thus

$ echo '-rwx' | tr -- '-rwx' '0421'

yields the expected result.