UNIX Productivity Skills

Source: Internet
Author: User
Tags echo command time and date

Is UNIX used in daily office environments? Not necessarily very clumsy. Using the powerful functions and available system tools of Unix shell can greatly improve your work efficiency in the office.

Introduction

UNIX? The command line language is well known for its comprehensive functionality. By using a variety of small tools, utilities, and combining them in Shell for execution, you can specify many precise and complex tasks.

However, when using them in an office environment, these tools may become powerful assistants to improve your work efficiency. Many unique UNIX skills can be used to improve productivity.

This article provides some suggestions and tips for using command lines to improve office efficiency, this includes how to view the current system habits, how to calculate the time spent, how to operate the secret of the date, how to use a fast and simple method to send reminders to yourself, and how to automate repetitive interactive tasks.

View daily habits

The first step to improve office efficiency using Unix command lines is to carefully study your daily habits. The commonly used tools and applications, as well as accessing and modifying files, can tell you what kind of daily work takes a lot of time and what operations should be avoided.

View the tools used

You need to check which tools and applications are frequently used. You can easily find out your daily work habits in the built-in history of shell, which will output an enumeration list of the input row content sent to shell in the current and past sessions. For a typical example, see Listing 1.

Listing 1. example output of shell built-in history


$ History
1 WHO
2 ls
3 CD/usr/local/proj
4 Ls
5 CD WebSphere
6 ls
7 LS-l
$

A real history is usually stored in a file for future sessions. For example, the Korn shell saves the command history in a hidden file in the user's home directory. sh_history, While bash shell uses. bash_history. These files are usually overwritten after a certain length is reached, but many shells have variables that set the maximum length of history. Korn and bash shell have variables of histsize and histfilesize, you can set them in your shell Startup File.

Using sort to run history is very useful, and you can get a list of the most commonly used commands. Then, use awk to delete the command name minus option and parameters, and then pass the sorted list to uniq to get an enumeration list. Finally, call sort again to sort the first column of the list in reverse order (the largest column is in the front), which is to enumerate itself. Listing 2 shows an example of the actual operation.

List 2. LIST commands in Shell history based on usage frequency


$ History | awk '{print $2}' | awk 'begin {FS = "|"} {print $1}' | sort | uniq-c | sort-R

4 Ls
2 cd
1 WHO
$

If the history file is large, you can first transmit it to tail through a pipeline to perform periodic checks. For example, to check the last 1,000 commands, you can try:

$ History | tail-1000 | awk '{print $2}' | awk 'begin {FS = "|"} {print $1}' | sort | uniq-c | sort -R

View accessed or modified files

