34

Is there a drush command to show existing aliases? Some Googling didn't turn up anything.

  • $ drush site-alias @self – monymirza Nov 15 '12 at 15:16
  • 'drush sa @self --full --with-db --with-optional' will generate a template that you can append to ~/.drush/aliases.drushrc.php for further use. Do not forget to change the key 'self' in the table by an unique alias name for your site. – Interdruper Aug 30 '16 at 16:28
45

You can use this in the terminal

drush sa

For example on my dev server:

- drush sa
@8080
@commons_3_dev
@none
@w2

The aliases are set in file called aliases.drushrc.php. For me this is located in /usr/local/share/drush/. Depending on how you installed Drush and on which distro you're on this may differ.

You can set up aliases in this fashion inside that file

$aliases['8080'] = array(
'uri'=>'server.com:8080',
'root'=>'/var/www/html_webtest2',
);

$aliases['w2'] = array(
'uri'=>'webtest2.server.com.edu',
'root'=>'/var/www/html_webtest2',
);

$aliases['commons_3_dev'] = array(
'uri'=>'yourserver.com/c3d7/',
'root'=>'/var/www/html_commons_3_dev',
);

For more fun, you can chain these together for server wide backups. For example, I do a big back up to all aliased sites like this

 drush sa | egrep "(@|default)" | egrep -v "(@none|@self) | xargs -L1 drush arb

Taken individually

 drush sa  # list site aliases
 | egrep "(@|default)"  # include default and any line containing a @ mark
 | egrep -v "(@none|@self)" # remove any lines with @none or @self 
 | xargs -L1 drush arb # with each line run drush archive-backup

To find path and other info, use a bit o' pipping:

drush sa | xargs -I {}  sh -c "echo {}; drush {} st"

To narrow it down to finding paths:

    drush sa | xargs -I {}  sh -c "echo {}; drush {} st" | egrep "(@|path)"
@8080
 Site path                     :  sites/8080.webtest2               
 File directory path           :  sites/8080.webtest2/files         
 Private file directory path   :  /var/www/drupal_private_files                   
@commons_3_dev
 Site path              :  sites/default                                          
 File directory path    :  sites/default/files                                    
@none
@w2
 Site path              :  sites/default                                          
 File directory path    :  sites/default/files 

update

A bit late but I wanted to say don't forget about drush @sites st. I believe the @sites parameter will act on everything found under the sites folder. Think

drush @sites cron -y # runs cron on each root/sites/site
drush @sites rf 
  • It would be handy also to know what filesystem path these sites map to from the sa command :) – user1359 Nov 15 '12 at 15:55
  • 1
    Try drush @alias st (for status) – Rick Nov 15 '12 at 16:01
  • yeah, but I don't want to have to check each alias individually to see if it's the one I'm looking for. I'm dealing with a lot of aliases in a multi-site, multi-user environment. The one I want may not even exist! – user1359 Nov 15 '12 at 16:05
  • 4
    Try this: drush sa | xargs -I {} sh -c "drush {} st" – Rick Nov 15 '12 at 16:10
  • 1
    Get creative with pipes and grep. Sometimes the simplest bash commands strung together will give you some wonderful information. – Rick Nov 15 '12 at 19:30
2

If you're like me you want all the details too…

Try drush site-alias --table or the shortcut drush sa --table.

Check GitHub or drush topic aliases for further info.

  • I know this is an ancient thread but if anyone lands here via google - the parameter is not --table but drush sa --format=table. And to save you some awk weight lifting you can use the --fields and --field-labels=0 options to keep things concise. – Dan Shumaker Apr 26 '18 at 14:39
  • @DanShumaker I haven't worked in on Drupal in a few years now. Feel free to give a new answer, and I'll upvote yours. – Rob Colburn Sep 4 '18 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.