Linux Command Line Basics : Lesson 3 : The Linux Filesystem

1. Intro to the Filesystem

Whether you're going to be developing web services and deploying them on a Linux Container, or doing systems work and troubleshooting servers, having a good grasp on the file system is pretty essential.
In this lesson, you'll practice working with files and directories, and using a range of shell commands that operate on them.

2. Quiz: The Filesystem Tree

The two most important kinds of objects in a Linux server's filesystem are files and directories.




The reason for this is that these characters all have special meanings to the shell, and putting a backslash in front of them tells the shell to treat them as ordinary characters.

Directories are nested inside each other, with the outermost or topmost being the file system root or root directory.
It's very common for there to be multiple discs or disc partitions on a Linux system.
Unlike on Windows, there aren't separate roots for each disc, like C: or  D: drives.
This means that no matter what directory a file is in, you can unambiguously refer to that file by giving the full path which starts at the root and lists each directory on the way down to the individual file.

3. Quiz: The Working Directory


If you want to know the path of that directory, you can use the pwd command which stands for print working directory, and this says that here the working directory .
You can change the working directory with the CD command for change directory.


4. Absolute and Relative Paths

The full path is called the absolute path, and that means that it tells every step that has to be taken from the root, or the absolute begging of the file system.

To make things simpler, we can use relative paths instead.
A file's relative path, is its location relative to the current working directory.



Notice that, unlike a full path, the relative path does not start with a slash.
That's how you can tell a relative path from an absolute one.

The special directory entry '..' points from a directory to its parent.
So, if you're in /home/philip/ocean, and you refer to '..', you're talking about the directory /home/philp
And '.' points from each directory to itself.
Another handy shortcut is ~. ~ is an abbreviation for your own home directory.

5. Quiz: Absolute and Relative Paths


6. Quiz: cd without args


7. Quiz: cd to not a directory


8. Quiz: Navigating Directories


9. Tab Completion

If you press tab and then tab again it'll list all of the possible completions for what you've typed.

10. Quiz: Moving and Copying Files

The shell command to move files is mv, which is short for move.
And the command cp is for copy.

11. Quiz: Making and Removing Directories

You can create new directories using the mkdir command.
All you have to give mkdir is a path to where the new directory should be.



And if you're done with a directory, and want to get rid of it, the command for that rmdir.
You can't use just plain rm on a directory.

But if a directory has files in it, you can't rmdir that directory.
There is a way to recursively remove a directory and all the files inside.



Curl is for downloading from a web URL and empty isn't one of those.
The r stands for recursive.

And this is the standard way to erase an entire directory and all of its contents.

And mv junk trash will do one of two different things.
If there is a directory called trash, it'll move junk to inside of it.
And if there isn't a directory called trash, it'll rename junk to trash.

12. Quiz: mv and directories


13. Globbing

Any time you want to operate on a bunch of files that have similar names, you can use a glob pattern to do it. Globbing is the real, actual, technical term for matching files by name in the Unix shell.
Globbing is a kind of pattern matching for file names.
When you write glob pattern in a shell command, the shell turns that pattern into a list of file names that exist to match the pattern.


Follow these following explanations one by one in order.

For instance, a star matches any string of characters.

You can use a star at the beginning or at the end of a pattern.

You can use two stars in the same pattern.
For instance, matching every file whose name contains pp.

A star can appear in the middle of a pattern.
Matching all the files that start with B and end with png.

To match files that end in either CSS or html, a list of strings in curly braces will match any of the alternatives.

A single question mark matches any one character.

Two question marks matches two characters, and so on.

List of character inside square brackets matches any one of the characters inside those brackets, so be and then square brackets.



Something to watch out for is that file names in Linux are always case sensitive, and that applies to globbing too.

14. Quiz: Globbing Quiz


15. Quiz: Applying Globbing


cp doesn't create directories on its own.

16. Course Outro

Now you're ready to go on to any number of subjects that depends on the command line interface.
Another command line tool to learn is Git.
A very popular distributed version control system.


0 개의 댓글:

댓글 쓰기