TranslateProject/sources/tech/20140701 Command Line Tuesdays--Part Two.md
2014-07-02 22:08:48 +08:00

4.8 KiB
Raw Blame History

乌龙茶占坑 Command Line Tuesdays Part Two

Heya geekos!

Lets refresh our memories. Last week, we skimmed through some basic commands, learned what a shell is actually, and made a steady introduction into our CLI Tuesdays series.

Todays menu offers something else: navigation through the file system.

Now, the best picture I managed to find on the www is from a site called devopsbootcamp. You can find their tutorials and the rest here. But anyway, heres a very nice diagram of what a linux root filesystem looks like.

Filesys

For example, as stated in the above picture, your user directory (where you usually store your movies, music, documents etc.) is located in the /home folder. /home folder is located under /. Then you have the /etc folder, where most of the files for configuration are located. Anyway, you can find the detailed description here, as well not be getting into which folder is for what, until we start using and configuring them. Today is reserved for navigation only. And on that note, lets get down to the first command of the day…

pwd

pwd, or print working directory is a very useful command if you think you are lost navigating through the folders. At any given moment, type pwd, and voila! What appears is a complete pathway you took to arrive to this folder. Those guys in The Cube could sure use it, losers.

Cube 注:此图原文哪里看不到,看看能通过什么途径得到

Imagine yourselves walking from room to room inside a massive apartment, loosing your way. pwd is like the breadcrumb trail leading you to your starting point, so you dont loose your way inside the folder maze!

pwd

cd

Now you know in which directory youre situated thanks to your usage of the pwd command. Now you want to take the next step and move to another directory. Lets say you have a folder/directory inside your home folder you want to relocate your top secret terminal operation to. For this, you use the cd command. cd, or change directory, will change the location of wanted directory. How do you use it? Simple, type cd and the path to your folder. Lets say, for example, you want to enter your Hello Kitty picture collection in your home folder. You type cd /home/username/Hello\ Kitty.

As you see, we didnt only use the space bar in the folder name. Thats because the terminal wont recognize it. Whenever you want to navigate to a folder containing a space in its name, you replace it with the backslash character, followed by space. You can also, without using the backslash+space option, just put the whole folder name into quotes, f.ex. cd /home/username/”Hello Kitty”.

cd

Try it out yourself. Navigate to a different directory using cd, and when there, type pwd to see if everything worked as its supposed to.

Mr. Shotts Shottcuts

Mr. Shotts reminds us there are also some shortcuts available.

If you type only cd, without the path following it, your terminal will change your working directory (whatever it may be) to your /home folder.

The same, if you type cd ~user_name it will lead you to the home folder of the specific user you stated.

Next Week

Next week, well head over to the next chapter well learn how to list files and directories, view text files and classify files contents so it will be a bit more work than were used to, but I hope youll have enough time. Command by command, and if you havent the time to do it yourself, well learn the basics together in a matter of months!

and remember…

…have a lot of fun!

P.S.: Thanks to bwls comment, we fixed an error in the text regarding the space bar in directory names.

P.P.S.: GreatEmerald also added some fresh information about file hierarchy. You can read it in the comments.

Thanks for your input/corrections.


via: https://news.opensuse.org/2014/06/24/command-line-tuesdays-part-two/

译者:译者ID 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出