I know that the builtin command ulimit is listed in the bash man page.

Grepping for it doesn't return anything though. Why?

grep and man both work fine, man bash | grep strings returns several matching lines.

I suspect it's something to do with bold text or similar, but I can't find the answer. The environment variable LANG=en_US.UTF-8.

(I'm trying this on the latest Mac OS X Snow Leopard, with Terminal.app, if that's important. My interactive shell is zsh.)

EDIT: GNU grep 2.5.1, man 1.6c.

  • 1
    MAN is an application. It opens the manual, and displays it. You can search with it, and there are other functionalities. Anyway, it displays NO output ... that's why you don't get anything when you try to grep it. * This would be an answer if I would find my account to the server to test ... :))) * – Apache Jun 28 '11 at 12:00
  • @Shiki: But it does display output. It's just written to pipe that output through $PAGER if the user doesn't redirect it elsewhere (if stdout is a tty, in technical terms). For example, man ... | cat works. – grawity Jun 28 '11 at 20:58

I don't have your environment so I cannot test. As a workaround you can pipe the output to a file and grep through that instead

man bash | col -bx > /tmp/bash.man
grep ulimit /tmp/bash.man
  • Thanks. That works, but it doesn't explain why grep can't match bold text in the man page. Of course, man bash | col -bx | grep ulimit works nicely now too, after the formatting from col. – Chris Poole Jun 28 '11 at 12:12
  • 1
    Actually, it does, if you think about what the -b option to col actually ends up doing in response to input sequences like u^Hul^Hli^Him^Hmi^Hit^Ht. – JdeBP Jun 28 '11 at 13:10
  • Yes, you're right. Many thanks! I ended up using your example to write a little function:help () { 3=${3:-'0'}; man $1 | col -bx | grep -A$3 $2 | more }. – Chris Poole Jun 28 '11 at 16:01
  • @Chris: ...have you tried the built-in command help ulimit? – grawity Jun 28 '11 at 20:59
  • 1
    @grawity I think help is bash-only; I use zsh interactively, which has no built-in help. – Chris Poole Jun 28 '11 at 21:39

I do not have a Mac, but on Ubuntu, the manual page is shown through the less program.

To search in a manual page, press / followed by the search term (ulimit). In a bash shell, you can run help ulimit to get help on ulimit.

I do not know why your grep does not filter ulimit out. ulimit is bold-faced in the manual page, perhaps that has something to do with it. Certain escape sequences are hidden, but do have an effect: it changes (background) color or changes the appearance (underlined, bold-faced).

From my bash (version 4.2.8):

ulimit: ulimit [-SHacdefilmnpqrstuvx] [limit]
  Modify shell resource limits.

  Provides control over the resources available to the shell and processes
  it creates, on systems that allow such control.

    -S        use the `soft' resource limit
    -H        use the `hard' resource limit
    -a        all current limits are reported
    -b        the socket buffer size
    -c        the maximum size of core files created
    -d        the maximum size of a process's data segment
    -e        the maximum scheduling priority (`nice')
    -f        the maximum size of files written by the shell and its children
    -i        the maximum number of pending signals
    -l        the maximum size a process may lock into memory
    -m        the maximum resident set size
    -n        the maximum number of open file descriptors
    -p        the pipe buffer size
    -q        the maximum number of bytes in POSIX message queues
    -r        the maximum real-time scheduling priority
    -s        the maximum stack size
    -t        the maximum amount of cpu time in seconds
    -u        the maximum number of user processes
    -v        the size of virtual memory
    -x        the maximum number of file locks

  If LIMIT is given, it is the new value of the specified resource; the
  special LIMIT values `soft', `hard', and `unlimited' stand for the
  current soft limit, the current hard limit, and no limit, respectively.
  Otherwise, the current value of the specified resource is printed.  If
  no option is given, then -f is assumed.

  Values are in 1024-byte increments, except for -t, which is in seconds,
  -p, which is in increments of 512 bytes, and -u, which is an unscaled
  number of processes.

  Exit Status:
  Returns success unless an invalid option is supplied or an error occurs.
  • 1
    I didn't realise man was being piped though a pager like less. It seems the same is so on the Mac: typing / while viewing the man page does let me find ulimit quickly. I had no idea you could do this! Thanks. Piping the manpage through col -bx strips enough to allow grep to find the text too. – Chris Poole Jun 28 '11 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.