mardi 13 mars 2012

Affichage du shell, historique, option du shell


Afficher les shells disponibles

[bob@centos ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh
[bob@centos ~]$
[bob@centos ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh
[bob@centos ~]$



Afficher le shell de connexion

-sh-3.2$ ps
  PID TTY          TIME CMD
 3167 pts/0    00:00:00 sh
 3189 pts/0    00:00:00 ps

Ou bien

-sh-3.2$ echo $SHELL
/bin/sh
-sh-3.2$


Changer son shell


-sh-3.2$ chsh --h
Usage: chsh [ -s shell ] [ --list-shells ] [ --help ] [ --version ]
       [ nom-usager ]
-sh-3.2$ chsh -s /bin/bash
Modification du shell pour bob.
Mot de passe :
Shell a changé.
-sh-3.2$

Il faut ensuite se reconnecter.


Connaitre le type d'une commande (interne ou externe)

[bob@centos ~]$ type echo
echo is a shell builtin
[bob@centos ~]$
[bob@centos ~]$ type grep
grep is /bin/grep


Affichage des variables du shell

[bob@centos ~]$ set
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="25" [3]="1" [4]="release" [5]="i686-redhat-linux-gnu")
BASH_VERSION='3.2.25(1)-release'
COLORS=/etc/DIR_COLORS.xterm
COLUMNS=80
DIRSTACK=()
EUID=500
GROUPS=()
G_BROKEN_FILENAMES=1
HISTFILE=/home/bob/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
...


Affichage des variables exportées du shell

[bob@centos ~]$ env
HOSTNAME=centos.domaine.fr
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_TTY=/dev/pts/0
USER=bob
...


Affichage des options du shell

[bob@centos ~]$ set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
...


Activation / désactivation d'une option

[root@centos bob]# set -o | grep emacs
emacs           on
[root@centos bob]# set +o emacs
[root@centos bob]# set -o | grep emacs
emacs           off
[root@centos bob]# set -o emacs
[root@centos bob]# set -o | grep emacs
emacs           on
[root@centos bob]#


Affichage du prompt du style -utilisateur@nom machine réperoire actuel:

[root@centos bob]# echo $PS1
[\u@\h \W]\$


Raccourci pour la commande history

Affichage puis exécution de la dernière commande

[bob@centos home]$ ls /etc | tail -2
yum.conf
yum.repos.d
[bob@centos home]$!!

ls /etc | tail -2
yum.conf
yum.repos.d


Rappel de la commande ayant le numéro 203 dans l'historique

[bob@centos home]$ history | tail -5
  206  pwd
  207  history
  208  ls /etc | tail -2
  209  ls
  210  history | tail -5
[bob@centos home]$ !208
ls /etc | tail -2
yum.conf
yum.repos.d
[bob@centos home]$


Rappel de la dernière commande en substituant des caractères

[bob@centos home]$ ls /etc | tail -2
yum.conf
yum.repos.d
[bob@centos home]$ !!:s^etc^home
ls /home | tail -2
bob
[bob@centos home]$


Affiche la commande sans l'exécuter

[bob@centos home]$ !!:p
ls /home | tail -2
[bob@centos home]$

Aucun commentaire:

Enregistrer un commentaire

Comment ajouter une route statique sur une distribution Linux Ubuntu

Pour ajouter une route statique au démarrage d'Ubuntu, voici le fichier à modifier. Dans l'exemple on ajoute une route pour joindre ...