Linux Shell Command Learning Note (i)

Source: Internet
Author: User
Tags echo command

Key Points:shell types, echo,$, basic syntax, Ls,man,su,sudo,grep,ps,clear,cp,rm,cat,more

Reference: http://www.jb51.net/LINUXjishu/45329.html

There are many types of shells, such as the Csh,bourne Shell,korn shell. In most Linux distributions today, the default shell is typically the Bourne Again Shell (bash).

<echo>

Echo $SHELL

In Linux, the$ symbol represents a shell variable. All shells use variables in this way. There are some shell variables that have default values when your system starts. For example, $SHELL; $LOGNAME is your login name, and the $path variable indicates the scope of your shell command's search.

The function of the echo command is to print out your input. If your input has the special meaning of the shell, such as a shell variable, he outputs the value of the variable.

[Email protected] setup]$ Echo 123

123

[Email protected] setup]$ echo $LOGNAME

D4csqa

[Email protected] setup]$ echo $SHELL

/bin/bash

An important part of the Linux Shell command is that you can string the commands together. This is the ingenious feature that unix/linux from the very beginning of the first day. The simplest way to connect commands is to use "|", which we call "pipe". The output of the first command is the input to the next command.

The Linux command has its own grammar rules:

The basic syntax is like this:

Command-option file

Ls-la

The meaning of this line of command is to output the file name of all the files in the current directory, L for "long", A for "all", with the L option, you will find that the content of the output is more rich, not only the file name, as well as the access rights of files, owners, groups, etc.

Ls-l * (Equivalent to Ls–l | grep A *, but the latter can only be grep when a file begins with a only one case)

This command lists all the files that start with lowercase a in the current working directory, such as Abc.txt,alpha.jpg and so on.

LS A?CD

This command lists all files that end with a lowercase CD with an unknown character beginning with lowercase a. For example, Adcd,axcd, but ADFDCD is not listed and Axcd.txt is not listed.

Ls–l session**info*

This command lists all the files that contain the info string and the beginning of the session string, but only the simple sum, that is, for the two conditions that are satisfied at the same time, will not be identified only once, but enumerated two times. The process is to iterate through the files listed in the LS, for each file first to determine whether to satisfy *info*, is the output, and then to determine whether to meet session*, is the output. When all the criteria are questioned, skip to the next file, and so on.

But ls–l | grep Session | GREP info implements the intersection of conditions, that is, the output is to satisfy both the condition containing the session string and the condition containing the info string.

Summary:

For a single filter,ls–l *str* equivalent to Ls–l | grep str.

A simple overlay for multiple filter,ls–l *str1* *str2* (simpler than the set), Ls–l |grep str1 | grep str2 is the intersection.

<man>

Man: If you want to know what each command means and how he uses it, you can use the manual command, for example: Man ls. Man output is written for system administrators and developers, if you want to learn more about the use of commands, you can find the network of Linux command documents, there is a very convenient Daniel Barrett Linux pocket Guide.

<su><sudo>

The role of the SU and SUDO:SU commands is to switch users, which is also referred to as Superuser, because in some systems the SU command allows you to log on as a user root with all the privileges of the system. Unless you are a system administrator, I would never recommend you to use SU to switch to root, because this can cause you a lot of trouble. A more secure approach is to use the sudo command, which allows you to run a command with root privileges.

<grep>

grep is a powerful text search tool that uses regular expressions to search for text and print matching lines. For example:

grep foo/etc/passwd

Returns all rows containing Foo in the password file

Grep-i "foo"/etc/passwd

The-I option ignores case, which means that if a row contains Foo or foo, it will be searched.

grep also supports recursive search:

Grep-r "foo"/home/sjvn

This command will search for all rows containing "foo" in the/HOME/SJVN directory and its subdirectories.

GREP is also commonly used in tandem with other commands, such as:

Ls-la | grep foo

<ps>

Reports the status of the process. This command will show which programs are running.

<clear>

Clear the screen.

<cp>

CP file1 File2

Copy the contents of the File1 into the current folder File2. If File2 does not exist, create a new. If file2 exists, overwrite.

<rm>

Rm–i FileName

There will be a confirmation message.

<cat>

You can display text messages from your Linux computer. The difference from VI or VIM is that the former is read-only and the latter can be edited.

Cat/proc/cpuinfo

Show the important stats for your CPU.

Cat/proc/version

Show details of your currently running Linux distributions.

Cat/etc/printcap

Show the printer you are currently installing.

<more>

Content, paging display, space key to switch pages.

-num Indicates the number of single-page rows. The Space key scrolls the num rows one at a time.

Linux Shell Command Learning Note (i)

Related Article

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.