Messing with other people’s files

There is this girl in the office that claims to be an expert in Linux. The truth is that she barely knows how to operate a computer. I don’t like her, or her attitude, so I made this script.


cd $1

#We create the list of files
ls -1 > ../list1
mv ../list1 .
cp list1 original

#Get the total number of files
number=`wc -l list1 | awk '{print $1}'`

#Do the changes, as random as is could manage to...
for i in `seq 1 $number`
    #Invert the list
    tac list1 > list2
    #Get a random number for desition
    ran=$(( $RANDOM % 10 ))
    if  [ $ran -lt 5 ]
        #Get a random number for desition
        ran2=$(( $RANDOM % 10 ))
        if  [ $ran2 -gt 5 ]
            let cola=$number-$i
            #Put the last line as the first one
            tail -$i      list2 >  list1
            head -n $cola list2 >> list1
            #Swap lines
            awk 'NR%2{x=$0;next}{print $0"\n"x;}END{if(NR%2)print;}' list2 > list1
        let cola=$number-$i
        #Put the first line at the end
        tail -n $cola  list2 >  list1
        head -$i       list2 >> list1

#Changes the files list to temporary
while read line
    echo $line-tmp >> list3
done < list1 #Merge the original and tmp lists paste original list3 > list4

#Get the new names to the files
while read line
    mv `echo $line`
done < list4

#remove the tmp tag
for i in $(cat list3)
    raiz=`echo $i | cut -f1 -d-`
    mv $i $raiz

#Remove the rubbish
rm list1 list2 list3 list4 original
cd $actual

exit 0

Basically, what it does is to interchange the names of the files in a directory. It’s not big deal, unless you’re dealing with thousands of them and you’re a computer illiterate bitch. Anyways, it takes as first argument the name of the directory that you want to mess with.

I will have fun on Monday.


Acerca de José Manuel

I'm from Mexico and currently in a PhD program in the University of Oviedo, in Spain.
Esta entrada fue publicada en Escuela y etiquetada , , . Guarda el enlace permanente.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s