martes, julio 05, 2011

cd suffle

Hoy me hicieron el día: tenía tiempo que no encontraba una opción tan oscura y a la vez tan útil de un comando que uso diario, a todas horas y del cual pensaba ya no sacar más provecho, el hecho en cuestion es cd shuffle...

Cabe aclarar que sólo funciona con ksh, si estas con bash no funcionará... Pasemos al pedazo del man ksh que nos interesa:

cd [ -LP ] [ arg ]
cd [ -LP ] old new
..explicaciones mas, explicaciones menos...
The second form of cd substitutes the string new for the string old in the current directory name, PWD, and tries to change to this new directory.
..explicaciones mas, explicaciones menos...


Y a la demostracion:

[root@macuile .gnome2]# ksh
# echo $SHELL

/bin/bash
#Nota: no tengo idea de donde guarda ksh el shell utilizado actualmente
# como podrán darse cuenta no se borró el SHELL anterior
# echo $$
12330
# ps -ef | grep $$
root 12330 12277 0 22:53 pts/0 00:00:00 ksh
root 12339 12330 0 22:53 pts/0 00:00:00 ps -ef
root 12340 12330 0 22:53 pts/0 00:00:00 grep 12330
#Nota: con esto nos aseguramos de que sea ksh
# cd /home/db2inst1/.gnome2
# cd db2inst1 miguel

/home/miguel/.gnome2
# pwd
/home/miguel/.gnome2
#Nota: magia, nos cambiamos de directorio
[root@macuile .gnome2]# echo $SHELL
/bin/bash
[root@macuile .gnome2]# pwd
/home/db2inst1/.gnome2
[root@macuile .gnome2]# cd db2inst1 miguel
-bash: cd: db2inst1: No such file or directory
[root@macuile .gnome2]# mkdir db2inst1 miguel
[root@macuile .gnome2]# cd db2inst1 miguel
#Nota: A mi parecer este comportamiento es peor que no hacer nada y fallar
[root@macuile db2inst1]# pwd
/home/db2inst1/.gnome2/db2inst1
[root@macuile db2inst1]# mkdir miguel
[root@macuile db2inst1]# cd ..
[root@macuile .gnome2]# cd db2inst1 miguel
#Nota: sería interesante que hubiera entrado hasta miguel, no hubo suerte
[root@macuile db2inst1]# pwd
/home/db2inst1/.gnome2/db2inst1
[root@macuile db2inst1]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Jul 5 23:20 miguel


No hay comentarios.: