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

Hack 2. Use CD Alias to Navigate Up the Directory

阅读更多
cd ..命令可以返回到上一层目录。
我们都知道使用cd ../是回到系统的上一层目录,但是当你进入到一个很深的目录的时候,你想回到前3层的目录,你就要用cd ../../../来达到目的,如果是目录更深,或许你需要的../就要写的更多。现在通过cd alisa命令来减轻或减少../的输入次数。
假设有如下的目录:
jack@Ubuntu: mkdir -p /tmp/very/long/directory/structure/that/is/too/deep
jack@Ubuntu:cd /tmp/very/long/directory/structure/that/is/too/deep
jack@Ubuntu:/tmp/very/long/directory/structure/that/is/too/deep$ pwd
/tmp/very/long/directory/structure/that/is/too/deep
jack@Ubuntu:/tmp/very/long/directory/structure/that/is/too/deep$ cd ../../../../
jack@Ubuntu:/tmp/very/long/directory/structure$ pwd
/tmp/very/long/directory/structure

通常的做法是我们要../四次才能回到structure目录
现在提供如下方法:
方法1:定义..n别名来指定到第几层目录。如果要永久生效要把命令写入~/.bash_profile并重启系统。
jack@Ubuntu:/tmp/very/long/directory/structure$ alias ..1="cd ../"
jack@Ubuntu:/tmp/very/long/directory/structure$ alias ..2="cd ../../"
jack@Ubuntu:/tmp/very/long/directory/structure$ alias ..3="cd ../../../"
jack@Ubuntu:/tmp/very/long/directory/structure$ alias ..4="cd ../../../../"
jack@Ubuntu:/tmp/very/long/directory/structure/that/is/too/deep$ pwd
/tmp/very/long/directory/structure/that/is/too/deep
jack@Ubuntu:/tmp/very/long/directory/structure/that/is/too/deep$ ..4
jack@Ubuntu:/tmp/very/long/directory/structure$ pwd
/tmp/very/long/directory/structure

比较方便吧。

其他方法跟方法1类似,区别就是对别名的定义如何能更好的让使用者能够快速记住,比如定义为alias cd1="cd ../"等。了解了alias 命令我们就可以自己去定义一些比较常用的命令。
例如:公司通常都不会给普通的开发在prod环境配很高的权限,所以有时候我们就需要sudo 到某个有特定权限的帐号去做一些操作。例如:sudo -u devderiv 切换到devderiv帐号,这个命令经常用,为了节约时间,可以定义alias,alias devderiv=“sudo -u devderiv” 这样就可以直接输入devderiv来切换帐号了。如果命令更长的话,定义别名会更加的方便快捷。
--EOF--

分享到:
评论

