Linux 101 Hacks First CD command

Source: Internet
Author: User

This series comes from "Linux 101 hacks", the author also wrote other 101 hacks tutorials, read a few chapters, think skills are also good, very practical, do a summary collection.

Cdpath

Set the base directory

pwd/home/ramesh[[email protected]-db ~]# CD mailfile  or directory[Note: The above attempts to enter the current directory under the Mail subdirectory][[email protected]-db ~]# export cdpath=/etc[[emailprotected]-db ~]# CD mail
    /etc/mail[Note: The above is the Mail directory for entry/etc, not the mail directory under the current directory][[email protected]pwd/etc/mail

If you want the settings to be permanent, you can write export cdpath=/etc to ~/.bash_profile.
Similar to the environment variable PATH, you can also add more than one directory entry in Cdpath, with each directory entry separated by a colon, example
The following: for example:

Export Cdpath=.:~:/etc:/var

CD and Alias

I can only say too much TM.

mkdir -p/tmp/very/long/directory/structure/that/is/too//tmp/very/Long /directory/structure/that/is/too/pwd/tmp/very/long/directory/structure/that/is /too/deep# CD. /.. /.. /.. /pwd/tmp/very/long/directory/structure

You can use the following four ways to replace a CD: /.. /.. /.. /So that you can quickly return to the level four directory. In the following method, ".. 4 "To return to the Level 4 directory,". 3 "Return to Level 3 directory,". 2 "Return to Level 2 directory. Write the following aliases to ~/.BASHRC (the other Linux/unix may be ~/.bash_profile), and then log back in.

This common command can be saved in the ~/.BASHRC ~/.bash_profile /etc/profile, and will not be repeated

alias..="CD.."alias..2="CD.. /.."alias..3="CD.. /.. /.."alias..4="CD.. /.. /.. /.."alias..5="CD.. /.. /.. /.. /.."# CD/tmp/very/Long/directory/structure/that/is/too/deep# .4[Note: Use the.4returns the level four directory]#pwd/tmp/very/Long/directory/structure
Alias.. ="CD.."alias ...="CD.. /.."alias ....="CD.. /.. /.."alias ... ..="CD.. /.. /.. /.."alias ...="CD.. /.. /.. /.. /.."# CD/tmp/very/Long/directory/structure/that/is/too/deep# .....  [Note: Use ..... (5point) means to return up to level four of the directory]#pwd/tmp/very/Long/directory/structure
Alias CD. ="CD.."alias CD ...="CD.. /.."alias CD ....="CD.. /.. /.."alias CD .....="CD.. /.. /.. /.."alias CD ...="CD.. /.. /.. /.. /.."# CD/tmp/very/Long/directory/structure/that/is/too/deep# cd ..... [Note: Use CD ..... Return to the four-level catalogue]#pwd/tmp/very/Long/directory/structure
4 4 Layer directory. Alias CD1="CD . " alias CD2="CD. /.. " alias CD3="CD. /.. /.. " alias CD4="CD. /.. /.. /.. " alias CD5="CD. /.. /.. /.. /.. "
mkdir and CDs
mkdir -p/tmp/subdir1/subdir2//tmp/subdir1/subdir2/pwd/tmp/subdir1/subdir2/ Subdir3

Wouldn't it be great if mkdir and CD operations were implemented in a separate command? Try adding the following code
Enter./.bash_profile and log back in.

$ VI. bash_profile
function Mkdircd () {mkdir-p "[email protected]" && eval cd "\" \$$#\ "";}

This I personally feel very practical!

# mkdircd/tmp/subdir1/subdir2/pwd/tmp/subdir1/subdir2/subdir3
CD-

This technique is very common, and I don't talk about it.

Dirs, pushd, popd to operate the directory stack

Well, I'm familiar with the operation.

pushd into this directory

POPD exit this directory, return to your just directory, note, here as long as you pushd in, no matter how to operate, POPD will come back to the previous position, and CD-not the same

Dirs Display your current directory stack, meaning that you can pushd, and then pushd into the directory, dirs display all of your directory stack, popd and then exit one after another, advanced out of the queue

mkdir /tmp/mkdir /tmp/mkdir /tmp/mkdir /tmp/  /tmp//tmp//tmp//tmp/dir4# pushd. # dirs/tmp/dir4/tmp/dir4/tmp/dir3 /tmp/dir2/tmp/dir1[Note: The first directory name shown will always be the current directory, rather than explicitly pressing the contents of the Stack

At this point, the directory stack contains the following:

/tmp/dir4/tmp/dir3/tmp/dir2/tmp/dir1

The last directory to be pressed will be at the top of the stack. When you execute "popd", the system jumps to the top of the stack and clears it from the stack. As shown above, the last press on the stack is/tmp/dir4, so when a popd is performed, it jumps to the/tmp/dir4 directory and removes it from the stack at the same time. As shown below:

pwd/tmp/dir4[Note: After executing the popd command, the directory stack includes the following directories /tmp/dir3  /tmp/dir2/tmp/ pwd/tmp/dir3[Note: After executing the popd command, the directory stack includes the following directory]/tmp/dir2/tmp/dir1
Shopt–s Cdspell

Use "Shopt-s Cdspell" to automatically fix the misspelled directory name on the CD. If you make a lot of mistakes in typing,
Error, this command is very useful. See the following examples:

I didn't use it much.

# cd/etc/Mallfile-/etc/pwd/etc/mail[Note: When I mistakenly knocked mail into the Mall, with this command mall will automatically be replaced by mail]

Linux 101 Hacks First CD command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.