Question 3.27: You want to quickly create a file with some text, or record ......

You want to quickly create a file with some text, or record a directory listing into a file.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

Use the > command to redirect output that would otherwise appear on the command line.

For example, to copy a directory listing into a file called myfiles.txt, do the following:

$ ls > myfiles.txt
$ more myfiles.txt
Desktop
indiecity
master.zip
mcpi

Discussion

You can use the > command on any Linux command that produces output, even if you are running, say, a Python program.

You can also use the opposite < command to redirect user input, although this is not nearly as useful as >.

See Also

To use > to join together a number of files, see Recipe 3.28.

Related Answered Questions

Question: 3.34

Verified Answer:

Use the Linux df command: $ df -h Filesystem   ...
Question: 3.33

Verified Answer:

Use the Linux date command. The date and time form...
Question: 3.32

Verified Answer:

Edit the file ~/.bashrc using nano (Recipe 3.6), a...
Question: 3.31

Verified Answer:

Run the program or command in the background using...
Question: 3.30

Verified Answer:

Redirect the output to /dev/null using >. For e...
Question: 3.24

Verified Answer:

Use the Task Manager utility, which you’ll find on...
Question: 3.29

Verified Answer:

Use the pipe command, which is the bar symbol (|) ...
Question: 3.28

Verified Answer:

Use the cat command to concatenate a number of fil...
Question: 3.26

Verified Answer:

Use the lsusb command. This will list all the devi...
Question: 3.25

Verified Answer:

Depending on the file type, you will need to use t...