NAME

Rex::Commands::Fs

DESCRIPTION

With this module you can do file system tasks like creating a directory, removing files, move files, and more.

SYNOPSIS

my @files = list_files "/etc";

unlink("/tmp/file");

rmdir("/tmp");
mkdir("/tmp");

my %stat = stat("/etc/passwd");

my $link = readlink("/path/to/a/link");
symlink("/source", "/dest");

rename("oldname", "newname");

chdir("/tmp");

is_file("/etc/passwd");
is_dir("/etc");
is_writeable("/tmp");
is_writable("/tmp");

EXPORTED FUNCTIONS

list_files("/path");

This function list all entries (files, directories, ...) in a given directory and returns a array.

task "ls-etc", "server01", sub {
   my @tmp_files = grep { /\.tmp$/ } list_files("/etc");
};
symlink($from, $to)

This function will create a symlink from $from to $to.

task "symlink", "server01", sub {
   symlink("/var/www/versions/1.0.0", "/var/www/html");
};
unlink($file)

This function will remove the given file.

task "unlink", "server01", sub {
   unlink("/tmp/testfile");
};
rmdir($dir)

This function will remove the given directory.

task "rmdir", "server01", sub {
   rmdir("/tmp");
};
mkdir($newdir)

This function will create a new directory.

task "mkdir", "server01", sub {
   mkdir("/tmp");
};
stat($file)

This function will return a hash with the following information about a file or directory.

mode
size
uid
gid
atime
mtime
task "stat", "server01", sub {
   my %file_stat = stat("/etc/passwd");
};
is_file($file)

This function tests if $file is a file. Returns 1 if true. 0 if false.

task "isfile", "server01", sub {
   if( is_file("/etc/passwd") ) {
      say "it is a file.";
   }
   else {
      say "hm, this is not a file.";
   }
};
is_dir($dir)

This function tests if $dir is a directory. Returns 1 if true. 0 if false.

task "isdir", "server01", sub {
   if( is_dir("/etc") ) {
      say "it is a directory.";
   }
   else {
      say "hm, this is not a directory.";
   }
};
is_readable($file)

This function tests if $file is readable. It returns 1 if true. 0 if false.

task "readable", "server01", sub {
   if( is_readable("/etc/passwd") ) {
      say "passwd is readable";
   }
   else {
      say "not readable.";
   }
};
is_writable($file)

This function tests if $file is writable. It returns 1 if true. 0 if false.

task "writable", "server01", sub {
   if( is_writable("/etc/passwd") ) {
      say "passwd is writable";
   }
   else {
      say "not writable.";
   }
};
is_writeable($file)

This is only an alias for is_writable.

readlink($link)

This function returns the link endpoint if $link is a symlink. If $link is not a symlink it will die.

task "islink", "server01", sub {
   my $link;
   eval {
      $link = readlink("/tmp/testlink");
   };
   
   say "this is a link" if($link);
};
rename($old, $new)

This function will rename $old to $new. Will return 1 on success and 0 on failure.

task "rename", "server01", sub {
   rename("/tmp/old", "/tmp/new");
}; 
chdir($newdir)

This function will change the current workdirectory to $newdir. This function currently only works local.

task "chdir", "server01", sub {
   chdir("/tmp");
};

1 POD Error

The following errors were encountered while parsing the POD:

Around line 72:

Non-ASCII character seen before =encoding in '} list_files("/etc");'. Assuming UTF-8