Is there a drush
command to show existing aliases? Some Googling didn't turn up anything.
2 Answers
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 :)– user1359Commented Nov 15, 2012 at 15:55 -
1
-
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!– user1359Commented Nov 15, 2012 at 16:05
-
4
-
1Get creative with pipes and grep. Sometimes the simplest bash commands strung together will give you some wonderful information.– RickCommented Nov 15, 2012 at 19:30
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.
-
2I 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. Commented Apr 26, 2018 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. Commented Sep 4, 2018 at 13:44
$ drush site-alias @self