`
xfxlch
  • 浏览: 167480 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Hack 3. Perform mkdir and cd Using a Single Command

阅读更多
在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--




分享到:
评论

相关推荐

    Linux-101-Hacks

    Perform mkdir and cd Using a Single Command 使用`mkdir -p`结合管道符号`|`实现创建并进入目录的操作。 ```bash mkdir -p /path/to/newdir | cd - ``` #### Hack 4. Toggle Between Directories 使用`pushd`和`...

    Linux101 Hacks 2rd

    Perform mkdir and cd Using a Single Command** 在某些情况下,我们需要创建一个新目录并立即进入该目录。可以使用以下命令一次性完成这两个操作: ```bash mkdir -p path/to/directory && cd path/to/directory ...

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    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 ...

    .net中进度条示例演示,ProgressBar1.PerformStep(),VB.net源代码程序

    3. **触发事件**:为了启动这个任务,你可能需要绑定一个按钮的Click事件或其他触发事件,如文件加载完成或网络请求结束。在事件处理程序中调用`ExecuteTask()`。 ```vb.net Private Sub btnStart_Click(sender As ...

    Continuous.Integration.Delivery.and.Deployment.epub

    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...

    Programming Excel With Vba And .net.chm

    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...

    .A.Comprehensive.Guide.to.Digital.Electronics.and.Computer.System.Architecture.p

    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- ...

    Swift.Data.Structure.and.Algorithms

    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.Cplusplus.MFC.and.STL

    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 ...

    BSD Hacks.pdf

    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 ...

    Developing Applications for IBM MQ V9.pdf 官方文档英文版

    Actions that your applications can perform...........................................................................................7 Application programs using the MQI..................................

    Data Analysis Using SQL and Excel(Wiley,2ed,2015)

    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, 2016]

    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 ...

    Unix shell programming in 24 hours.pdf

    - **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 ...

    html5_css3.pdf

    ■■ 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. ■■ ...

    Ubuntu.15.04.Server.with.systemd.Administration.and.Reference.epub

    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 ...

Global site tag (gtag.js) - Google Analytics