Export Linux Command Outputs to a File

Windows Articles

How to install NetBeans on Windows 10

Hi! Today we're going to talk a little about Netbeans. This is an integrated development environment that allows programming in various languages....

How to install Atom Text Editor on Ubuntu 20.04?

It is often said that the process of software development is complex. And this is true, therefore it is required to use...

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools 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 NetBeans on Windows 10

Hi! Today we're going to talk a little about Netbeans. This is an integrated development environment that allows programming in various languages....

How to install Atom Text Editor on Ubuntu 20.04?

It is often said that the process of software development is complex. And this is true, therefore it is required to use...

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...