input.txt is ISO-8859-1; convert it to UTF-8 and save output.txt.
Which command is appropriate?
iconv uses -f for the source encoding and -t for the target, then writes converted output to standard output.
Detailed explanation
iconv -f UTF-8 -t ISO-8859-1 input.txt > output.txtIncorrect. The source and target encodings are reversed.
Incorrect. The source and target encodings are reversed.
iconv -f ISO-8859-1 -t UTF-8 input.txt > output.txtCorrect. It converts from ISO-8859-1 to UTF-8 and redirects the result.
Correct. It converts from ISO-8859-1 to UTF-8 and redirects the result.
iconv -f ISO-8859-1 input.txt output.txtIncorrect. The output file is not specified in this positional form.
Incorrect. The output file is not specified in this positional form.
locale -t UTF-8 input.txt > output.txtIncorrect. locale is not a text conversion command.
Incorrect. locale is not a text conversion command.
Try it yourself
An example you can run in a temporary verification environment.
printf '\351\n' | iconv -f ISO-8859-1 -t UTF-8 | od -An -t x1Expected result
c3 a9 0aKey points
- -f is from
- -t is to
- Output can be redirected
Notes
- Environment: GNU libiconv互換iconv / 合成1文字
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.