linux poison RSS
linux poison Email

Perl Script: File test operators

Below is simple perl script which demonstrate the usage if file test operator ..
Feel free to use and copy this script:

Source: cat

$FILE = "server.txt";

if ( -b $FILE ){
        print "$FILE is block device \n";
if ( -c $FILE ){
        print "$FILE is char device \n";
if ( -d $FILE ){
        print "$FILE is dirctory \n";
if ( -e $FILE ){
        print "$FILE exists \n";
if ( -f $FILE ){
        print "$FILE is ordinary file \n";
if ( -l $FILE ){
        print "$FILE is symbolic link \n";
if ( -o $FILE ){
        print "$FILE is owned by current user. \n";

 if ( -p $FILE ){
        print "$FILE is named pipe \n";
if ( -r $FILE ){
        print "$FILE is a readable file \n";
if ( -s $FILE ){
        print "$FILE is non empty file. \n";
if ( -w $FILE ){
        print "$FILE is writable file \n";
if ( -x $FILE ){
        print "$FILE is exe file \n";
if ( -B $FILE ){
        print "$FILE is binary file \n";
if ( -T $FILE ){
        print "$FILE is text file \n";
if ( -S $FILE ){
        print "$FILE is socket file \n";

Output: perl

server.txt exists
server.txt is ordinary file
server.txt is owned by current user.
server.txt is a readable file
server.txt is non empty file.
server.txt is writable file
server.txt is text file


Post a Comment

Related Posts with Thumbnails