1

I have learned that fg %N means "go to task N"

I don't understand this command or how to use it. I have tried to see the manual entry of this command in the terminal, but that didn't work:

$ man fg
No manual entry for fg.
6
  • 1>2& redirects stdout to a file named 2 and puts the command in the background; you probably (or at least should have) learned 2>&1 Jan 12, 2018 at 13:22
  • I didn't understand please explain it clearly Jan 12, 2018 at 13:25
  • In my first question that is that is 1>2& - I didn't understand the meaning of this line " Redirect stdout to stderr" Jan 12, 2018 at 13:32
  • Since someone answered your question, I removed one of the questions. If you still need help with the question I removed, please ask a separate question
    – Zanna
    Jan 12, 2018 at 13:32
  • If you don't have a manpage you can usually find one by googling man $command, eg man fg yields this man fg page.
    – pbhj
    Jan 12, 2018 at 14:30

2 Answers 2

9

Second one first: fg is a bash shell built-in command and as such you need to refer to the man page for bash. In particular, the section JOB CONTROL says

   Simply naming a job can be used to bring it into the foreground: %1  is
   a  synonym  for  ``fg %1'', bringing job 1 from the background into the
   foreground.  Similarly, ``%1 &''  resumes  job  1  in  the  background,
   equivalent to ``bg %1''.

Alternatively, you can use the shell's interactive help system:

$ help fg
fg: fg [job_spec]
    Move job to the foreground.

    Place the job identified by JOB_SPEC in the foreground, making it the
    current job.  If JOB_SPEC is not present, the shell's notion of the
    current job is used.

    Exit Status:
    Status of command placed in foreground, or failure if an error occurs.

Now for the first part. The actual command you stated does not in fact redirect stdout to stderr: it redirects stdout to a file named 2 and then puts the whole command into the shell's background. Hence

$ man 1>2&
[1] 4662

runs man in the background (as job [1], with process ID 4662) - if you look in the current directory you will likely find a file called 2 with contents

 What manual page do you want?

The command you should have used is 1>&2

  • &2 : file descriptor #2
  • 2& : file named 2, command run in the background

For more information see the REDIRECTION section of man bash

8
  1. fg is a bash builtin command:

    $ type fg
    fg is a shell builtin
    

    To get information on individual bash commands, use help:

    $ help fg
    fg: fg [job_spec]
        Move job to the foreground.
    
        Place the job identified by JOB_SPEC in the foreground, making it the
        current job.  If JOB_SPEC is not present, the shell's notion of the
        current job is used.
    
        Exit Status:
        Status of command placed in foreground, or failure if an error occurs.
    
  2. As mentioned in the first version of the question, 1>&2 is an example of redirection. To read about redirection, run man bash and go to the section entitled REDIRECTION.

1
  • Since you've answered, I'm going to remove the part about redirection from the question and retract my close vote (I've done it, so you may want to remove your part 2. unless you disagree with my action D: )
    – Zanna
    Jan 12, 2018 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .