http://www.perlmonks.org?node_id=627015

In response to blazar's suggestion in 626986:
This is a rough conversion table from UNIX commands to Perl.
Please note that there are not always direct single equivalents.

Please feel free to add more, there must be lots.
UNIXPerlOrigin
. do built-in
awk perl ;-) (often 'split') built-in
See also a2pBase program
basename File::Basename::basename Base module
cat while(<>){print} built-in
ExtUtils::Command::cat Base module
cd chdir built-in
chmod chmod built-in
chown chown built-in
cp File::Copy Base module
ExtUtils::Command::cp Base module
cut split built-in
date localtime built-in
POSIX::strftime Base module
declare see typedef
df Filesys::Df CPAN
diff File::Compare Base module
dirname File::Basename::dirname Base modules
echo print built-in
egrep while(<>){print if /re/} built-in
eval eval built-in
exec exec built-in
pipe (co-processes) built-in
open (file descriptors) built-in
export Assign to %ENV Hash variable
Env::C CPAN
find File::Find::find Base module
ftp Net::Ftp Base module
function sub built-in
grep see egrep
hostname Sys::Hostname::hostnameBase module
integer int built-in
kill kill built-in
ln link built-in
ln -s symlink built-in
ls glob built-in
opendir/readdir/closedir built-in
stat/lstat built-in
mkdir mkdir built-in
mkpath ExtUtils::Command::mkpath Base module
mv rename built-in
ExtUtils::Command::mv Base module
od ord built-in
printf built-in
print print built-in
printf printf built-in
ps Proc::ProcessTable CPAN
pwd Cwd::getcwd Base module
rand rand built-in
read See I/O Operators built-in
rm unlink built-in
ExtUtils::Command::rm Base module
rm -f ExtUtils::Command::rm_rf Base module
sed s/// (usually) built-in
See also s2pBase program
select Shell::POSIX::select CPAN
sleep sleep built-in
alarm built-in
sort sort built-in
source do built-in
tail File::Tail CPAN
telnet Net::Telnet CPAN>
times times built-in
touch open/close built-in
ExtUtils::Command::touch Base module
trap %SIG Hash
sigtrap pragma
typeset my built-in
typeset -i int built-in
typeset -l lc built-in
typeset -u uc built-in
typeset -Z sprintf built-in

updates: link/symlink, thanks to Crackers2
Net::Telnet added with thanks to regexes
a2p and s2p, thanks to Trizor
cut, thanks to RMGir
ps, thanks to Nasrudin

Replies are listed 'Best First'.
Re: UNIX 'command' equivalents in Perl
by TStanley (Canon) on Jul 17, 2007 at 17:19 UTC
    There is also a book called Minimal Perl, that does an excellent job of comparing shell and Perl.

    TStanley
    --------
    People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell
Re: UNIX 'command' equivalents in Perl
by derby (Abbot) on Jul 17, 2007 at 13:40 UTC

      You could go even further and take a look at Perl Power Tools.

      Well, ppt used to be cool, but the project seems to be sleeping now... and anyway the purpose here is not to show how to reimplement possibly complex *NIX commands in Perl, but just the reverse: to show how things a newbie may want to system (or similar) out to an external program to do can be handled just fine with basic perl construct or judicious use of a core or CPAN module.

Re: UNIX 'command' equivalents in Perl
by RMGir (Prior) on Jul 18, 2007 at 09:58 UTC
    UNIXPerlOrigin
    cutsplitbuilt-in
    ifif, unlessbuilt-in
    whilewhile, for, foreachbuilt-in

    Of course, cut usually winds up being in a complex pipe with sed, sort, and join, so if you see cut in a pipe sequence, odds are you've found a perfect piece of shell script to convert to perl...

    And complex conditional or looping structures are much easier in perl than shell (at least to me...)


    Mike
Re: UNIX 'command' equivalents in Perl
by quester (Vicar) on Jul 18, 2007 at 07:09 UTC
    You might also toss in:

    expect Expect

    and just possibly ssh...

    ssh Net::SSH::Perl

    if you think the target audience for this document won't be utterly terrorized by the Net::SSH::Perl installation.

Re: UNIX 'command' equivalents in Perl
by Trizor (Pilgrim) on Jul 18, 2007 at 04:29 UTC
    You might also want to mention a2p and s2p for sed and awk replacements...
Re: UNIX 'command' equivalents in Perl
by jplindstrom (Monsignor) on Jul 18, 2007 at 15:03 UTC
    mkdir -p and mkpath -- File::Path::mkpath()

    rm -r -- File::Path::rmtree()

    /J

Re: UNIX 'command' equivalents in Perl
by eyepopslikeamosquito (Archbishop) on Jul 20, 2007 at 22:56 UTC

    For the touch command, suggest you add utime in addition to open/close, since if the file already exists you don't need to open and close it, you can simply call the utime built-in function to change its access and modification times.

Re: UNIX 'command' equivalents in Perl
by Nasrudin (Acolyte) on Nov 14, 2007 at 23:37 UTC
    I notice "ps" is missing...any suggestions? Proc::ProcessTable was the best I was able to find in an admittedly short search effort.
Re: UNIX 'command' equivalents in Perl
by paulchernoch (Acolyte) on Aug 05, 2009 at 13:29 UTC
    The 'which' command is simulated by using the function "which" in the module File::Which.