Linux operating system Getting Started Basics Tutorial 3

Source: Internet
Author: User

Chapter III Linux Basic use of commands (basic )-(advanced article in the following, this chapter from a practical point of view to introduce basic operations )

Now please enter your username and password, of course, we enter root, so that all administrative rights !

You must very much like to see those very beautiful graphical interfaces at once, but maybe I'll let you down. I recommend mastering basic Linux commands before using the graphical interface, which is a real linuxer. Where do you start ?

  1. LS lists the file and directory commands

You must really want to know what's on your computer, now execute the command ls, ah, why nothing ? Of course, this is the first time you have logged into this system, your default location is your personal directory, not the system root directory. You have not stored any personal files in this directory, of course, nothing at all. If you are logged in as root, your personal directory is the /root directory, and if you are logged in with a regular user, such as Kris, then Kris's personal directory is /kris. What does the previous /mean? is the meaning of "root", that is, the first directory, in the root directory under the establishment of a lot of subdirectories, we have discussed in Chapter one.

  The LS command has a number of options, which are commonly used:

  The-a option is used to list all files, including those that are hidden. Why do we have to hide the file? Reason and why you want to hide the love letter is not let mom and dad find is the same. It's for secrecy. Now execute the ls-a look ? Is there a hidden file ". BASHRC" being shown ? You must be surprised to find that this file name is preceded by a dot, yes ! Remember, as long as the first character in front of the file name is a ".", This file is a hidden file. The first character in front of a directory name is "." This directory is the hidden directory.

  -l This option is used to display a list of the most properties of all the files under this directory. You can have the size of each file, the owner, your permissions and the modification date, and so on.

  -R R means recursive recursion, obviously this option allows the system to display all the files under this directory, as well as the files under all subdirectories. Which is to shake out all our big piles of fruit.

  --color This option is particularly useful, I estimate that everyone's display is color-show it, what ? Is your monitor still black and white? For the color display , then we can let the LS command use a different wink to represent different file types. For example, the executable file is green, the normal file is white, the directory is blue. You might ask, is the directory also a file? Yes, in Linux everything is a file, all hardware devices are replaced with a file, such as your floppy drive, is replaced by/dev/fd0. The directory is also a file.

  --help This option is available for almost every Linux command and is used to display the Help information for that command.

  2. CD and mkdir and RM change of course directory, create new directory and delete directory command

The strike, just said the directory, each time we login has a default directory is our personal user directory. How do we get to other directories? ?cd is used to change the current directory. As we said earlier, cd/You can enter the root directory. Won't you try it?

Let's see what files and subdirectories are under the root directory, execute ls, and we found that there is a directory name under the root directory is a special pervert, called usr, go inside to see, cd usr, see what is there psycho (perverted src, into the src directory to see ? Nothing fun. So now we go back to the usr directory, how to do is cd usr? Perform a try, as if not, the system reported an error cd:usr:No such file or directory. What's this about, /usr/src, we execute cd usr means to enter /usr/src/usr directory instead of /usr directory. The correct approach is to cd/usr.

Like you in the Chinese food in the basket to see a Sichuan's basket, there is a small baskets in Chengdu, now you enter after the discovery of Chengdu's small basket inside a very spicy food called "spicy". You want to eat some dessert after the big meal, so prepare to go to Fuzhou. Can you stand in the basket of Chengdu to go to Fuzhou? of course, Fuzhou is not in the basket of Chengdu, you should enter the "/Chinese cuisine /Fuzhou " instead of "/Chinese cuisine /Sichuan /Chengdu /Fuzhou " right ?

OK, a problem arises, I go to a directory every time, to use /usr/src ... Is this a complicated way to express it ? not necessarily. We use the ".." Way to represent the previous level of the directory. If you are now in the /usr/src directory, There are two ways to enter the/usr directory:cd/usr and CD. They are the same.

How do I know which directory I am in now ? With the command pwd, this command has nothing to say, the execution once knew.

Now I want to create a directory in my own personal directory called Loveletter. I should first go back to my own directory, here is a simple way, is to directly run the CD without any parameters, so you can go back to their own directory, of course, you can Cd/root or cd/home/kris, see what you are logged in with what user.

After entering my own directory, the command to create a new directory is

  mkdir New directory Name

I execute mkdir loveletter to build a new directory called Loveletter. Go to this directory and see ? Don't worry, take it slow. I'm not in a hurry, what's your hurry ?

Suddenly I think of this computer my parents also want to use, they see my love letter directory What to do ? You forgot what I just said. You can add a point to the "." In the previous method to hide directories and files ? We can change the name of this directory, but this command I am going to talk about later, now we use a very boring way to complete this request. The idea is to delete the Oveletter directory you just created in the new one . Loveletter directory, the reason that this method is very boring, because we are now doing experiments, if it is true, you would like to delete your love letter?

The command to delete a directory can actually delete the file, which is RM.

  RM file name /directory name to be deleted

I remember Redhat will prompt you if it is really going to be deleted. Pressing y is OK, and pressing n is canceling. If Redhat does not prompt you, then will please according to I say the method modifies the system to let it prompt us. Lest the heartache later. Deleting a file is simple. The trouble is to delete a directory, if there are already files in a directory,RM is not allowed to delete directly, you must first delete all the files in the directory, and then delete the directory. But there is a parameter can be changed, that is, -RF, this parameter is a certain danger, because even if the system would have been to remind you if it is true to delete the directory, plus this parameter will not be prompted. Execute RM directory -RF will have your information dismissed in the blink of an hour !

