automatically quit less after a short time

k-h

I use less to view the text output of a command that has sensitive information. Less is good for this as it uses an alternate screen and wipes it after use. I'd like the less session to quit after a short time, like say 5 minutes.

Is there any simple command line way to invoke less with piped text and have it quit automatically after say 5 minutes?

Fox

Assuming you have GNU coreutils, a somewhat simple approach is to replace less with timeout --foreground 600 less; printf '\033[?47h'; clear; printf '\033[?1049l'; stty cooked echo in such sensitive commands. The timeout command kills a process after a given duration, the --foreground switch allows less to use the TTY, and stty cooked echo fixes the terminal after killing less. In case killing less prevented the clear and exit of the alternate screen, the intervening commands do that.

The escape sequences used in the printf commands are appropriate for a DEC-compatible terminal (emulator) such as Xterm. Your specific terminal may use different sequences to accomplish this task.

A simple function:

tless () {
  timeout --foreground 600 less "$@"
  printf '\033[?47h' # Enter alternate screen
  clear
  printf '\033[?1049l' # Exit alternate screen and restore cursor
  </dev/tty stty cooked echo # Use in a pipe requires specifying the TTY
}

can make for substantially less typing.


Thanks @meuh for pointing out that the original version might not clear or exit the alternate screen.

Edited to allow tless some-file. Further, this version has been tested on Linux and Solaris 11.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to prevent the q will be uppercase automatically while try to quit vim?

분류에서Dev

How to prevent the q will be uppercase automatically while try to quit vim?

분류에서Dev

Automatically set an updatedAt time on a record

분류에서Dev

Start nginx after reboot automatically

분류에서Dev

Using xmodmap automatically after login

분류에서Dev

Hide time in transaction mails with {{var order.getCreatedAtFormated(''short'')}}

분류에서Dev

Jssor Slider: Captions overlap for a short time before slideshow starts

분류에서Dev

Restore clock after short powerdown for no-network, no-RTC system

분류에서Dev

start openvpn client automatically at certain time?

분류에서Dev

Dropbox service not starting automatically after kernel upgrade

분류에서Dev

Conky does not starting automatically after boot

분류에서Dev

How to automatically restart a program after it's closed

분류에서Dev

How to launch browser automatically after war deployment?

분류에서Dev

Computer automatically shutdown shortly after power on

분류에서Dev

Less output does not show output in terminal after quitting it

분류에서Dev

How to make LESS 'remember' search patterns after I close it?

분류에서Dev

Automatically get the time taking day light saving hours into account

분류에서Dev

How can I automatically invoke a servlet periodically at specified time intervals

분류에서Dev

Unity greeter background not changing for users automatically after upgrade

분류에서Dev

How to automatically execute a command in a terminal after a period without activity?

분류에서Dev

Setup gitlab-runner to run automatically after git push?

분류에서Dev

IdentityServer4 automatically logout after 30 minutes

분류에서Dev

How to send message after NSArrayController did automatically rearrange it's objects?

분류에서Dev

Automatically execute code before and after running any procedure

분류에서Dev

Why is Terminal automatically executing my command after pasting text?

분류에서Dev

"Message Queue service is not available" when service automatically starts after reboot

분류에서Dev

Automatically remove source files after collectstatic with django-pipeline

분류에서Dev

How to automatically force fsck disks after crash in `systemd`?

분류에서Dev

-bash: /bin/cd: No such file or directory - automatically execute ls after cd

Related 관련 기사

  1. 1

    How to prevent the q will be uppercase automatically while try to quit vim?

  2. 2

    How to prevent the q will be uppercase automatically while try to quit vim?

  3. 3

    Automatically set an updatedAt time on a record

  4. 4

    Start nginx after reboot automatically

  5. 5

    Using xmodmap automatically after login

  6. 6

    Hide time in transaction mails with {{var order.getCreatedAtFormated(''short'')}}

  7. 7

    Jssor Slider: Captions overlap for a short time before slideshow starts

  8. 8

    Restore clock after short powerdown for no-network, no-RTC system

  9. 9

    start openvpn client automatically at certain time?

  10. 10

    Dropbox service not starting automatically after kernel upgrade

  11. 11

    Conky does not starting automatically after boot

  12. 12

    How to automatically restart a program after it's closed

  13. 13

    How to launch browser automatically after war deployment?

  14. 14

    Computer automatically shutdown shortly after power on

  15. 15

    Less output does not show output in terminal after quitting it

  16. 16

    How to make LESS 'remember' search patterns after I close it?

  17. 17

    Automatically get the time taking day light saving hours into account

  18. 18

    How can I automatically invoke a servlet periodically at specified time intervals

  19. 19

    Unity greeter background not changing for users automatically after upgrade

  20. 20

    How to automatically execute a command in a terminal after a period without activity?

  21. 21

    Setup gitlab-runner to run automatically after git push?

  22. 22

    IdentityServer4 automatically logout after 30 minutes

  23. 23

    How to send message after NSArrayController did automatically rearrange it's objects?

  24. 24

    Automatically execute code before and after running any procedure

  25. 25

    Why is Terminal automatically executing my command after pasting text?

  26. 26

    "Message Queue service is not available" when service automatically starts after reboot

  27. 27

    Automatically remove source files after collectstatic with django-pipeline

  28. 28

    How to automatically force fsck disks after crash in `systemd`?

  29. 29

    -bash: /bin/cd: No such file or directory - automatically execute ls after cd

뜨겁다태그

보관