码迷,mamicode.com
首页 > 其他好文 > 详细

how to navigate(跳转)the file system

时间:2017-09-10 01:16:04      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:configure   home   nan   contents   support   style   some   mbed   mina   

The first thing we need to learn to do (desides just typing) is how to navigate the file system on our Linux system.In this chapter we will introduce the following commands:

pwd-Print name of current working directory

cd-Change directory

ls-list directory contents(内容,目录)

 

understand file system tree

Like Windows,a Unix-like operating system such as Linux organizes its files in what is called a hierarchical(分层的)directory structure(结构).This means that they are organized in a tree-like(树状的) pattern(模式,图案) of directories (sometimes called folders in other systems),which may contain files and other directories.The first directory in the file system is called the root directory.The root directory contains(包含) files and subdirectories,which(指子目录) contain more files and subdirectories and so on and so on.

Note that unlike Windows,which has a separate(here is 单独的) file system tree for each storage device,Unix-like systems such as Linux always have a single file system tree,regardless of how many drives or storage devices are attached(附加) to the computer.Storage devices are attached(or more correctly,mounted) at various points on the tree according to the whims(突发的奇想,兴致) of the system administrator,the person(or persons)responsible for the maintenance(维护) of the system.

 

当前工作目录

Most of us are probably familiar with a graphical file manager which represents the file system tree as in Figure 1.Notice that the tree is usually shown upended(倒置),that is,with the root at the top and the various branches descending below.

技术分享

However,the command line has no pictures,so to navigate(航行于,在此指跳转) the file system tree we need to think of it in a different way

Imagine that the file system is a maze(迷宫) shaped like an upside-down(equal upended) tree and we are able to stand in the middle of it. At any given time(在任何给定的时间,在任意时刻),we are inside a single directory and we can see the files contained in the directory and the pathway to the directory above us(called the parent directory) and any subdirectories below us.The directory we are standing in is called the current working directory.To display the current working directory,we use the pwd(print working directory)command.

When we first log in to our system(or start a terminal emulator session)our current working directory is set to our home directory.Each user account is given its own home directory and when operating as a regular user,the home directory is the only place the user is allowed to write files.

 

List contents in the directory

To list the files and directories in the current working directory,we use the ls command.

技术分享

Actually,we can use the ls command to list the contents of any directoy,not just the current working directory,and there are many other fun things it can do as well.We‘ll spend more time with ls in the next chapter.

 

Change current working directory

To change your working directory(Where we are standing in our tree-shaped maze) we use the cd command.To do this,type cd followed by the pathname of the desired(想要的,渴望得到的)working directory.A pathname(follow cd) is the route we take along the branches(分支) of the tree to get to the directory we want.Pathnames can be specified in one of two different ways;as absolute pathnames or as relative pathnames.Let‘s deal with absolute pathnames first.(我们先来介绍绝对路径)

 

Absolute pathname

An absolue pathname begins with the root directory and follows the tree branch(分支) until the path to the desired(想要的,渴望得到的)directory or file is completed.For example,there is a directory on your system in which(这里的in which 指a directory,为毛要加in呢?因为这句话的主语是most of your system‘s programs如果去掉in,主语就成了a directoy.) most of your system‘s programs are installed.(你的系统中有个目录,大多数系统程序都装这个目录下。)The pathname of the directory is /usr/bin.This means from the root directory(represented by the leading slash in the pathname从开头的/)there is a directory called"usr" which contains a directory called "bin".

Now we can see that we have changed the current working directory to /usr/bin and that it is full of files.Notice how the shell prompt has changed?As a convenience(为了方便),it is usually set up to automatically display the name of the working directory.

 

Relative pathname

Where an absolute pathname starts from the root directory and leads to its destination,a relative pathname starts from the working directory.To do this,it uses a couple of special symbols to represent relative positions in the file system tree.These special symbols are "."(dot)and".."(dot dot)

The "." symbol refers to the working directory and the ".." symbol refers to the working directory‘s parent directory.Here is how it works.Let‘s change the working directory to /usr/bin again:

技术分享

Okay,now let‘s say that we wanted to change the working directory to the parent of /usr/bin which is /usr.We could do that two different ways.Either with an absolute pathname:

技术分享

Or,with a relative pathname:

技术分享

Now,there is something important that I must point out here.In almost all cases(在几乎所有的情况下),you can omit(忽略) the"./".It is implied(隐含的).Typing:

技术分享

does the same thing.(实现相同的效果。)In general(总之,通常,一般而言),if you do not specify a pathname to something,the working directory will be assumed(假定)..

例如:新建一个文件夹或目录,如果没有指定工作目录,那么它的工作目录就会被假定为当前工作目录。

 

Useful shortcut(短路,捷径,快捷方式) keys

In table 3-1 we see some useful ways the current working directory can be quickly changed.

shortcut result
cd changes the working directory to your home directory         (equal cd~)
cd - changes the working directory to the previous working directory   (equal cd..)
cd ~user_name

changes the working directory to the home directoy of user_name.For example,cd ~bob will change the directory

to the home directory of user "bob."

 

!!!Important Facts About Filenames

1.Filenames that begin with a period character(字符) are hidden.This only means that ls will not list them unless you say ls -a.When your account was created,several hidden files were placed in your home directory to configure things for your account.(当你创建了新账号,几个隐藏的文件将被放置在你的家目录底下,它们是用来配置、设定账号属性的文件。)Later on we will take a closer (仔细,更进一步)look at some of these files to see how you can customize(定制) your environment. In addition,some applications place their configuration and setting files in your home directory as hidden files.

2.Filenames and commands in Linux,like Unix,are case sensitive(区分大小写,!!!!要是不接触这本书我死都不会晓得这两单词是这意思).The filenames "File1" and "file1"  refer to different files.

3.Linux has no concept(观念) of a "file extension(文件扩展名)" like some other operating systems.You may name files any way you like.The contents(内容,厉害了刚刚傻逼样的还以为是上面的观念) and/or purpose of a file is determined by other means(手段,方法).Although Unix-like operating system don‘t use file extensions to deterimine the contents/purpose of files,some application programs do.

4.Though Linux supports long filenames which may contain embedded(嵌入式) spaces and punctuation characters(punctuation 标点符号、标点字符,character性格、字符,punctuation character标点字符,标点符号),limit the punctuation characters in the names of files you create to period(句号),dash(破折号),and underscore(下划线).Most importantly,do not embed(嵌入) spaces in filenames.If you want to represent spaces between words in a filename,use underscore characters.You will thank yourself later.

 

how to navigate(跳转)the file system

标签:configure   home   nan   contents   support   style   some   mbed   mina   

原文地址:http://www.cnblogs.com/itmeatball/p/7499848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!