Experience harvesting Linux Terminal handy command

Source: Internet
Author: User
Tags aliases

First, command line daily system shortcut keys

The following shortcuts are very useful and can greatly improve your productivity:

    • CTRL + U-cut the content before the cursor
    • CTRL + K-cut the cursor to the end of the line
    • CTRL + Y-paste
    • CTRL + E-Move cursor to end of line
    • CTRL + A-Move the cursor to the beginning of the line
    • ALT + F-Jump down a space
    • ALT + B-jumps back to the previous space
    • ALT + Backspace-delete the previous word
    • CTRL + W-cut the cursor after a word
    • Shift + Insert-Pastes text inside the terminal

So in order to make the above content easier to understand, look at the following line of commands.

    1. sudo apt-get intall programname

As you can see, there is a spelling error in the command, and the "intall" should be replaced with "install" for normal execution.

Imagine now that the cursor is at the end of the line, we have many ways to return her to the word install and replace it.

I can press two times alt+b so the cursor will be in the following position (where the cursor is used to refer to).

    1. sudo apt-get^intall programname

Now you can double-click the arrow keys and insert "s" into the install.

If you want to copy the text from the browser to the terminal, you can use the shortcut "SHIFT + Insert".

Ii. using Nohup to run commands after logging out of an SSH session

The nohup command is really useful if you are using SSH to log on to other machines.

So how do you use Nohup?

Imagine that you telnet to another computer using SSH, you run a very time-consuming command and then quit the SSH session, but the command is still executing. And Nohup can turn this scene into a reality.

For example, because of the need for testing, I sent my Raspberry Pi to download the release version. I will never give my Raspberry Pi an external monitor, keyboard, or mouse.

Generally I always use SSH to connect to the Raspberry Pi from my laptop computer. If I use Raspberry Pi to download large files without nohup, I have to wait until the download is complete before I log out of my SSH session and turn off my notebook. But if so, why should I use the Raspberry Pi file?

The method of using Nohup is also very simple, just enter the command you want to execute after nohup in the following example:

    1. nohup wget http://mirror.is.co.za/mirrors/linuxmint.com/iso//stable/17.1/linuxmint-17.1-cinnamon-64bit.iso &
    2. Use jobs to view tasks.

      Use FG%n to close.

Three, Linux/centos timing task at instruction detailed

directive: at
Timed tasks, specifying a time to perform a task that can only be performed once.

Syntax: # at [parameter] [TIME]
at> Execution of instructions
Exit at Command Ctrl+d

Command Prerequisites:
The ATD process needs to be turned on (ATD is started by default with system boot in Redhat)
The test found that there is no own at service in the centos6.5 mini version, so you need to download it yourself
# yum-y Install at

# Ps-ef | grep ATD # #查看是否开启atd
#/etc/init.d/atd Start # #开启atd
# chkconfig--level 2345 ATD on # #设置atd开机启动

Query deletes the current pending task
Queries the current wait task and is not displayed after it is executed
# ATQ

Delete a task in the system that is being set up by an at and waiting to be executed
# ATRM task's work number
Example: # ATRM 17

Common parameters:
-M: When the specified task is completed, the user will be sent a message, even if there is no standard output
Aliases for-I:ATQ
Aliases for-D:ATRM
-V: Shows when the task will be executed
-C: Print the contents of the task to standard output
-V: Display version information
-Q: Add < queue after > use specified queue
-F: Append < file > read into task from specified file instead of reading from standard input
-T: Back < time parameters > submit a task to run in the form of a time parameter

Time: Defines when to perform the at task, in the following format:
1, hh:mm
Note: At today's hh:mm time, if the time has passed, tomorrow's hh:mm will do this task.
Ex> 04:00

2, hh:mm YYYY-MM-DD
Description: Specifies that the task be carried out at a particular time of day of the month of the year
Ex> 04:00 2009-03-17

3, HH:MM[AM|PM] [Month] [Date]
A provision for the task at some point in a certain month of the year
Ex> 04pm March 17

4, HH:MM[AM|PM] + number [Minutes|hours|days|weeks]
Description: Specify how much time will be added to the task at a certain point in time.
Ex> now + 5 minutes
Ex> 04pm + 3 days

