A summary of the usage tips for Linux command line

Source: Internet
Author: User

2681421.jpg (16.24 KB, download count: in)

Download attachments

Linux command exercises with tips-Wheat Academy

2015-6-18 16:42 Upload

In the world of software development, the operating system that deals with apes as a web-side program is believed to be a Linux system. And for the use of Linux systems, if you can master some small tricks, in the process of development, debugging, I believe that the efficiency of things will be some improvement. Here are some of the 3 Linux programming user command-line tips that you can share.
1. How to schedule a task under Linux without using cron the so-called Cron is a task/command that is dispatched under Linux. We usually use cron when we dispatch a task, but it does not apply to cron, but it can also dispatch tasks. Runs a command (date) every 5 seconds and then writes the result to a file (Data.txt). To achieve this, we can run the following single-line script directly at the command prompt. $ while true; Dodate >> Date.txt; Sleep 5; Done & Where: While true: Allow the script to enter a loop in which the condition is always true, that is, to create a dead loop that repeats the commands inside again and again. Do:do is the keyword in the while statement, and the command after it is executed, where you can place one or a series of commands behind it. Date >>date.txt: Runs the date command and writes its output to the Data.txt file. Note that we use >&GT, rather than >. >>: Append write to File (Date.txt), so the output will be appended to the file each time the command is run. If you use >, the previous content will be overwritten over and over again. Sleep 5: Leave the script in a 5-second sleep state before running the command. Note that the time unit here can only be in seconds. This means that if you want the command to run every 6 minutes, you should use sleep360. Done:while the tag that ends the loop statement block. &: Put the entire process in the background. Similarly, we can run any script in this way. The example below is a script named script_name.sh that runs every 100 seconds. It is also worth mentioning that the script file mentioned above must be in the current directory, otherwise the full path (/home/$USER/.../script_name.sh) will be used. The single-line script that implements the above functionality is as follows: $ while true; Do/bin/sh script_name.sh; Sleep 100; Done & Summary: The single-line script above is not a substitute for cron because the Cron tool supports many options, is more flexible, and is more customizable. However, if we want to run some tests, such as I/O evaluation, the single-line script above will work.

2. How to clear the end content without using the clear command normally we use the clear command to empty the terminal content on Linux, but we will save a lot of time if we use CTRL + L shortcuts. Because CTRL + L is a shortcut key that cannot be used in scripts, you can use this shortcut in addition to the clear command to clear the contents of the screen in the script.
3. Run a command in another directory, and then automatically return to the current working directory in programming, we often want to run a command in another directory, and then go back to the current directory, but this is usually difficult to implement. In fact, to achieve this requirement is simple, you just need to put the command in parentheses. Let's illustrate this: avi@deb:~$ (cd/home/avi/downloads/) Example output: avi@deb:~ It first CD to the Downloads directory, and then back to the previous home directory. You might think that the commands inside are not executed at all, or that there is some kind of error, because there is no change from the command prompt. Let's simply modify this command: avi@deb:~$ (cd/home/avi/downloads/&& ls-l) Sample output:-rw-r-----1 avi avi 54272 May 3 18:37 text1.txt- Rw-r-----1 avi avi 54272 May 3 18:37 text2.txt-rw-r-----1 avi avi 54272 May 3 18:37 text3.txtavi@deb:~$ in the above command, it first enters downl OADs directory, then lists the contents of the file, and finally returns to the current directory. Also it proved that the order succeeded carried out. You can include any command in parentheses, and you will be able to return to the current directory after execution. The above is the Linux command line 3 super-practical tips, master and skilled use of them, will enable you to develop software on the Linux system appears more professional, more efficient.


Recommended Learning: PHP Development Practical Tutorial http://www.maiziedu.com/course/php/article source: Code
  • 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.