« Articoli sotto Linux

Hot Keys in riga di comando

Hot Keys

Alcune combinazioni di tasti possono essere molto utili in Linux, eccone alcune:

* History – con l’uso delle frecce [SU] e [GIU] e possibile ottenere la lista di tutti i comandi precedentemente digidati.
* Backscrolling – lo scrolling dello schermo indietro o in avanti si ottiene premendo [SHIFT] + [PAGINA SU] o [PAGINA GIU]. Questo permette di vedere testo che precedentemente era sullo schermo.

Ecco altri hot keys:

* [CTRL]+[c] – interrompre il programma in esecuzione
* [CTRL]+[d] – segnala la fine dell’operazione di input
* [CTRL]+[u] oppure [CTRL]+[x] – cancella la linea attuale
* [CTRL]+[z] – mette il programma in pausa
* [TAB] – QUESTO E’ IL TASTO PIU’ USATO. Completa automaticamente il percorso o il nome del file digidato da tastiera.
* [CTRL]+[t] – Inverte le due lettere dove si trova il cursore, utilissimo se quando si sbaglia per la troppa fretta. Esempio: ‘dorò diventa ‘door’
* [Shift]+[Scrollock] – visualizza informazioni sulla memoria
* [AltGr]+[ScrollLock] – visualizza lo stato dei registri
* [Ctrl]+[ScrollLock] – visualizza lo stato del sistema
* [AltGr]+[Fn] – Passa alla console virtualw “n”+12
* [Alt]+[RightArrow] – Passa alla console virtuale successiva
* [Alt]+[LeftArrow] – Passa alla console virtuale precedente
* [AltGr]+[PrintScreen] – Passa all’ultima console virtuale

Credit TO http://ubuntufacile.org/comandi-terminale/

Installare PHP 5.2.10 su Ubuntu 10.10 (downgrade)

Su Ubuntu 10.4 e 10.10 il PHP che si installa di default è il 5.3.
Purtroppo ancora tanti cms non supportano il php 5.3, per installare PHP 5.2.10 ho seguito questo tutorial:
http://harx.nl/component/content/article/2-linux/22-installingphp52onubuntu1010

Che per backup copio qui:
#!/bin/bash
# by Ruben Barkow (rubo77) http://www.entikey.z11.de/
# adapted by Roel Veldhuizen http://harx.nl for Ubuntu 10.10
# Originally Posted by Bachstelze http://ubuntuforums.org/showthread.php?p=9080474#post9080474
# OK, here's how to do the Apt magic to get PHP packages from the karmic repositories:

echo "Am I root? "
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then
echo " NO!
Error: You must be root to run this script.
Enter
sudo su
"

exit 1
fi
echo " OK";

# finish all apt-problems:
apt-get -f install

# remove all your existing PHP packages. You can list them with dpkg -l| grep php

PHPLIST=$(for i in $(dpkg -l | grep php|awk '{ print $2 }' ); do echo $i; done)

echo these pachets will be removed: $PHPLIST

# you need not to purge, if you have upgraded from karmic:
apt-get remove $PHPLIST

# on a fresh install, you need purge:
# aptitude remove --purge $PHPLIST

#Create a file each in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php5.2);
#
#Package: php5
#Pin: release a=karmic
#Pin-Priority: 991
#
#The big problem is that wildcards don't work, so you will need one such stanza for each PHP package you want to pull from karmic:

echo ''>/etc/apt/preferences.d/php5.2
for i in $PHPLIST ; do echo "Package: $i
Pin: release a=karmic
Pin-Priority: 991
">>/etc/apt/preferences.d/php5.2; done

# duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d:
#sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
# better exactly only the needed sources, cause otherwise you can get a cachsize problem:

echo "# needed sources vor php5.2:
deb http://de.archive.ubuntu.com/ubuntu/ karmic main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic main restricted
deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates main restricted
deb http://de.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic universe
deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb http://de.archive.ubuntu.com/ubuntu/ karmic multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic multiverse
deb http://de.archive.ubuntu.com/ubuntu/ karmic-updates multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ karmic-updates multiverse
deb http://security.ubuntu.com/ubuntu karmic-security main restricted
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted
deb http://security.ubuntu.com/ubuntu karmic-security universe
deb-src http://security.ubuntu.com/ubuntu karmic-security universe
deb http://security.ubuntu.com/ubuntu karmic-security multiverse
deb-src http://security.ubuntu.com/ubuntu karmic-security multiverse
" >> /etc/apt/sources.list.d/karmic.list

apt-get update

apache2ctl restart

echo install new from karmic:
apt-get -t karmic install $PHPLIST

# at the end retry the modul libapache2-mod-php5 in case it didn't work the first time:

apt-get -t karmic install libapache2-mod-php5

echo $PHPLIST

apache2ctl restart

ho dovuto anche seguire il consiglio di installare:

sudo apt-get install dos2unix

sudo sh dos2unix php5_2ubuntu_10_10.sh

e poi:
/etc/apt/preferences.d/php5.2 rinominato in /etc/apt/preferences.d/php52

quindi mi ritrovo con il php 5.2.10 nn so se si può aggiornare alla 5.2.14 … okkio cmq che al prox apt-get upgrade sovrascrive il 5.3 di nuovo

Reset della password del DB MySql

Credi to http://en.kioskea.net/faq/630-reinitializing-the-root-password-of-mysql

The root password is lost!

To be able to modify the existing root password, you must firstly be connected to it. If you know the root password and just want to reinitialize it, you can skip this part. In the case that you donâ€(TM)t have the root password then follow the steps below.
It s is possible to bypass the authentication process and to access MySQL:

