All Tips


7

Tip #534   Adding times to the history

Typically when one types the history command, it displays the command number and the command. For auditing purposes it would be helpful to display the timestamp as well. To do so we need to set the environmental variable HISTTIMEFORMAT.

HISTTIMEFORMAT supports format strings of strftime.

Some important format strings:

%T Replaced by the time ( %H : %M : %S )
%F Equivalent to %Y - %m - %d

Read more »

5

Tip #533   User input timeout

In bash scripting if you have a situation where you don't want to wait forever for a user to respond, you can use the read command with the -t option which causes read to time out in "number of seconds" specified.

From read command man page:

-t timeout : Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe.

-p prompt : Display prompt, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.

Example:
Read more »

5

Tip #532   Kill the process locking a file

If you're having problems unmounting a volume or other situations where a process accessing a file can stop you, the following will kill the process accessing 'filename'.

Read more »

3

Tip #528   Top ten running processes

Display the top ten running processes - sorted by memory usage

ps aux | sort -nk +4 | tail

ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT. Read more »

7

Tip #527   Fix a borked terminal

If you bork your terminal by sending binary data to STDOUT or similar, you can get your terminal back using the reset command rather than killing and restarting the session. Just type 'reset' at the command line (note that you often won't be able to see the characters as you type them). Read more »
  • TAGS:

3

Tip #525   Find words in garbled text

Have a bunch of garbled text? Curious as to what words might be found inside? Try the following:

Read more »