The Linux learning record-----Happy Linux command line.

Source: Internet
Author: User
Tags readable

Before self-study python time has been used Win7, did not think, also a bit afraid to use Linux, may be a little fear of the unknown things, but, but, learning for 4 months, retreat can not be retired, whether it is the deployment of the site, or based on the needs of back-end work, Linux learning must be put on the agenda, Reference book,, "Happy Linux command line", OS installed by virtual machine Ubuntu 16

Like a word in a book

The beginning of the preparation work goes into the super user,,,,

Su-
This will change to Superuser in the current directory.
If you haven't set a superuser password before,
Need to use sudo passwd root
Follow the prompts, if prompted to enter a password, is your user password
Then prompt for a UNIX password
Confirm Unix Password
Then use Su-then prompt for the root password and then go to root.

1 jumps in the file system

The first thing we need to learn (in addition to typing) is how to jump in a Linux file system. In this chapter
, we will describe the following commands:

? pwd-print out the current working directory name

? cd-Changing the Directory

? Ls-List Directory contents shortcut key run Results

The CD changes the working directory to your home directory.

CD-Changes the working directory to the previous working directory.
CD? User name changes the working directory to the user home directory. For example, CD Bob will change the work
To the home directory of the user "Bob".

2

Ls-Listing Directory Contents

?? le-determine File types

? less-Browsing File contents

Understand the meaning of the letters behind the LS command

The LS command has a number of options. The table lists the most commonly used options.

Option Long option description
-A--all lists all files, even the default names that start with a dot
Hidden files that are hidden.


-D--directory Typically, if a directory name is specified, the LS command lists the directories in this directory
Content, not the directory itself. Combine this option with the-l option
Use, you can see the details of the specified directory, not the directory
Content in the.


-F--classify This option adds an indication after each name listed
Character. For example, if the name is a directory name, a '/' word will be added
Character.


-H--human-readable when listed in long format, in people-readable format instead of Word
The number of sections to display the size of the file .

-L Displays the results in a long format.
-R--reverse Displays the results in reverse order. Typically, the output of the LS command
In ascending alphabetical order.


The-s command output is sorted by file size.


-T is sorted by modified time.

3. manipulating Files and directories

cp-Copying files and directories

? mv-moving/renaming files and directories

? mkdir-Creating a Directory

? rm-Deleting files and directories

? ln-creating hard links and symbolic links

With 5 of the most common commands.

RM (delete) The most commonly used

Option meaning
-I,--interactive prompts the user to confirm the information before deleting the existing file. If you do not specify
With this option, RM will silently delete the file
-R,--recursive to delete a file recursively, which means that if you want to delete a directory, this
Directory is also included, the subdirectory is deleted. To delete an item
This option must be specified.
-F,--force ignores files that do not exist, and does not display prompt messages. This option overturns the "--
Interactive "option.
-V,--verbose displays informative operation information when executing the RM command.

Table 5-8: RM options

Command Run result
Rm. Le1 silently deleting files
Rm-i? Le1 except before deleting the file, prompting the user to confirm the information, and the above life
The same effect.
Rm-r le1 dir1 Delete files? le1, directory Dir1, and dir1 content.
RM-RF le1 Dir1, except if the file Le1, or directory Dir1 does not exist, RM still
will continue to execute.

Create your own commands with aliases (alias)
Now is the time to feel the first time programming experience! We will create our own commands with the alias command. But at the beginning
Before, we need to show a little command-line trick. Multiple commands can be placed on the same line, with ";" points between commands

Generate a command alias foo= ' Cd/usr; ls CD-'

Delete a command [[email protected] ~]$ unalias foo


Open. It works like this:

Command1; Command2; Command3 ...

We will use the following example:

[Email protected] ~]$ cd/usr; ls CD-
Bin Games Kerberos lib64 local share tmp
...
[Email protected] ~]$

As we've seen, we've combined three commands on a single line. First change the directory to/USR and then list the directories
Content, and finally back to the original directory (with the command "CD ~"), ending at the beginning of the place. Now, with the Alia command, the
A sequence of commands into a command. The first thing we need to do is to conceive a name for our new order. Say
"Test". It is a good idea to find out if the "test" command name already exists in the system before using "test". For
To find out, you can use the type command:

