Ubuntu Learning Notes (ii)

Source: Internet
Author: User

1. Repetitive instructions

1.1 Repeat the previous instructions, you can use!! Command

Run as follows

1.2.! The string is a command that executes the most recently executed string as a starting point, and ! ? string[?] represents the most recent execution, including String the string. !n means repeating the command in the other history buffer or the nth number in the file .

Examples such as the following

In addition, "!!:[g]s/old/new[/"can be used to modify the command before execution. If all needs to be replaced , add a gto the front of s . Of course, the last one / can be omitted.

[Email protected]:~$ sudo mkdir test[email protected]:~$!!:s/test/test2/sudo mkdir test2[email protected]:~$ lsDesktop< C8/>downloads         Music     public     test   videosdocuments  examples.desktop  Pictures  Templates  

1.3 In the Korn Shell , you can use command r to repeat a previous instruction.

If the ksh is not installed then install it first. While studying, I looked at what commands my system could use,

[Email protected]:~$ sudo cat/etc/shells#/etc/shells:valid login Shells/bin/sh/bin/dash/bin/bash/bin/rbash

Unfortunately, no ksh command, I tried to install a bit, did not put up. But in order to use this command, we can also use the r command here. as shown below.

[Email protected]:~$ alias r= ' fc-s ' [email protected]:~$ lsdesktop    Downloads         Music     public     test   Videosdocuments  examples.desktop  Pictures  Templates  test2[email protected]:~$ rlsdesktop    Downloads         Music     public     test   videosdocuments  examples.desktop  Pictures  Templates  Test2


2. Supplementary order

2.1 Command supplement, if sometimes the command can not remember the command to add, enter BZ Press two tab after the following command appears,

[Email protected]:~$ bzbzcat         bzegrep       bzgrep        bzless        bzcmp         bzexe         bzip2         bzmore        Bzdiff        bzfgrep       bzip2recover  

Add C and press two times tab as follows

[Email protected]:~$ bzcbzcat  bzcmp  

pressing tab after entering a will automatically complete

[Email protected]:~$ bzcat

2.2 File name supplement, after you enter a part of the file name, press the tab key to supplement.

2.3 Variable name supplement,bash also supports the addition of variable name, when entering a variable name starting address, enter the tab key,bash Another part of the variable name will be provided.

[Email protected]:~$ echo $HO $home      $HOSTNAME  $HOSTTYPE  [email protected]:~$ echo $HOME/HOME/ZJQ

2.4 Command aliases, this is relatively easy, in the Windows dos window, when doing digital certificates, I have used this alias setting method. Here's a ls-l a name ll

[Email protected]:~$ alias ll= "Ls-l" [email protected]:~$ lltotal 52drwxr-xr-x 2 zjq  zjq  4096 Oct 08:54 Desktop Drwxr-xr-x 2 zjq  zjq  4096 Oct all 08:54 documentsdrwxr-xr-x 2 zjq  zjq  4096 Oct 08:54 Downloads

When defining a command alias, it is also important to note that if the alias contains values such as value, the use of single double quotes will have some differences, see the following two examples.

Double quotes

[Email protected]:~$ alias mydir= "echo current directory are $PWD" [email protected]:~$ alias Mydiralias mydir= ' Echo current Directory IS/HOME/ZJQ '

The value inside the alias is already explained in advance, and the directory inside is the current directory, and it will not change if you jump to another directory. Next I jump the path and execute mydir

[Email protected]:~$ cd public[email protected]:~/public$ mydircurrent directory IS/HOME/ZJQ

The value of the string has not changed at all

Single quotation marks

[Email protected]:~$ alias mydir= ' echo current directory are $PWD ' [email protected]:~$ alias Mydiralias mydir= ' Echo current Directory is $PWD '

I'll take a look at Mydir.

[Email protected]:~$ mydircurrent directory IS/HOME/ZJQ

I'll jump to a directory and execute mydir .

To cancel the alias, use Unalias to cancel the alias, then use alias to view the alias , the alias has been canceled.

[Email protected]:~/public$ unalias mydir[email protected]:~/public$ Alais mydiralais:command not found


3. Operation Control

3.1 Job control, when a & isfollowed by a name, theshell appears with the following information, a number indicating the job number, and the other is the process ID

[email protected]:~$ ls &[1] 4445

I don't have a long job to do here, so I'm just going to record the use of the command for the time being.

After the job runs in the background, you can use the jobs command to view the jobs that are running in the background.

When a job is too big we want to stop it, you can use Ctrl + Z

To put a stop command in the background, use bg%n (n is the job number )

To get the background job back to the foreground, use FG%n (n is the job number )

To stop a background job, use kill%n (n is the job number )

To wait for a job to run, use wait%n (n is the job number )

Of course, sometimes we may want to turn off the terminal, but it does not affect the operation until the end of the job. You can use the nohup command. For example, run a script nohup load.sh

3.2 Session record with command acknowledgement.

Using the script will be saved in the current directory typescript , you can Specify a different file name after the script, of course, if you use a file, It is also possible to add the-a parameter to the script , so that the previous content is not overwritten.

[Email protected]:~$ scriptscript started, file is Typescript[email protected]:~$ datethu Nov 04:07:09 PST 2014[email p rotected]:~$ Kk:command not found[email protected]:~$ lsdesktop    Downloads         Music     public     test   Typescriptdocuments  examples.desktop  Pictures  Templates  test2  videos[email protected]:~$ Uptime 04:07:22  up 5:16,  2 users,  

Use exit to terminate the session logging function, not to exit the terminal!

You can see the contents of the record below.

[Email protected]:~$ cat tyoescriptcat:tyoescript:No such file or Directory[email protected]:~$ cat Typescriptscript STA rted on Thu 04:07:04 AM pst[email protected]:~$ datethu Nov 04:07:09 PST 2014[email protected]:~$ Kk:comma nd not found[email protected]:~$ lsdesktop    Downloads         Music     public     test   typescriptdocuments  Examples.desktop  Pictures  Templates  test2  videos[email protected]:~$ uptime 04:07:22  up 5:16,  2 users,  

3.3 How to verify Ubuntu commands. When you enter a liux command,theShell lists the directory order by the path variable, the so-called retrieval path, to retrieve its
Matches the command. Sometimes it is possible to inadvertently modify the order of the retrievable, this time you need to see exactly which command is executed,

Whichis Command:

[Email protected]:~$ which Tar/bin/tar

Whereis Command

[Email protected]:~$ whereis Tartar:/bin/tar/usr/include/tar.h/usr/share/man/man1/tar.1.gz

3.4 You can use the apropos command When you need to perform a specific processing task without knowing the exact name of the command

It starts out exactly like Man-k.

[Email protected]:~$ apropos Whoat.allow (5)         -determine who can submit jobs via at or Batchat.deny (5)          -determin E who can submit jobs via at or batchbsd-from (1)         -print names of those who has sent Mailfrom (1)             -print names  Of those who had sent MAILW (1)-show who was logged on and what                they was Doing.w.procps (1)         -show who is logged On and what they be doing.who (1)              -show who is logged Onwhoami (1)           -Print effective Useridwhois (1)            -Clie NT for the WHOIS directory service

Of course, you can use the whatis command When you know a command and don't know his exact purpose.

[Email protected]:~$ whatis whowho (1)              -show who was logged on


Ubuntu Learning Notes (ii)

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.