相关推荐

    Linux-101-Hacks

    Use CD Alias to Navigate Up the Directory 通过设置`cd`的别名,可以在当前目录的父目录间快速切换。 ```bash alias up='cd ..' ``` 这样,在终端中输入`up`即可进入当前目录的父目录。 #### Hack 3. Perform ...

    Linux101 Hacks 2rd

    Use CD Alias to Navigate Up the Directory** 通过定义`cd`的别名,可以轻松实现向上导航多级目录。例如,可以设置`cd ..`的别名为`cdu`,这样输入`cdu`即可返回上一级目录;设置`cd ../..`的别名为`cddu`,则...

    Springer.The.Developer’s.Guide.to.Debugging.2008.pdf

    3.6 Learn to Navigate Through the Program. . . . . . 28 3.7 Learn to Inspect Data: Variables and Expressions . . . . 29 3.8 A Debug Session on a Simple Example . . . . . . 30 4 Fixing Memory Problems...

    dod-external-integrations-template

    1. In a terminal, navigate to the directory where you want to install the app 2. $ ssh -T git@github.com 3. $ git clone git@github.com:shaunculrich77/dod-external-integrations-template 自签名本地证书 ...

    The.Agile.Consultant.Guiding.Clients.to.Enterprise.Agility.epub

    Use recognized change-management techniques to guide the enterprise to agility while minimizing disruption and resistance Navigate the many challenges that can derail the transition to agility ...

    esp-idf-v3.2.zip

    Use up & down arrow keys to navigate the menu. Use Enter key to go into a submenu, Escape key to go out or to exit. Type ? to see a help screen. Enter key exits the help screen. Use Space key, or Y ...

    pl2303hxa phased out since 2012 version 3.8.31.0

    After completing the driver download, extract the zipped file;...Navigate to the folder of the driver you downloaded and select the file "ser2pl"; Press OK and proceed to perform the installation

    Web.Client.Programming.with.Perl.Automating.Tasks.on.the.Web.pdf

    Graphical browsers require you to navigate the Web manually. In an effort to diminish the amount of tedious pointing-and-clicking you do with your browser, this book shows you how to liberate ...

    Ibx for Embarcadero RAD Studio XE4

    2. Copy the extracted folders and paste them into the main BDS directory: C:\Program Files (x86)\Embarcadero\RAD Studio\11.0 3. In the IDE, install the IBX package: A. Choose Component > Install ...

    WPF 实现导航通过Frame的Navigate函数实现导航

    本示例着重讲解如何利用`Frame`控件的`Navigate`函数来实现页面间的导航,并且通过设置`NavigationUIVisibility`属性隐藏导航UI,使得界面更加简洁,更适合初学者学习。 首先,我们需要了解`Frame`控件。`Frame`是...

    Linux.101.Hacks

    **Hack 2: Use cd Aliases to Navigate Up the Directory Effectively** 为了提高效率,可以为 `cd` 命令创建别名,使其能够更方便地向上导航。例如: ```bash alias ..='cd ..' alias ...='cd ../..' alias ....='...

    angular2中router路由跳转navigate的使用与刷新页面问题详解

    Angular2中Router路由跳转Navigate的使用与刷新页面问题详解 Angular2中Router路由跳转Navigate的使用是Angular2路由跳转的核心部分,而刷新页面问题则是开发中常见的问题。本文将详细介绍Angular2中Router路由跳转...

    otp-system-documentation

    - Use a command like `tar xzf <PREFIX>.tar.gz` to extract the files into the directory. - Replace `<PREFIX>` with the actual prefix name of the compressed tar file. **Setting Up the Environment:** ...

    微信小程序出现wx.navigateTo页面不跳转问题的解决方法

    本文实例讲述了微信小程序出现wx.navigateTo页面不跳转问题的解决方法。分享给大家供大家参考,具体如下: 今天在做微信小程序的时候,做的商品购买...https://mp.weixin.qq.com/debug/wxadoc/dev/api/ui-navigate.htm

    OPC UA 客户端 服务器 标准库源码

    2. Navigate to the project folder of the sample app, e.g. SampleApplications/Samples/NetCoreConsoleClient 3. Run the script ./createcert.sh to create the certificates for the sample applications. 4. ...

    Ajax Starter Kit

    Book Description Ajax Starter Kit – Phil Ballard. Everything you need to start learning Ajax today! Ajax Programmer’s ...2. Navigate to the CD folder and double-click on the file named start.html.

    微信小程序wx.navigateTo中events属性实现页面间通信传值,数据同步

    小程序wx.navigateTo路由方法中新增加了events属性,可以用于监听被打开页面发送到当前页面的数据。基础库 2.7.3 开始支持。 相关文档链接:...

    fonts_2.zip

    4. Navigate to the font directory # cd /usr/share/fonts/truetype 5. Create fonts.scale and fonts.dir # mkfontscale && mkfontdir # fc-cache 6. Add the new font directory to the X11 font path # ...

    微软虚拟光驱_迷你虚拟光驱

    绿色、小巧,不占用多少资源...You may now use the drive letter as if it were a local CD-ROM device. When you are finished you may unmount, stop, and remove the driver from memory using the driver control.

Global site tag (gtag.js) - Google Analytics