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.
αғsнιη
  • 35,092
  • 41
  • 129
  • 192
coding_ninza
  • 462
  • 2
  • 7
  • 17
  • `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` – steeldriver Jan 12 '18 at 13:22
  • I didn't understand please explain it clearly – coding_ninza Jan 12 '18 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" – coding_ninza Jan 12 '18 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 '18 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](https://docs.oracle.com/cd/E19455-01/806-0624/6j9vek556/index.html) page. – pbhj Jan 12 '18 at 14:30
  • You might want to read [How can I get help on terminal commands?](https://askubuntu.com/q/991946/507051) to get to know what alternatives there are to `man` and when you can (or should) use them. – dessert Jan 13 '18 at 23:13

2 Answers2

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

steeldriver
  • 131,985
  • 21
  • 239
  • 326
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.

John1024
  • 13,539
  • 42
  • 51
  • 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 '18 at 13:30