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.
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 #22&
: file named 2
, command run in the backgroundFor more information see the REDIRECTION
section of man bash
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.
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>2&
redirects stdout to a file named2
and puts the command in the background; you probably (or at least should have) learned2>&1
man $command
, egman fg
yields this man fg page.