Time format extension:
At allows you to use a fairly complex set of time-specific methods.
1, can accept in the day hh:mm (Hours: minutes) type of time designation. If the time has passed, then it will be executed the next day.
2, can use Midnight (late night), noon (noon), Teatime (tea time, usually 4 o'clock in the afternoon) and other vague words to specify the time.
3, can use the 12-hour timekeeping system, that is, after the time plus AM (morning) or PM (afternoon) to indicate whether it is morning or afternoon.
4, can specify the specific date of the command execution, the format is Month Day (month) or mm/dd/yy (Month/day/year) or Dd.mm.yy (day. Month), the specified date must be followed by the specified time.
5, can use the relative timing method. The specified format is: Now + Count Time-units, today is the current time, Time-units is the time unit, here can be minutes (minutes), hours (hours), Days (day), Weeks (week). Count is the amount of time, days, hours.
6. Be able to specify the time to complete the command directly using today (present), Tomorrow (Tomorrow).

Restrict users ' use rights
Premise: Many hosts by the so-called attack, most often found that their system is a lot of hacking programs, these programs are likely to use a number of scheduled tasks to run or collect your system running information, and regularly sent to the hacker. So, unless it's your approved account, don't let them use the AT command first.
The control file used by the AT command to restrict user control of use
Control Files directory:/etc/at.allow and/etc/at.deny
Control file Usage Rules:
1: First find/etc/at.allow This file, write in this file user can use at, no user in this file can not use at (even if not written in At.deny);
2: If/etc/at.allow does not exist, look for/etc/at.deny this file, if it is written in this At.deny user can not use at, but not in this At.deny file users will be able to use the AT command.
3: If none of the two files exist, then only root can use the AT command.
4: In general distributions, because it is assumed that all users on the system are trustworthy, the system usually retains an empty/etc/at.deny file, which means that all people are allowed to use the AT command.
5: If you do not want some users to use at, the user's account will be written to/etc/at.deny! One account to write a line.
# Vi/etc/at.allow

Precautions
1, if the command output at the wrong path will send the results in the form of mail to the user
2, when a task is created will be assigned to a task number, and will be queued inside the/var/spool/at. It is not recommended to use VI Editor to modify, error-prone.

Example:
Example 1: Three days after 5 o'clock in the afternoon Chung execution of/bin/ls
# at 5pm + 3 days
At>/bin/ls
At> <EOT>
Job 7 at 2013-01-08 17:00

Example 2: Tomorrow 17 o'clock, the output time is within the specified file
# at 17:20 tomorrow
At> Date >/root/doiido.log
At> <EOT>
Job 8 at 2013-01-06 17:20

Example 3: After scheduling a task, use the ATQ command to see that the system is not performing a work task before it is executed
# ATQ
8 2013-01-06 17:20 a root
7 2013-01-08 17:00 a root

Example 4: Delete a task that has already been set
# ATQ
8 2013-01-06 17:20 a root
7 2013-01-08 17:00 a root
# ATRM 7
# ATQ
8 2013-01-06 17:20 a root

Example 5: Displaying the contents of a task that has been set
# At-c 8
#!/bin/sh
# Atrun Uid=0 gid=0
# Mail Root 0
echo "Hello"
Date > Doiido.log

Extended instruction Batch
Batch is a special version of the AT command that is used when performing tasks that consume a lot of resources, only when CPU requirements are less than 80% of CPU capacity
# Batch
at> echo "HI" >/dev/tty2
The tasks created by batch are also viewed through ATQ, atrm delete

Iv. using Htop to view and manage processes

Which command do you use to find out which processes are running on your computer? I bet it's ' ps ' and then add a different parameter to get the different output you want.

Install ' Htop '! Absolutely Brief Encounter you.

Htop renders the process as a list in the terminal, somewhat similar to Task Manager in Windows. You can use the combination of function keys to toggle the way you arrange and the items that are displayed. You can also kill the process directly in the htop.

Simple input htop in the terminal can be run.

    1. htop

Experience harvesting Linux terminal convenient command

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.