Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward bash colors

Is there any way to export the colors of an output of a command?

Let's explain it with a small example:

ls -alh --color=auto

will print the colored contents of the directory, while

ls -alh --color=auto | cat

won't print some color. What I want to know is a trick or a tool, let's call it magic, that restores these commands like \033[1m, so that colors are available for latter processing:

ls -alh --color=auto | magic | cat

or

ls -alh --color=auto | magic >> file

Update:
I'm using ls just for this example, but want to know whether there is a general possibility.

like image 781
binfalse Avatar asked Jul 02 '26 03:07

binfalse


1 Answers

script outputfile command 

will do the trick. e.g:

script capture.txt ls --color=always
like image 158
Ramon Poca Avatar answered Jul 03 '26 18:07

Ramon Poca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!