[[Email protected] ~]$ type test
Test is a shell builtin

Oh! The "test" name is already in use. Try "foo":

[[Email protected] ~]$ type Foo
Bash:type:foo:not found

That's great! "Foo" is not occupied yet. To create a command alias:

[[email protected] ~]$ alias foo= ' cd/usr; ls CD-'

Note the command structure:


Alias name= ' String '

After the command "alias", enter "name" followed by (no space) is an equal sign, followed by a string of
Quoted string, the contents of the string are assigned to name. After we have defined the alias, this command alias can be
Use in any place. Try it:

[Email protected] ~]$ foo
Bin Games Kerberos lib64 local share tmp
...
[Email protected] ~]$

We can also use the type command to view our aliases:

[[Email protected] ~]$ type Foo
Foo is aliased to ' cd/usr; LS; CD-'

To delete an alias, use the Unalias command, like this:

[Email protected] ~]$ unalias foo
[[Email protected] ~]$ type Foo
Bash:type:foo:not found

Although we intentionally avoid naming our aliases with existing command names, this is a common thing to do. Usually
Will add a commonly used option to a frequently used command. For example, the LS command, which was seen before, would take a colored
Color support:

[[Email protected] ~]$ type ls
LS is aliased to ' LS--color=tty '

To view all aliases defined in the system environment, use the alias command without parameters. Below in the Fedora system
The alias that is defined by default. Try to figure out what they do:


[[email protected] ~]$ alias
Alias l.= ' ls-d. *--color=tty '
...

5 | redirect

In this lesson, let's introduce perhaps the coolest feature of the command line. It is called I/O redirection. "I/o" represents input/output
Out, through this tool, you can redirect the command input and output, command input from the file, and the output is saved to the text
Thing You can also connect multiple commands together to form a powerful command pipeline. In order to show off this tool, we will describe
The following command:

? Cat-Connection File

? Sort-Sorts text lines

? Uniq-Report or omit duplicate lines

? grep-Print matching rows

? WC-the number of newline characters, words, and bytes in the printed file

? Head-The first part of the output file

? Tail-The last part of the output file

I/O redirection allows us to redefine where the standard output is sent. REDIRECT standard output to another file in addition to the screen,
We use the ">" redirect followed by the file name. Why are we doing this? Because sometimes a command's
Running results are useful for storing to a file. For example, we can tell the shell to convey the results of the LS command to the text
Ls-output.txt, the file replaces the screen.

[Email protected] ~]$ ls-l/usr/bin > Ls-output.txt

6 | See the world from the Shell's eyes,

? echo-Displays a line of text

1. Arithmetic expression expansion

[[email protected] ~]$ echo $ ((2 + 2))

[[email protected] ~]$ echo $ (($ ((5**2)) * 3))

2. Use of curly braces

[Email protected] ~]$ echo front-{a,b,c}-back
Front-a-back Front-b-back Front-c-back

A series of integers are used:

[[email protected] ~]$ echo number_{1..5}
number_1 number_2 number_3 number_4 number_5

A series of letters in reverse order:

[Email protected] ~]$ echo {Z.. A
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

So what's good about it? The most common application is to create a series of files or directory listings. For example, if I
They are photographers and have lots of photos. We want to organize these photos in chronological order. First, we will create a series of
A table of contents named in the form of a number "year-month". In this way, the directory names are sorted chronologically. We can key
into the entire directory list, but the workload is too large and error-prone. Instead, we can do this:

[Email protected] ~]$ mkdir Pics
[Email protected] ~]$ CD Pics
[[email protected] pics]$ mkdir {2007..2009}-0{1..9} {2007..2009}-{10..12}
[[email protected] pics]$ ls
2007-01 2007-07 2008-01 2008-07 2009-01 2009-07
2007-02 2007-08 2008-02 2008-08 2009-02 2009-08
2007-03 2007-09 2008-03 2008-09 2009-03 2009-09
2007-04 2007-10 2008-04 2008-10 2009-04 2009-10
2007-05 2007-11 2008-05 2008-11 2009-05 2009-11
2007-06 2007-12 2008-06 2008-12 2009-06 2009-12

·

The Linux learning record-----Happy Linux command line.

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.