Alias disponible avec sudo

Résolu
salut a tous,
j'utilise un serveur sous debian 4.0.
dans mon compte utilisateur, j'ai configure les alias suivants dans ~/.bashrc
alias ll='ls -Al'
alias lr='ls -AlR'

j'aimerais que ces alias fonctionnent aussi avec sudo.
J'ai donc edite le fichier /root/.bashrc
pourtant, les alias ne sont pas reconnus :
$ sudo ll /home/
sudo: ll: command not found

Quelqu'un sait comment faire ?
Merci
Santiago

--

Il y a 10 types de personnes dans le monde
Ceux qui comprennent le binaire et les autres.

8 réponses

  1. Il faut ajouter un alias dans ton ~/.bashrc
    alias sudo='A='alias' sudo  '


    Je l'ai testé avec succès sur Ubuntu 10.04.1 et Debian 5.0.5, bash 3.2.39, sudo 1.6.9p17 : ça fonctionne

    Vu sur http://ubuntuforums.org/showthread.php?t=217188
    1. Ça fait un gros up de ton post mais franchement ça ma tué cette ligne... Ça marche sur Mavericks aussi (en éditant bien sur le ~/.bash_profile).
  2. Modérateur
    Je pense qu'il suffit de mettre ces alias dans /root/.bashrc

    Bonne chance
    1. Modérateur
      Hi,

      J'ai donc edite le fichier /root/.bashrc
      L'est pas bien réveillée ce matin mamiemando ? ;-))
  3. J'ai pourtant clairement ecrit en ligne 10 et 11 de mon post :

    Quote:
    > J'ai donc edite le fichier /root/.bashrc
    > pourtant, les alias ne sont pas reconnus :

    Cette technique ne marche donc pas.
    Merci quand meme de ton intervention.
    Santiago
    1. Modérateur
      Salut,

      Essaye :
      sudo -i ll /home/
      Extrait du man sudo :
      -i  The -i (simulate initial login) option runs the shell specified in
                 the passwd(5) entry of the user that the command is being run as.
                 The command name argument given to the shell begins with a - to
                 tell the shell to run as a login shell.  sudo attempts to change to
                 that user's home directory before running the shell.  It also ini-
                 tializes the environment, leaving TERM unchanged, setting HOME,
                 SHELL, USER, LOGNAME, and PATH, and unsetting all other environment
                 variables.  Note that because the shell to use is determined before
                 the sudoers file is parsed, a runas_default setting in sudoers will
                 specify the user to run the shell as but will not affect which
                 shell is actually run.
      1. $ sudo -i ll /home/
        -bash: ll: No such file or directory

        Visiblement, il n'imterprete plus ce qui suit ll -i comme une commande.
        Bizarre...
        Merci quand meme.
        1. Modérateur
          Au pire tu fais un
          sudo su -

          ou un :
          sudo -s

          Désolée pour ce matin j'étais effectivement mal réveillée ;-)

          Bonne chance
          1. ben justement c'est ce que j'ai pas envie de faire
            en l'occurence, je fais plutot :
            $ sudo ls -Al

            puisque mon alias n'est pas reconnu

            1. Modérateur
              Salut,

              Voici un exemple
              lami20j@debian-acer:~$ echo "alias sudoll='sudo ls -Al'" >>.bashrc
              lami20j@debian-acer:~$ source .bashrc
              lami20j@debian-acer:~$ alias| grep ll
              alias ll='ls -Al'
              alias sudoll='sudo ls -Al'
              lami20j@debian-acer:~$ cd boot_grub
              lami20j@debian-acer:~/boot_grub$ sudoll
              
              We trust you have received the usual lecture from the local System
              Administrator. It usually boils down to these three things:
              
                  #1) Respect the privacy of others.
                  #2) Think before you type.
                  #3) With great power comes great responsibility.
              
              [sudo] password for lami20j: 
              total 12
              -rw-rwxr--+ 1 root root 4625  6 sept.  2009 menu.lst
              lami20j@debian-acer:~/boot_grub$ ls -Al
              total 12
              -rw-rwxr--+ 1 root root 4625  6 sept.  2009 menu.lst
              lami20j@debian-acer:~/boot_grub$ ll
              total 12
              -rw-rwxr--+ 1 root root 4625  6 sept.  2009 menu.lst