wiki:cli:files_and_directories
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:cli:files_and_directories [2014/08/02 23:44] – Add Key points jensv | wiki:cli:files_and_directories [2022/07/21 06:59] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====Navigating Files & Directories==== | ||
| + | |||
| + | The part of the operating system responsible for managing files and directories is called the file system. It organizes our data into files, which hold information, | ||
| + | |||
| + | Several commands are frequently used to create, inspect, rename, and delete files and directories. To start exploring them, let's open a shell window: | ||
| + | |||
| + | $ | ||
| + | |||
| + | |||
| + | The dollar sign is a prompt, which shows us that the shell is waiting for input; your shell may show something more elaborate. | ||
| + | |||
| + | Type the command '' | ||
| + | |||
| + | $ whoami | ||
| + | |||
| + | jens | ||
| + | |||
| + | More specifically, | ||
| + | |||
| + | *finds a program called whoami, | ||
| + | *runs that program, | ||
| + | *displays that program' | ||
| + | *displays a new prompt to tell us that it's ready for more commands. | ||
| + | |||
| + | Next, let's find out where we are by running a command called '' | ||
| + | |||
| + | $ pwd | ||
| + | |||
| + | / | ||
| + | | ||
| + | To understand what a "home directory" | ||
| + | |||
| + | Inside that directory are several other directories: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | We know that our current working directory ''/ | ||
| + | because ''/ | ||
| + | Similarly, | ||
| + | we know that ''/ | ||
| + | because its name begins with ''/'' | ||
| + | |||
| + | Underneath ''/ | ||
| + | we find one directory for each user with an account on this machine. | ||
| + | The Simon' | ||
| + | Kara's in ''/ | ||
| + | and Jens' in ''/ | ||
| + | |||
| + | > Notice that there are two meanings for the ''/'' | ||
| + | > When it appears at the front of a file or directory name, | ||
| + | > it refers to the root directory. When it appears *inside* a name, | ||
| + | > it's just a separator. | ||
| + | |||
| + | Let's see what's in my home directory by running '' | ||
| + | which stands for " | ||
| + | |||
| + | $ ls | ||
| + | | ||
| + | examples.desktop | ||
| + | |||
| + | '' | ||
| + | arranged neatly into columns. | ||
| + | We can make its output more comprehensible by using the flag '' | ||
| + | which tells '' | ||
| + | |||
| + | $ ls -F | ||
| + | | ||
| + | examples.desktop | ||
| + | |||
| + | Here, | ||
| + | we can see that ''/ | ||
| + | The names that don't have trailing slashes, | ||
| + | like '' | ||
| + | are plain old files. | ||
| + | And note that there is a space between '' | ||
| + | without it, | ||
| + | the shell thinks we're trying to run a command called '' | ||
| + | which doesn' | ||
| + | |||
| + | > What's In A Name? | ||
| + | > | ||
| + | > You may have noticed that all of my files' names are " | ||
| + | > something" | ||
| + | > almost anything else we want. However, most people use two-part names | ||
| + | > most of the time to help them (and their programs) tell different kinds | ||
| + | > of files apart. The second part of such a name is called the | ||
| + | > filename extension, and indicates | ||
| + | > what type of data the file holds: '' | ||
| + | > indicates a PDF document, '' | ||
| + | > for some program or other, and so on. | ||
| + | > | ||
| + | > This is just a convention, albeit an important one. Files contain | ||
| + | > bytes: it's up to us and our programs to interpret those bytes | ||
| + | > according to the rules for PDF documents, images, and so on. | ||
| + | > | ||
| + | > Naming a PNG image of a whale as '' | ||
| + | > magically turn it into a recording of whalesong, though it *might* | ||
| + | > cause the operating system to try to open it with a music player | ||
| + | > when someone double-clicks it. | ||
| + | |||
| + | Let's go inside '' | ||
| + | '' | ||
| + | |||
| + | $ cd bootcamp | ||
| + | |||
| + | '' | ||
| + | |||
| + | Notice, by the way that we spelled the directory name. | ||
| + | It doesn' | ||
| + | that's added to directory names by '' | ||
| + | And it doesn' | ||
| + | i.e., it tells '' | ||
| + | rather than from the root of the file system. | ||
| + | |||
| + | The leading ''/'' | ||
| + | so it always refers to exactly one directory, | ||
| + | no matter where we are when we run the command. | ||
| + | |||
| + | Let's make sure we are in '' | ||
| + | |||
| + | $ pwd | ||
| + | |||
| + | / | ||
| + | |||
| + | Let's look around with '' | ||
| + | |||
| + | $ ls | ||
| + | |||
| + | shell make | ||
| + | |||
| + | Now let's look a little bit closer let's run '' | ||
| + | |||
| + | $ ls -a -F | ||
| + | |||
| + | ./ | ||
| + | make/ | ||
| + | |||
| + | '' | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Let's look at '' | ||
| + | |||
| + | $ ls -F . | ||
| + | |||
| + | shell/ | ||
| + | |||
| + | $ ls -F .. | ||
| + | |||
| + | desktop.examples | ||
| + | |||
| + | We recognize the directory contents. | ||
| + | |||
| + | Let's go back to our home directory. | ||
| + | |||
| + | $ cd .. | ||
| + | |||
| + | $ pwd | ||
| + | |||
| + | / | ||
| + | |||
| + | > Orthogonality | ||
| + | > | ||
| + | > The special names '' | ||
| + | > they are interpreted the same way by every program. | ||
| + | > For example, | ||
| + | > if we are in ''/ | ||
| + | > the command '' | ||
| + | > When the meanings of the parts are the same no matter how they' | ||
| + | > programmers say they are orthogonal: | ||
| + | > Orthogonal systems tend to be easier for people to learn | ||
| + | > because there are fewer special cases and exceptions to keep track of. | ||
| + | |||
| + | Let's take an excursion to the ''/ | ||
| + | |||
| + | $ cd /bin | ||
| + | |||
| + | $ ls | ||
| + | |||
| + | ====Does anyone recognize any of the programs? | ||
| + | |||
| + | ====How do we get back to our home directory? | ||
| + | |||
| + | ====Key Points==== | ||
| + | *The file system is responsible for managing information on the disk. | ||
| + | *Information is stored in files, which are stored in directories (folders). | ||
| + | *Directories can also store other directories, | ||
| + | *''/'' | ||
| + | *A relative path specifies a location starting from the current location. | ||
| + | *An absolute path specifies a location from the root of the filesystem. | ||
| + | *Directory names in a path are separated with ''/'' | ||
| + | *'' | ||
| + | *Most files' names are '' | ||
| + | *Most commands take options (flags) which begin with a '' | ||