Use el operador unlink para suprimir ficheros:
unlink "one", "two", "three", glob "*.o";Devuelve el número de ficheros suprimidos.
La función symlink crea un link simbólico:
cat ln.pl #!/usr/bin/perl -w symlink "/home/pl/public_html/regexpr/perl/doc", "doc" or warn "No se pudo construir enlace simbólico: $!";
Para crear un directorio use mkdir:
mkdir "tmp", 0755 or warn"No se pudo crear directorio: $!";
El módulo File::Path provee un medio conveniente para la creación y destrucción recursiva de directorios. El siguiente ejemplo usa la versión 2.04 del módulo:
pp2@nereida:~/src/perl/testing$ perl -MFile::Path -wde 0
Loading DB routines from perl5db.pl version 1.28
main::(-e:1): 0
DB<1> mkpath( '/tmp/chum/cham/', '/tmp/chum/chim', {verbose => 1} )
mkdir /tmp/chum
mkdir /tmp/chum/cham/
mkdir /tmp/chum/chim
DB<2> !! ls -ld /tmp/chum /tmp/chum/cham/ /tmp/chum/chim
drwxr-xr-x 4 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum
drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum/cham/
drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum/chim
DB<3> rmtree('/tmp/chum/cham/', '/tmp/chum/chim', { verbose => 1, error => \$err_list })
rmdir /tmp/chum/cham
rmdir /tmp/chum/chim
DB<4> x $err_list
0 ARRAY(0x84b6178)
empty array
DB<5> !! ls -ld /tmp/chum /tmp/chum/cham/ /tmp/chum/chim
ls: /tmp/chum/cham/: No existe el fichero o el directorio
ls: /tmp/chum/chim: No existe el fichero o el directorio
drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:42 /tmp/chum
(Command exited 2)
DB<6> mkpath( '/tmp/chum/cham/', '/tmp/chum/chim', {verbose => 1} )
mkdir /tmp/chum/cham/
mkdir /tmp/chum/chim
DB<7> !! touch /tmp/chum/cham/tutu.txt
DB<8> !! touch /tmp/chum/chim/titi.txt
DB<9> x rmtree('/tmp/chum/cham/', '/tmp/chum/chim', { verbose => 1, error => \$err_list })
unlink /tmp/chum/cham/tutu.txt
rmdir /tmp/chum/cham
unlink /tmp/chum/chim/titi.txt
rmdir /tmp/chum/chim
0 4
La función rename nos permite cambiar el nombre de un fichero o moverlo de ubicación:
rename "viejo", "nuevo"; rename "/home/casiano/m.txt /tmp/m.txt";La función
rename tiene un efecto similar al comando mv de Unix.
Utilice la función rmdir para suprimir directorios:
rmdir "tutu/";
Utilice la función chmod para cambiar los permisos de un fichero o directorio:
chmod 0755, "one", "two";
my ($user, $group) = (1004, 100); chown $user, $group, glob "/tmp/*.c";
Utilice la función getpwnam para traducir de nombre a número
y la función getgrnam para traducir de un nombre de grupo
a su número:
lhp@nereida:/tmp$ perl -wde 0
DB<1> @a = getpwnam('elvira')
DB<2> x @a
0 'elvira'
1 'x'
2 1033
3 1033
4 ''
5 ''
6 'Elvira,,,'
7 '/home/elvira'
8 '/bin/bash'
DB<3> $a = getpwnam('elvira')
DB<4> x $a
0 1033
DB<5> x getgrnam "users"
0 'users'
1 'x'
2 100
3 ''
DB<6> x scalar(getgrnam "users")
0 100