* Stop the MySQL server.
o

#/etc/init.d/mysql stop

* Restart MySQL, disabling network communication and skipping the authentication procedure.
o

#mysqld –skip-grant-tables –skip-networking &

Reinitializing the password:

* Get connected to the system database (mysql) of MySQL:
o

# mysql mysql -u root

* Type in the following command and reset your password
o

UPDATE user SET password=PASSWORD(‘newpassword’) WHERE user=”root”;

* If you didn’t go through the first step, to validate the changes simply type:
o

FLUSH PRIVILEGES;

* If you started MySQL manually(bypassing the authentication process), the server must be restarted:
o

#/etc/init.d/mysql restart

Function split() is deprecated

ERRORE:

Unknown error (8192): Function split() is deprecated in /var/www/magento/app/code/core/Mage/Admin/Model/User.php on line 374

in
/app/code/core/Mage/Admin/Model/User.php o

alla riga 374

sostituire questa
$nodePath = ‘adminhtml/menu/’ . join(‘/children/’, split(‘/’, $startupPage)) . ‘/action’;

con questa
$nodePath = ‘adminhtml/menu/’ . join(‘/children/’, explode(‘/’, $startupPage)) . ‘/action’;

Importare un database da riga di comando (mySql)

Comando

mysql < nome_file.sql db_name -u root -p

se il database è compresso scompattarlo, l’estensione deve essere .sql

Comprimere/decomprimere tarball gz

Il comando zip permette di creare archivi zip dei nostri file personali, per comprimere una cartella di nome archivio con compressione zip scriveremo:

zip -r archivio.zip archivio

arcchivio.zip rappresenta il nome che diamo al nuovo archivo compresso, -r indica al comando di comprimere in modo ricorsivo, archivio rappresenta la cartella da comprimere.

per decomprimere il nostro archivio.zip basterà scrivere da terminale:

unzip archivio.zip

I più importanti archivi con cui ci troveremo ad operara con linux sono gli archivi tar.gz e tar.bz2.
per comprimere una cartella di nome prova con al suo interno dei file in un archivio tar.gz ci basterà scrivere da terminale:

tar czvf prova.tar.gz prova

analizziamo quello che abbiamo scritto “c” indica al comando tar di comprimere, “z” di comprimere nel formato zip, “v” rappresenta il verbose mode, “f” indica di procedere in modo ricorsivo, archivio.tar.gz, rappresenta il nome che diamo al nuovo archivio, prova rappresenta la cartella da comprimere.

per decomprimere il nostro archivio di nome prova.tar.gz ci basterà, digitare da terminale.

tar zxvf prova.tar.gz

analizziamo la sintassi “z” indica che ci troviamo di fronte ad un archivio zip, “x” indica al comando tar di estrarre, “v” indica il verbose mode, “f” indica al comando di lavorare in modo ricorsivo.

Per comprimere i nostri dati in tar.bz2 si utilizzerà il comando tar con la seguente sintassi:
tar cjvf archivio.tar.bz2 archivio

analizziamo anche in questo caso quello che abbiamo scritto, “c” indica al comando tar di comprimere, “j” indica di comprimere nel formato bzip2, “v” verbose mode, “f” rappresenta il modo ricorsivo.

Per decomprimere si utilizzerà la seguente sintassi:

tar jxvf archivio.tar.bz2

analizziamo le varie opzioni date, “j” indica un archivio bzip2, “x” indica al comando di estrarre, “v” rappresenta il verbose mode, “f” rappresenta un azione ricorsiva di estrazione.

Per comprimere una cartella di nome prova , servendoci della compressione rar, scriveremo da terminale:

rar a prova.rar prova

analizziamo la sintassi “a” rappresenta di comprimere tutti i file, prova.rar indica il nome dato al nostro archivio, prova rappresenta la cartella da comprimere.

per decomprimere il nostro archivo prova.rar, basterà digitare da terminale:

unrar e archivio.rar

l’opzione “e” indica di estrarre nella stessa cartella dove digitiamo il comando.

per visualizzare i manuali dei comandi qui usati basterà dare prima del comando man.

es. man rar; man tar; man zip.

I comandi rar ed unrar molto probabilmente non sono installati di default nella vostra distribuzione, per installarli scrivete da terminale:

sudo apt-get install rar unrar

Credit to: http://ubuntufacile.blogspot.com/2007/10/gestione-archivi-zip-rar-tar-da-schell.html

tar.bz2 per comprimere una cartella

tar -cjf backup.tar.bz2 directory

…which creates a bzip2 file (smaller than tarball) which can be decompressed using…

tar -xjf backup.tar.bz2

*************

tar -cvzf backup.tgz directory

c = create, v = verbose, z = compress with GZIP, f = archive name

This creates a “tarball” of the directory which can be extracted by replacing the “c” in the above command with “x” (for extract) and leaving off the directory name.

Cron Job

Run an php file with cron job on plesk

/usr/bin/php -f /var/www/vhosts/NOME-DOMINIO/httpdocs/PATH/FILE.php

RM directory

rm [-f] [-i] [-R] [-r] [filenames | directory]

-f Remove all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option will not suppress an error message.
-i Interactive. With this option, rm prompts for confirmation before removing any files. It over- rides the -f option and remains in effect even if the standard input is not a terminal.
-R Same as -r option.
-r Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used.  Symbolic links that are encountered with this option will not be traversed.  If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message.
filenames A path of a filename to be removed.