---
title: "bashrc，profile等文件的执行时机"
author: "splayx"
date: "2013-07-18T00:37:05Z"
tags: []
categories: ["操作系统"]
slug: "bashrc-profile"
draft: false
lastmod: "2013-07-18T00:41:47Z"
id: 1908994
url: "https://splayx.iteye.com/blog/1908994"
---

在/etc，/home/username目录的bashrc，profile文件加上以下代码，

 

```
echo `date` >> /home/zhennn/priority                                            
echo "/home/zhennn/.bashrc" >> /home/zhennn/priority                            
echo >> /home/zhennn/priority  
```

 

观察一下它们的执行顺序。

做两个操作1）打开一个终端、2）用终端登录用户（su - zhennn)

 

```
2013年 07月 18日 星期四 00:32:56 CST                                            
/etc/bash.bashrc                                                                
                                                                                
2013年 07月 18日 星期四 00:32:56 CST                                            
/home/zhennn/.bashrc                                                            
                                                                                
2013年 07月 18日 星期四 00:33:29 CST                                            
/etc/bash.bashrc                                                                
                                                                                
2013年 07月 18日 星期四 00:33:29 CST                                            
/etc/profile                                                                    
                                                                                
2013年 07月 18日 星期四 00:33:29 CST                                            
/home/zhennn/.bashrc                                                            
                                                                                
2013年 07月 18日 星期四 00:33:29 CST                                            
/home/zhennn/.profile 
```

 

所以一个用户进入一个终端时会执行一次bashrc，而且/etc先于 /home/username的。

当用户登录时profile也会被执行，同个目录中bashrc先于profile。