You can use the same principle to view the accessed and modified files. To do this, you can use the find utility to locate and view all files that have been accessed or changed within a certain period of time (today, yesterday, or any past date or time.

Generally, you cannot find out who finally accessed or modified the file, because it is not easy to obtain such information in UNIX, however, by limiting the search to files contained in your home directory tree, you can only view personal files. You can also restrict the search so that you can only search for files in a specific project directory that you are monitoring or using.

The find utility has several symbols that can be used to locate files based on time, as shown in table 1. Directories are not regular files, but they are accessed when they are listed or used as the current working directory. Therefore, you need to exclude them using the negative and-type signs in the search.

Table 1. Some flags of the find utility
Flag description
-Daystart indicates that it starts from the early morning of the specified day.
-The last time atime accessed the file, expressed in days.
-Ctime: the time when the last state of the file is changed, expressed by the number of days.
-The time when the last file is modified by mtime, expressed by the number of days.
-The time when Amin finally accesses the file, expressed in minutes. (Not all implementations are available .)
-The time when Cmin last changed the File status, expressed in minutes. (Not all implementations are available .)
-Mmin indicates the last modification time of the file, in minutes. (Not all implementations are available .)
-Type indicates the file type. For example, D indicates the directory.
-The user X file belongs to user X.
-The group X file belongs to group X.
-Newer X Files are updated compared with file X.

The following describes how to list all the files modified in the home directory tree one hour ago:

$ Find ~ -Mmin 60 /! -Type D

If a negative value is specified for the flag, it indicates that the value must match or be closer. For example, the following describes how to list all the modified files in your home directory tree from an hour ago to now:

$ Find ~ -Mmin-60 /! -Type D

Not all find implementations support the min flag. If your find statement is not supported, you can use touch to create a virtual file, whose timestamp is earlier than the file to be searched, and then use the-newer flag to search for files updated compared to it:

$ Date
Mon Oct 23 09:42:42 EDT 2006
$ Touch-T 10230842 temp
$ LS-l temp
-RW-r -- 1 Joe 0 Oct 23 08:42 temp
$ Find ~ -Newer temp /! -Type D

The special-daystart flag can be used with any date option to measure the time from the early morning of the current day (instead of 24 hours ago) to the command execution time. The following command attempts to list all the files that have been accessed from anywhere in the system in the early morning:

$ Find/-user 'whoam'-daystart-atime-1 /! -Type D

Similarly, you can list all the files modified in the home directory tree today:

$ Find ~ -Daystart-mtime-1 /! -Type D

You can change the search time by assigning different values to different time signs. You can also combine these labels. For example, you can list all the files in the home directory tree that have been accessed and modified since seven days ago:

$ Find ~ -Daystart-atime-7-mtime-7 /! -Type D

You can also find files based on a specific date or time range (measured by day or minute. To complete this task, you can use touch to create one or more virtual files, as described earlier.

When you need to find files that match a certain range, create two virtual files whose timestamps can describe this range. Then, use the-newer flag for the older file and "/!" For the second file. -Newer ".

For example, to search for all the files accessed in the/usr/share directory tree on January 1, August 2006, try the following command:

$ Touch-D & quot; Aug 1 2006 & quot; file. Start
$ Touch-D & quot; Sep 1 2006 & quot; file. End
$ Find/usr/share-daystart-newer file. Start /! -Daystart-newer file. End

Finally, when listing the directory content, you can sort it by the last modification time of the file, which is sometimes helpful. In some versions, the LS tool has the-C option, which can be sorted by the file modification time and display the last modified file first. Used together with the-l (long list) and-T (sort by modification time) options, you can sort the directory list in the order in which the last modified files are located, the long list shows the file modification time rather than the default Creation Time:

$ LS-LTC/usr/local/proj/WebSphere | less

Computing time spent

Another valuable way to improve office efficiency using UNIX is to calculate the time spent on frequently executed commands. Then, you can evaluate the results and determine if you have spent too much time waiting for the end of a specific process.

Time spent on Command Execution

Is the system running slowly? How long have you waited in shell? Nothing can be done when a specific command is executed? How long does it take to complete daily work in the morning?

When you use the date, sleep, and echo commands to calculate the time spent on a specific task, you can obtain substantive answers to these questions.

To do this, you can enter a long input line starting with the date statement to output the time and date in the required format (generally, hours and minutes are enough. Then, run the command input line (which may be several lines of content concatenated by shell commands), and use the same input line to obtain the date again. If the commands you test produce a large amount of output, you can redirect them to read the start and end dates. Calculate the difference between the two dates:

$ Date; system-Backup>/dev/NULL; system-diag>/dev/NULL ;/
> Netstat>/dev/null; df>/dev/null; Date

Test your typing speed

You can use the same method to test typing input:

$ Date; CAT | WC-W; Date

If you provide an input example that lasts for at least 1 minute, but preferably 3 minutes or longer, the result of this command is more accurate. Calculate the difference (in minutes) between the two dates, and divide the value by the number of words you enter (output by the Intermediate command, get the average number of words entered per minute.

You can automate this task by setting corresponding variables for the start and stop dates and the number of output words. However, to correctly complete this task, you must avoid a common error when using these time for subtraction calculation. GNU has extended the date command, namely the % s format option, to avoid such errors. It outputs the number of seconds since the Unix new era, which is defined as the UTC time in the early morning of January 1, January 1, 1970. Then, you can calculate the time separately based on the number of seconds.

Assign a variable speed as the output of the ECHO command to set the correct formula and pass it to the calculator tool, such as BC through a pipeline. Then, a new echo language is output, which will output the message about the typing speed:

$ Start = 'date + % s'; words = 'cat | WC-W'; stop = 'date + % s'; speed =/
> 'Echo "$ words/($ stop-$ start)/60)" | bc'; ECHO/
> "You have a typing speed of $ speed words per minute ."

You can put it in a script and change its permissions so that all users can execute it so that other users in the system can also use it, as shown in listing 3.

Listing 3. Example of running typespeed script


$ Typespeed
The quick brown fox jumped over the lazy dog. The quick brown dog --
...
-- Jumped over the lazy fox.
^ D

You have a typing speed of 82.33333333 words per minute.
$

Date

The date tool can do more work, not just print out the current system date. You can use it to obtain the day of the week for the given date, and obtain the relative date relative to the current date.

Know the day of a week

Another extension of GNU's date command is the-D option. This option is useful when there is no calendar table on your table (Unix users do not need a calendar table. With this powerful option, you can quickly find out the day of the week for a specific date by enclose the date as a parameter enclosed by quotation marks:

$ Date-d "Nov 22"
Wed Nov 22 00:00:00 est 2006
$

In this example, you can see that July 22, November 22 is Wednesday this year.

Therefore, if you hold a major meeting on July 15, November 22, you can immediately learn that this day is Wednesday and that day you will arrive at the resident office.

Get relative date

The-D option also tells you which day is relative to the current date, from the current several days or after several weeks, or before (past ). You can complete this task by enclose the relative offset in quotation marks as a parameter of the-D option.

For example, you need to know the date two weeks later. If you are at the shell prompt, you can quickly get the answer:

$ Date-D '2 weeks'

There are other important methods to use this command. With the next command, you can get the day of the week in the future:

$ Date-D 'Next Monday'

Using the AGO command, you can get the past date:

$ Date-D '30 days ago'

You can use a negative number to get the opposite Date:

$ Date-D 'dec 14-2 weeks'

This technique is very useful. It can Set reminders for itself based on future dates, possibly in scripts or shell startup files, as shown below:

Day = 'date-d' 2 weeks '+ "% B % d "'
If test "'echo $ Day'" = "Aug 16"; Then ECHO 'product launch is now two weeks away! '; FI

Set reminders for yourself

You can use a variety of tools in the system to set your own departure reminders. they consume less space than paper notebooks and can be seen wherever you log on.

Know when to leave

When you work in the system, you may encounter other things. What is the leave tool on ibm aix? Operating systems and Berkeley Software Distribution (BSD) systems (see references) are very common and can help you.

Specify the departure time for the leave command, in the 24-hour format: hhmm. It runs in the background and will output a message on the Terminal 5 minutes before the given time to remind you to prepare for departure. If you are still logged on one minute before you leave, it will display this reminder message again, and then at the time when you should leave, then, it sends a reminder every other minute until you log out (or terminate the leave process ). Listing 4 provides an example. When you log out, the leave process is terminated.

Listing 4. Example of running the Leave command


$ Leave
When do you have to leave? 1830
Alarm set for Fri Aug 4. (PID 1735)
$ Date + "time now: % L: % m % P"
Time now: PM
$
<System bell rings>
You have to leave in 5 minutes.
$ Date + "time now: % L: % m % P"
Time now: PM
$
<System bell rings>
Just one more minute!
$ Date + "time now: % L: % m % P"
Time now: PM
$
Time to leave!
$ Date + "time now: % L: % m % P"
Time now: PM
$
<System bell rings>
Time to leave!
$ Date + "time now: % L: % m % P"
Time now: PM
$ Killed 1735
$ Sleep 120; date + "time now: % L: % m % P"
Time now: PM
$

You can provide relative time. If you want to leave after a certain time from now on, you can add + before the time parameter. To remind you to leave in two hours, enter the following command:

$ Leave + 0200

To provide time in minutes, you can set the hour field to 0. For example, if you know that you must leave after 10 minutes, you can enter:

$ Leave + 0010

You can also specify the exit time as the parameter, which makes leave a very useful command in the script, especially in the shell Startup File. For example, if you normally work until five o'clock P.M., but you must leave the Organization at four o'clock P.M. on the fifth day of the week, you can set a weekly reminder in the shell Startup file:

If test "'date + % a'" = "fri"; then leave 1600; FI

You can add a simple leave statement in the startup script without any parameters. Each time you log on to the shell, you can enter the departure time. If you press enter, that is, no value is specified, leave will exit without setting a reminder.

Send email reminders for yourself

You can also use text messages to send reminders for yourself. Create a reminder message, which is useful in some cases. You will learn this in the current logon session or the next logon.

Previously, the old elm mail proxy came with a tool that allows you to send memos via email, which is actually a script, subject, and body text to remind the sender. By using the time-based method, you can use the command line mailx tool to send emails to yourself, so that you can easily copy this process. (In some Unix systems, use mail instead of mailx .)

Provide your email address (or your user name in the local system, if you read the email in the local system) as a parameter, and then, you can enter a reminder message in the prompt subject line (if it is very short), as shown in listing 5. If the reminder message is not suitable for the subject line, you can enter it in the message body. A single line ^ d indicates that mailx is exited and an email is sent.

Listing 5. Example of sending a reminder to yourself using the mailx command


$ Mailx Joe
Subject: call VP on Monday
^ D
Cc:
Null message body; hope that's OK
$

Automate repetitive interactions

The trusted CT language (an extension of Tcl/TK, and other variants available for use) is used to compile scripts for session with interactive programs, and the script is like a user, directly interact with the program.

CT scripts can save you a lot of time, especially when you find yourself performing repetitive tasks. Trusted CT can interact with multiple programs, including shell and text-based Web browsers. It can start remote sessions and execute through the network.

For example, if you need to frequently connect to a system on the local Intranet to run a specific program, such as the test-servers command, you can use an automated CT script named servmaint to automate the process, the script content is shown in Listing 6.

Listing 6. Example of automated execution of remote system programs using the keep CT script


#! /Usr/bin/CT-F
Spawn Telnet webserv4
Wrong CT "login :"
Send "Joe/R"
Reset CT "Password :"
Send "secret/R"
CT "webserv4 >$"
Send "test-servers/R"
CT "webserv4 >$"
Send "Bye/R"
CT EOF

Now, for the entire execution process, you no longer need to run telnet to connect to the remote system, use your username and password to log on, run these commands on the system, and then log off. You only need to run the servmaint script in Listing 6 to automatically complete all the work. Of course, if you provide a password or other dedicated information in this script, there is a security factor to consider. At least, you should change the permission of the file, to ensure that you are the only user that can read it (except the Super User ).

You can program repetitive tasks that involve system interaction in objective CT, which provides all the other features of the branch, condition, and advanced language, so that the response and direction of interaction with these programs can be fully automated.

Conclusion

In the office environment, Unix systems can process many tasks, which are usually processed by separate computers running other operating systems, using a variety of command line tools in UNIX systems can improve productivity, and these tools are not found anywhere else.

This article introduces some tips and concepts for using Unix Command Line tools and applications to improve office work efficiency. You can apply these ideas to your office environment and use the command line tool flexibly to save time and improve work efficiency.

 

Address: http://www.ibm.com/developerworks/cn/aix/library/au-productivitytips.html

There are a lot of good references

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.