Tips & Tricks

Completamento automatico dei comandi

 

Se utilizzate più o meno regolarmente la linea di comando (in ambiente Linux ma non solo) avrete sperimentato la comodità del completamento automatico dei comandi (e dei percorsi nel filesystem) :è sufficiente inserire i primi caratteri del comando e premere il tasto TAB perché venga completato automaticamente il nome del comando (qualora i caratteri inseriti lo identifichino univocamente) o venga proposta la lista completa dei comandi che iniziano con tale sequenza di caratteri; tale funzionalità ha la duplice utilità di farci risparmiare tempo e di assisterci se non ricordiamo esattamente il nome di un comando, ma solo l’inizio. Nella maggior parte delle distribuzioni (Ubuntu in prima fila) questa comoda funzionalità è disponibile sin dal primo avvio, ma in certi frangenti può essere necessario effettuare alcune operazioni per attivarla: vediamo insieme quali. Il completamento si ottiene modificando il file .bashrc presente nella cartella home del vostro profilo (per visualizzarlo può essere necessario mostrare i file nascosti premendo in Nautilus la combinazione di tasti Ctrl+H); una volta aperto il file è necessario individuare le seguenti righe, collocate verso la fine:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi


Se non sono presenti, aggiungetele a mano e quindi rimuovete il simbolo di cancelletto ‘#’ davanti alle ultime tre righe, ottenendo il seguente risultato:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi


A questo punto potete chiudere il file e aprire un terminale per vedere il risultato (le modifiche non saranno visibili su eventuali terminali già aperti). La procedura appena illustrata abilita l’autocompletamento per il solo utente corrente: è possibile estendere la configurazione a tutti gli utenti del sistema modificando una volta per tutte il file /etc/bash.bashrc, ma l’operazione richiede privilegi di amministratore; la procedura da seguire è identica a quella riportata, a cambiare è solamente il file da modificare. Se si sceglie questa strada, non occorre ovviamente modificare il file .bashrc nella cartella home del proprio profilo poichè tutti gli utenti “ereditano” la configurazione contenuta nel file /etc/bash.bashrc.

Configurazione della rete

Cambiare hostname


On any Linux system you can see hostname with the command ‘hostname‘.

#hostname

without any parameter it will output the current hostname of the system.

#hostname --fqd

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh

#cat /etc/hostname

So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run /etc/init.d/hostname.sh start to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh). If you want more details check hostname man page

Use sysctl to change the variable kernel.hostname:

#sysctl kernel.hostname

to read the current hostname, and

#sysctl kernel.hostname=NEW_HOSTNAME

to change it.

If you want more details check sysctl man page. You can use the same process for all debian based distributions and other linux machines also.