Export Linux Command Outputs to a File

Windows Articles

How to install Screaming Frog SEO Spider on Ubuntu 20.04 / 18.04?

If you are working with blogs and content creation then you should know about SEO. Or in the best case, you have...

How to Configure a Firewall in Ubuntu 20.04 / Debian 10?

There is nothing safe from hackers on the Internet, however, we can implement security measures to be more protected against an attack. With this...

Gnome 3.38 available

Gnome OS is a Linux-based operating system, which has a huge domain in the Linux forums. On September 16, 2020, developers announced...

NVIDIA acquires ARM for $40 billion

Various rumors of an agreement between NVIDIA and SoftBank to acquire Arm. Where NVIDIA announces that they reached an agreement to buy...

How to install CodoForum on Ubuntu 20.04 / Debian 10?

Hi, folks. In this post, I will show you how to install CodoForum in Ubuntu 20.04 /Debian 10. This program is quite useful to...

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 Screaming Frog SEO Spider on Ubuntu 20.04 / 18.04?

If you are working with blogs and content creation then you should know about SEO. Or in the best case, you have...

How to Configure a Firewall in Ubuntu 20.04 / Debian 10?

There is nothing safe from hackers on the Internet, however, we can implement security measures to be more protected against an attack. With this...

Gnome 3.38 available

Gnome OS is a Linux-based operating system, which has a huge domain in the Linux forums. On September 16, 2020, developers announced...

NVIDIA acquires ARM for $40 billion

Various rumors of an agreement between NVIDIA and SoftBank to acquire Arm. Where NVIDIA announces that they reached an agreement to buy...

How to install CodoForum on Ubuntu 20.04 / Debian 10?

Hi, folks. In this post, I will show you how to install CodoForum in Ubuntu 20.04 /Debian 10. This program is quite useful to...
x