How to stop displaying long long file list of `ls`?

19,585

Solution 1

If you are over SSH, you can use escape sequences. For example to send break, press:

enter, ~ and B

"enter" is of course not typed, just press the enter key (I suppose to "reset" the current command buffer)

Other interesting ones

Terminate time-outing session

enter, ~ and .

Send escape character

enter, ~ and ~

You can list these commands with

enter, ~ and ?

On my system the above prints:

# ~?
Supported escape sequences:
  ~.  - terminate connection (and any multiplexed sessions)
  ~B  - send a BREAK to the remote system
  ~C  - open a command line
  ~R  - Request rekey (SSH protocol 2 only)
  ~^Z - suspend ssh
  ~#  - list forwarded connections
  ~&  - background ssh (when waiting for connections to terminate)
  ~?  - this message
  ~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

Solution 2

You can control the ls output by using less or more command, like below:

ls | more
ls | less

They'll work on interactive way. Or you can truncate output with head or tail command, like:

ls | head
ls | tail

head will show default 10 lines from head and tail will show default 10 lines from tail.

Solution 3

You can stop the output by pressing Ctrl + C (like it's the case with most programs inside the linux shell).

Edit: Just read that Ctrl + C is not working. I think simply opening a new console using Alt + F2 doesn't work with Putty either. Then just close the putty window and open a new one. With that, you can kill the process.

To read the output I would suggest using ls | less or pipe the output to a file and then read it ( ls > filelist.txt ).

Share:
19,585
Freewind
Author by

Freewind

A programmer ([email protected])

Updated on July 25, 2022

Comments

  • Freewind
    Freewind almost 2 years

    There is a big directory which contains 100k files on the remote server, and I typed command: ls in my putty.

    It starts to display a very long file list, and seems never end.

    How to stop it, without closing the putty program?

  • c00kiemon5ter
    c00kiemon5ter over 10 years
    another fun thing: vim /path/to/dir (assuming vim is installed)
  • rakib_
    rakib_ over 10 years
    ya, that could an way too! ;-)
  • Buttle Butkus
    Buttle Butkus over 8 years
    It doesn't seem to work on my CentOS 6. I am using AlphaCom, not putty. But I don't think that should matter.
  • alper
    alper almost 3 years
    Can ls be smart apply ls | more if output length is over 200, and do ls | head if output size if pretty small <20
  • Eric Tobias
    Eric Tobias over 2 years
    Also woks well with tree.