在linux系统中,我们经常会利用mkdir命令创建目录,并且cd到该目录下做一些必要的工作。
例如:
[clu@portal.ny1 ~]$ mkdir -p /tmp/subdir1/subdir2/subdir3
[clu@portal.ny1 ~]$ cd /tmp/subdir1/subdir2/subdir3
[clu@portal.ny1 subdir3]$ pwd
/tmp/subdir1/subdir2/subdir3
[clu@portal.ny1 subdir3]$
那么有没有更快的方法将两条命令结合起来操作,使得我们只要执行一条命令就可以既创建了目录,也cd到该目录了尼。有的,方法如下:
在
当前用户的home目录下,
[clu@portal.ny1 ~]$ pwd
/home/staff/clu
[clu@portal.ny1 ~]$ vi .bash_profile
新增一个方法:
function mkdircd(){
mkdir -p "$@" && eval cd "\"\$$#\"";
}
然后退出,重新登陆linux。
这样直接执行:
[clu@portal.ny1 ~]$ mkdircd /tmp/subdir1/subdir2/subdir3
[clu@portal.ny1 subdir3]$ pwd
/tmp/subdir1/subdir2/subdir3
这样就快多了
--EOF--
分享到:
相关推荐
Perform mkdir and cd Using a Single Command 使用`mkdir -p`结合管道符号`|`实现创建并进入目录的操作。 ```bash mkdir -p /path/to/newdir | cd - ``` #### Hack 4. Toggle Between Directories 使用`pushd`和`...
Perform mkdir and cd Using a Single Command** 在某些情况下,我们需要创建一个新目录并立即进入该目录。可以使用以下命令一次性完成这两个操作: ```bash mkdir -p path/to/directory && cd path/to/directory ...
Create a Single-Page App Using Angular's Router Chapter 9. Design Great UIs with Bootstrap's Grid and Components Chapter 10. Cache Complex Queries Using Materialized Views Chapter 11. Asynchronously ...
3. **触发事件**:为了启动这个任务,你可能需要绑定一个按钮的Click事件或其他触发事件,如文件加载完成或网络请求结束。在事件处理程序中调用`ExecuteTask()`。 ```vb.net Private Sub btnStart_Click(sender As ...
Perform Continuous Delivery and Deployment using Jenkins Test and deliver a web API Table of Contents Chapter 1. Continuous Integration, Delivery, And Deployment Foundations Chapter 2. Setting Up A Ci...
Chapter 3. Tasks in Visual Basic Section 3.1. Types of Tasks Section 3.2. Interact with Users Section 3.3. Do Math Section 3.4. Work with Text Section 3.5. Get Dates and Times Section 3.6...
Digital systems are created to perform data processing and control tasks. What distinguishes one system from another is an architecture tailored to efficiently execute the tasks for which it was de- ...
Master the most common algorithms and data structures, and learn how to implement them efficiently using the most up-to-date features of Swift 3 About This Book Develop a deep understanding of the ...
Software Application Development: A Visual C++, MFC, and STL Tutorial provides a detailed account of the software development process using Visual C++, MFC, and STL. It covers everything from the ...
5. **Delimiter Dilemma (HACK 17):** A discussion on handling delimited data in files, including techniques for parsing CSV and other structured data formats using command-line utilities. 6. **DOS ...
Actions that your applications can perform...........................................................................................7 Application programs using the MQI..................................
Data Analysis Using SQL and Excel, 2nd Edition shows you how to perform a wide range of sophisticated analyses using these simple tools, sparing you the significant expense of proprietary data mining ...
Data Analysis Using SQL and Excel, 2nd Edition shows you how to perform a wide range of sophisticated analyses using these simple tools, sparing you the significant expense of proprietary data mining ...
- **Command and Arithmetic Substitution** Command substitution allows the output of a command to be used within another command. It is denoted by `$()` or backticks ````. Arithmetic substitution is ...
■■ Create a project using Visual Studio Express 2012 for Web. ■■ Create a project using Blend for Visual Studio 2012. ■■ Create a project using Visual Studio Express 2012 for Windows 8. ■■ ...
The emphasis is on what administrators will need to know to perform key server support and management tasks. Coverage of the systemd service management system is integrated into the book, replacing ...