Export Linux Command Outputs to a File

Windows Articles

How To Install and Configure Master BIND DNS Server On Ubuntu 20.04

Today we are going to learn that how to install and configure Master BIND DNS server on Ubuntu 20.04. As you all know that...

Diskpart is a very useful tool for managing storage in Windows 10.

Hello! Diskpart is an internal tool included in Windows systems that allows you to manage storage units. Indeed, it is possible to manage internal...

How To Install MySQL 8.0 On Ubuntu 20.04

Today we are going to learn that how to Install MySQL 8.0 on Ubuntu 20.04. MySQL is one of the most popular and commonly...

How to Update to MIUI 12 via Fastboot

Greetings friends. The new version of the Android-based operating system MIUI 12 released this year, is still being deployed with some devices missing. On...

How to use modprobe command?

The modprobe command is a Linux administration system created for management, visualization, inclusion and exclusion. From loadable modules to kernel. Also, the Module is...

If you’re following OS Radar for quite a while, then you may already have noticed that lots of the posts tell about exporting the result to a text file. This is an awesome feature of Linux where you can export the output of a command to a file at your desired location.

It’s extremely useful in tons of cases. For example, you may end up with a very large output that’s giving you a hard time tracking on the terminal window. Or, you think that you need the information later on. Then, using this feature, you can save the output for later usage.

Today, we’ll dive deeper into the tricks.

Exporting output to a text file.

This is the most basic format of exporting output to a help file.

command > /file/path/command.txt

For example, let’s export the output of “help” command.

help

help > ~/Desktop/help.txt

Here, the “>” tells the terminal to export the output to somewhere else. This is the default behavior of the Bash shell. The output of “help” command is redirected to the “help.txt” file.

The file didn’t exist, so it will be created.

Selective export

It’s also possible to selectively export certain part of the output.

For example, when we shared the usage of “history” command in terminal, the entire list is pretty long! You can export the output with the above example with no problem.

Say, you only want to find out the commands you ran with “apt”. For that purpose, we shall be using “grep” – a handy search tool for the Linux environment.

For performing the task, the structure of the command will be something like this –

command | grep “search_term” > /file/path/command.txt

Now, let’s return to the scenario. Check out all the commands performed with “apt” –

history | grep apt

Export the result to a text file –

history | grep apt > ~/Desktop/apt_commands.txt

Multiple exports to a single file

Need to export all your command outputs into a single file? No need to worry.

The command structure will be –

command1 >> /file/path/command.file_extension

command2 >> /file/path/command.file_extension

command3 >> /file/path/command.file_extension

Let’s check out the following example –

lsb_release -a >> ~/Desktop/demo.txt

screenfetch >> ~/Desktop/demo.txt

neofetch >> ~/Desktop/demo.txt

Enjoy!

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How To Install and Configure Master BIND DNS Server On Ubuntu 20.04

Today we are going to learn that how to install and configure Master BIND DNS server on Ubuntu 20.04. As you all know that...

Diskpart is a very useful tool for managing storage in Windows 10.

Hello! Diskpart is an internal tool included in Windows systems that allows you to manage storage units. Indeed, it is possible to manage internal...

How To Install MySQL 8.0 On Ubuntu 20.04

Today we are going to learn that how to Install MySQL 8.0 on Ubuntu 20.04. MySQL is one of the most popular and commonly...

How to Update to MIUI 12 via Fastboot

Greetings friends. The new version of the Android-based operating system MIUI 12 released this year, is still being deployed with some devices missing. On...

How to use modprobe command?

The modprobe command is a Linux administration system created for management, visualization, inclusion and exclusion. From loadable modules to kernel. Also, the Module is...
x