Favorite | 15 Ge You can not understand the Linux non-special characters, my mother no longer have to worry about these symbols I do not understand it!

Original: Collection | 15 Ge You can not understand the Linux non-special characters, my mother no longer have to worry about these symbols I do not understand it!

I do not know how long the system to Linux, which may have to find out about special characters Linux has it? In fact, ah, those special characters are great use of it, today's article gave you simply look at Linux in science you need to know 15 special characters, or just want to learn to learn Linux junior partner got in the car for!

~ Home directory

The tilde ~ refers to your home directory , which is our user's personal directory, no matter where you are, input cd ~it will take you home!

cd ~

More high-end play is, it is followed by concrete path, located directly specify the location of the home directory is not very easy to do?

cd ~/work/archive

. Current directory

Periods . Represents the current directory , we look at all the files in the current directory:

ls -al

The red circle . Refers to the current directory, but it does not make sense, we are using more of it in the command, as follows:

./script.sh

This is just telling bash to find and execute in the current directory script.shfiles just fine, do not find in the path.

.. parent directory

Two periods .. on behalf of the parent directory , which is the parent directory of the current directory. Suppose we want to return to the parent directory:

cd ..

As before, you can add it back specific directory, to locate here, which means that the current directory with the same level of other directories:

cd ../projects/

/ Directory path delimiter

Slash "/" refers to the path of the directory separator , to say nothing here.

ls ~/work/tests/

However, it is interesting that, if the / path directory separator character in front of nothing, then, is not that mean that this is the most superior of the catalog? Since the directory tree Linux systems are started / , so only one / representative of what we often say the system root directory .

cd /

# Comments

To # beginning, on behalf of this sentence is a comment .

# This will be ignored by the Bash shell

Although the above that phrase is ignored, but it will still add to your command history.

More powerful approach is as follows:

Define a variable and assign a value to the string "amazing alvin"

this_string="amazing alvin"

$ {this_string # amazing} return is commented out of this_string amazing string variables can echo output facie results:

echo awsome ${this_string#amazing}

commented it was just amazing, it has not been deleted, remove the comment it back:

echo $this_string

? The single character wildcard

Question mark "?" , Referring to the single-character wildcard . Bash Shell supports three wildcards .

It represents the file name any one character matching, for example:

ls badge?.txt

Note that it badge.txt not match drops, because no character behind the badge.

Because "?" Matches a single character, so here is a seemingly very powerful play, is the file name of the file you want to find how many characters you can enter how many "?" .

ls ?????.txt

Look very powerful, but how do I feel this good awkward? ? ? ? ?

* Wildcard character sequence

An asterisk * represents any sequence of characters , matches any character, including the null character to the badge just an example:

ls badge*

We can see, badge.txt match up.

Match any types of files:

ls source.*

[] Wildcard character set

Square brackets "[]" refers to the character set wildcard , matching at least one character in a file name characters must be associated with the character set. To understand what its role in it by way of example:

ls badge_0[246].txt

ls badge_[01][789].txt

ls badge_[23][1-5].txt

; Command separator

With this we use every day ";" almost, not elaborate, mainly used to separate the commands of.

ls > count.txt; wc -l count.txt; rm count.txt

Note here with; when separate commands, even if the first command fails, the second command will run, even if the second command fails, the command will run the third, and so on.

If you want to stop in case of a failure of the command, use "&&" , as follows:

cd ./doesntexist && cp ~/Documents/reports/* .

& Background Processing

Sometimes when the terminal is running a command, such as vim, you want to run another command how to do? Here is a tip that is in command behind the increase a "&" symbol, will start the program in the background, so you can achieve the effect of background multitasking in the terminal.

vim command_address.page &

Shown above is the ID of the background processes.

<Input redirection

Many Linux command accepts a file as a parameter, and obtain the data from the file. Most of these commands can also obtain input from the stream. To create a stream, you can use the left angle bracket "<" , as will be redirected to the command file:

sort < words.txt

Words.txt above the contents of the file and sorted.

Note: It does not display the file name of the data source file.

wc words.txt
wc < words.txt

> Output redirection

Input and output are reversed, is well understood. Right angle brackets ">" to redirect the output command, usually redirected to a file .

ls > files.txt
cat files.txt

Digital and high-end players can also be used together:

wc doesntexist.txt 2> errors.txt
cat errors.txt

Here is a file descriptor 2, the standard error (stderr)

We are interested in what can go search for the next file descriptors stdin, stdout, stderr that?

| Connect command

We can "|" as the pipeline linking commands together. It takes the output from a command, and sent as inputs the next command. Pipe command number is arbitrary.

cat words.txt | grep [cC] | sort -r

Under explained above to use the cat to enter grep words.txt content file, and then extracted grep comprise any lower or upper row (C / c), and then passes these rows grep to sort, sort for the final reverse sort -r .

! Logical NOT

This programming language with the "!" Almost take us directly with an example:

[ ! -d ./backup ] && mkdir ./backup

The first command -d to determine whether there is a backup of the current directory directory file, add a logical not outside ! Judgment,
the second command is to create a backup file directory,
middle && mentioned above.
When the backup is the general directory does not exist, create a backup directory; when there is no second command execution.

You may wish to look at the state of the backup folder:

ls -l -d backup

"!" Another use is to re-run the command history:

!24
!!

"!!" is meant to rerun the last command.

$ Variable expression

"$" At the beginning usually indicates variables, here are some system variables:

echo $USER
echo $HOME
echo $PATH

Of course, you can also define your own variables and output:

ThisDistro=Ubuntu
MyNumber=2001
echo $ThisDistro
echo $MyNumber

We can also "{}" unlock more advanced play:

MyString define a variable and assign it a value 123456qwerty

MyString=123456qwerty

Normal output

echo ${MyString}

Add ": 6" returns from the index position 6 the beginning until the end of the string

echo ${MyString:6}

From the display position of the index onward six characters from the string 0

echo ${MyString:0:6}

Display string at index 4 onward from 4 characters

echo ${MyString:4:4}

Quote special characters

He said so much, then there is a problem, that is, I just want to be in command inside these special characters as a general symbol display how to do? This we call the references, Linux there are three reference method.

Use double quotes "" quotes, but this "$" is not valid.

echo "Today is $(date)"

Single quotes '' enclosed, stops all functions of special characters .

echo 'Today is $(date)'

Backslash \ escape, which in many cases are common.

echo "Today is \$(date)"

Today science article is a bit long, it slowly digested Kazakhstan.

After reading all the love, the point of a walk praise chant? Your greatest force "triple" continued Xu Liang is created!

  1. Watch the original public number " Liang Xu Linux ", the first time for the latest Linux dry!
  2. No background information public reply [interview] [] [Resume] to obtain first-tier manufacturers featured interview, self-improvement, resumes and other information.
  3. Watch my blog: lxlinux.net

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12604652.html