Then I'll delete the Loveletter directory now:RM loveletter-rf

Create a new directory for mkdir. Loveletter

Now ls to see, is not see loveletter directory ? But ls-a still can see. So the hidden way can only be their own, really let your file security way or later to talk about it.

  3. MV Change the file name and directory name of the command

  CP Copy files and directories command

  Man command use method Reference tool

  MV old filename New file name

  MV Old directory name new directory name

You can change the name of the file or directory.

I want to put this directory just now . Loveletter renamed back, because this boring way of hiding is very perverted, we have a more advanced way to do such a thing: just don't tell mom and dad your password !!!

  Mv. Loveletter Loveletter

  The CP command is used to copy a file into a new file,

  CP old filename New file name

This old document and the new file name if under the same directory, then of course, the name is not the same, very simple, if the name of the same reason why create two files ? If the old and new files are in different directories, we can make them have the same name. This is illustrated in the following example:

  CP Loveletter loveletter_yesterday The new file Loveletter_yesterday and the old Loveletter in the same directory, so the name is not the same.

  CP loveletter/home/loveletter The new file is under the/home directory, but the old file Loveletter under a user's personal directory, of course the two names can be the same.

  The CP command can also copy the entire directory, but for now we are not so complicated. In fact , CP and RM and ls These commands are not only the basic commands of Linux, but also contain a lot of functions. If you are interested, you can use Man

  Man command name

such as man ls, so that you can see all the LS command and parameters of the Keyholder interpretation, especially a part of the common command of the man Help has been translated by volunteers, everyone looks easier.

A little humor.

Well, said a lot of things, I want to rest, to tell you an interesting thing, we said a lot of commands and directories of the name, you do not feel a bit strange. To be honest, I didn't know what it meant when I first saw the USR directory, but then found the following correspondence:

  USR->; User

  LS->; List

  mkdir->; Make Dir

  RM->; Remove

  SRC->; Source

  MV->; Move

  CP->; Copy

  ...

Isn't it interesting that in the Unix world, including the Linux world, people's imaginations are so invincible ! Shorthand can be abbreviated to such a child. The general idea is to take a word of the first three or the first four letters as shorthand, but the Unix cattle are like to move shorthand to become mv, really do not know what they think. Let's all be subtle.

  4. Nano and vi Edit file commands and cat as well as more display text file

  Nano is a small free, and friendly editor, I think the Nano is more suitable for beginners who use Linux. We now only learn how to edit a file and how to save it.

  Nano file name

If you write a file name that already exists, open it and edit it, or create a new file. is the editing method still used to say ? hehe, when you want to quit, press ctrl+x, and theNano will ask you if you are saving the edited file. Press y to save and press N to not save.

  The biggest advantage of Nano is that the user can not remember too many operation keys, most of the common functions of the operation methods are listed on the screen. Novice need to note that "^x" is to hold down the CTRL key and then press the X meaning.

The following is a brief introduction to VI. VI is a very powerful editing software. It is too big to write a book dedicated to explain. From the point of view of use, let's talk about the usage of VI.

  VI has two modes, one is command mode and one is edit mode. after entering VI, the default is in command mode.

Now we doVI Loveletter. After entering, click on the keyboardInsert Function Key orI can enter the editing state, you can insert characters, then clickInsert into the cover mode, the difference between the two modes is easy to reflect, you can try it. Up and down four arrow keys to move the cursor. Basic editing commands andwindows there is no difference. Isn't it easy? esc key from edit mode back to command mode, first enter a colon shift key and then press the semicolon ";" This first enters a w, enter, you can save our edited content to loveletter file. Now let's press insert to continue editing. Then press ESC, enter ":", and then press w and can be saved. But now we do not need to save, we want to quit without saving, how to do it w is write meaning, save, Then we enter q is quit exit meaning. OK, input q, enter, vi hint we have just made the changes have not been saved, so remember ! once you need to discard our changes, we cannot directly use the Span lang= "en-us" >q command exits and requires q!, OK, quit.

We want to see if the loveletter we just edited is really saved, then vi loveletter,OK, see ? Now we want to exit directly, you can just enter ": Q" on it, do not enter that “!” Because we did not modify the contents of the file. If we revise this article, we can enter "Esc:wq" when we exit . You do not need to divide W and Q into two inputs.

  VI of the most basic usage of this is almost, if you want to know more about the knowledge of VI, after entering the VI directly according to F1 on it, there are keyholder help and teaching.

In fact, just now we want to look at the editor's Loveletter is not saved, no more VI in, just need to use the command

  Cat Loveletter

You can do it. Cat is the command used to display the contents of a text file. If our text file is very long and a screen is not displayed,cat will not automatically page out. We can switch orders .

  More Loveletter

  The more command displays a text file, if there is too much content, it will automatically pause at the end of each page until the user presses the SPACEBAR to continue.

  5. Most important command:halt reboot shutdown and restart command

In Linux, can not be directly with the power button shutdown, nor directly with the reset button restart, which has a large impact on the system, especially the hard disk. The shutdown command is Halt, and the restart command is reboot. In fact, there are shutdown commands to complete similar functions, if necessary, please use the man command learned today .

Finally finished this chapter, hope that the new person can be well read, this will help you. the configuration of Xwindow will be described below. This is a topic that everyone cares about.

See more IT industry articles see: Http://t.cn/Rz00TiA

Linux operating system Getting Started Basics Tutorial 3

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.