LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 12-10-2018, 01:15 PM   #1
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Rep: Reputation: Disabled
Trying to get colored output with ls on openBSD 6.4


Hello,

I have openBSD 6.4 installed on a VM which I've been using in an attempt to learn how to get file shares running on openBSD.

Quite frankly, I've taken for granted how colors pertaining to file type when ls is invoked or having aliases for lengthy commands is done in Linux.

In an attempt to get the same thing on openBSD, I went ahead and installed bash on my system.

I also changed my default shell to bash. I can only confirm this as whenever I logon now, I get bash instead openBSD's default.

When I echo $SHELL, I get the following path: /usr/local/bin/bash

When I echo $BASH_VERSION, I get 4.4.23(1)-Release

Under my home directory, I find the following files & folders:
Code:
.Xdefaults
.bash_history
.config
.cshrc
.cvsrc
.login
.mailrc
.profile
.ssh
.viminfo
mbox
Aside from the one's listed in blue, all other objects are files.

I've tried to see if there was a bashrc file anywhere but I don't know if that's the right file I should be editing now. I read somewhere that I could get what I'm asking for from other files, such as .bash_profile or even .profile.

I honestly don't know where to look at this point as I'm pretty new to BSD in general and I've never had to do this before on a Linux host.

Could I get some assistance?

TIA

EDIT:
I'm trying to get colors to function under the terminal (by that, I mean I want colored output). I already see color in instances where man is invoked and a man page is displayed. What I would like next is to see the colors I normally see when I invoke ls. On all Linux machines I've used in the past, I was able to run ls and the color scheme would be generated automatically. I don't know how to enable that same feature with ls on openBSD. I'm looking to achieve that, and my guess is to edit some config file, but I don't know if that's true.

EDIT #2:
This is all being done on an openBSD guest machine run via virtualbox. I am not trying to get this on a Linux machine 'cause I don't have to.

Last edited by That Random Guy; 12-11-2018 at 08:25 AM. Reason: title;edit
 
Old 12-10-2018, 05:49 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,056

Rep: Reputation: Disabled
The files you mention (.bash_profile, .profile, you can add .bsh_aliases and .bashrc) are optional and generally written by the user.
Try this command to know more:
man bash
Aldo, you could read http://tldp.org/LDP/Bash-Beginners-G...ers-Guide.html (old, but mostly still valid).

Last edited by Didier Spaier; 12-10-2018 at 05:52 PM.
 
Old 12-10-2018, 08:11 PM   #3
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by That Random Guy View Post
I've tried to see if there was a bashrc file anywhere but I don't know if that's the right file I should be editing now.
The environment variable for enabling colors is LS_OPTIONS, with LS_COLORS giving what colors to use for which files.
They are normally set by a program 'dircolors', which in _MY_ system is invoked by a script in the /etc/profile.d directory (all of the .sh scripts in that directory are executed by /etc/profile), but you can create your own /etc/profile.d/dircolors.sh (or any other name with the .sh extension) to set those variables AND create aliases for 'ls' with the $LS_OPTIONS added/
Again, mine is:
Code:
/bin/ls --color=auto -T 0
but I changed it from the dircolors default one.
 
1 members found this post helpful.
Old 12-11-2018, 01:57 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
That Random Guy, what is the problem?
i cannot make out a clear question in your op.
 
Old 12-11-2018, 04:22 AM   #5
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Quote:
Originally Posted by That Random Guy View Post
Quite frankly, I've taken for granted how colors pertaining to file type when ls is invoked or having aliases for lengthy commands is done in Linux.
As I understand it, it's GNU coreutils ls(1) which has the this colorisation feature. As far as I know, it has nothing to do with the shell and is not configured in ~/.profile or anything similar. OpenBSD's ls(1) does not have this.

Install the coreutils package and you will be able to use the GNU ls ( gls(1) ) which supports this feature. Refer to the man page.

You can then alias it as your ls(1) command.

Quote:
Originally Posted by That Random Guy View Post
I also changed my default shell to bash. I can only confirm this as whenever I logon now, I get bash instead openBSD's default.

When I echo $SHELL, I get the following path: /usr/local/bin/bash

When I echo $BASH_VERSION, I get 4.4.23(1)-Release
Be aware that changing your default shell to a shell which is installed from ports rather than the ksh(1) shell in base, could result in some breakage if the shell is removed. It's not a huge problem for a user account shell, but certainly do not change root's shell.

Last edited by cynwulf; 12-11-2018 at 04:24 AM.
 
Old 12-11-2018, 04:55 AM   #6
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Quote:
I read somewhere that I could get what I'm asking for from other files, such as .bash_profile or even .profile.
Here is a list and an explanation about the files which configure the way bash acts:
http://mywiki.wooledge.org/DotFiles?...=%28profile%29
Quite some linux distributions come with a lot of configurations out of box, debian even autocreates .profile and .bashrc (also very complex ones) in the users home directory.
I sometimes copy them to distros or OS'es where i ain't got them.

In general i think you are asking about what ehartman said.

As cynwulf said you can't expect a different flavor of commands, though with the same name, to always work the exact same way (in this case the command "ls"). Always make sure the according manpage confirms what you know from Gnu/Linux.

Though it really ain't that clear what exactly your problem is (as ondoho said too).
 
Old 12-11-2018, 08:17 AM   #7
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
LS colors

Quote:
Originally Posted by ondoho View Post
That Random Guy, what is the problem?
i cannot make out a clear question in your op.
I'm trying to get colored output for the ls command on openBSD as it is enabled by default on almost every Linux distro I can think of.

I initially also needed help with aliases but after playing with the .profile file, I was able to get that going.

I edited my OP so that others understand better as well. It was kind of vague.
 
Old 12-11-2018, 08:29 AM   #8
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
Yep

Quote:
Originally Posted by Didier Spaier View Post
The files you mention (.bash_profile, .profile, you can add .bsh_aliases and .bashrc) are optional and generally written by the user.
Try this command to know more:
man bash
Aldo, you could read http://tldp.org/LDP/Bash-Beginners-G...ers-Guide.html (old, but mostly still valid).
I already looked through the man page for bash and its related pages as well. Didn't see anything there that would help--and if there was, it wasn't clear enough.
 
Old 12-11-2018, 08:31 AM   #9
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
Yikes!

Quote:
Originally Posted by cynwulf View Post
As I understand it, it's GNU coreutils ls(1) which has the this colorisation feature. As far as I know, it has nothing to do with the shell and is not configured in ~/.profile or anything similar. OpenBSD's ls(1) does not have this.

Install the coreutils package and you will be able to use the GNU ls ( gls(1) ) which supports this feature. Refer to the man page.

You can then alias it as your ls(1) command.


Be aware that changing your default shell to a shell which is installed from ports rather than the ksh(1) shell in base, could result in some breakage if the shell is removed. It's not a huge problem for a user account shell, but certainly do not change root's shell.
I better change that now then. Thanks for the tip!
 
Old 12-11-2018, 08:51 AM   #10
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Quote:
Originally Posted by That Random Guy View Post
I'm trying to get colored output for the ls command on openBSD as it is enabled by default on almost every Linux distro I can think of.
As OpenBSD is not GNU or Linux and OpenBSD's ls(1) command is not the same as the GNU ls(1) command, you will not get the colourisation.

As I've said above, you will need to install coreutils from ports and use the GNU gls(1) command to get the colorised output (just tested and works).
 
Old 12-11-2018, 09:55 AM   #11
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
Yep

Quote:
Originally Posted by cynwulf View Post
As OpenBSD is not GNU or Linux and OpenBSD's ls(1) command is not the same as the GNU ls(1) command, you will not get the colourisation.

As I've said above, you will need to install coreutils from ports and use the GNU gls(1) command to get the colorised output (just tested and works).
Yep, and I understood that. I already had coreutils installed but wasn't aware of the differences between the distinct ls utils.

I was able to get an alias going for gls, but it doesn't seem to be working (i.e. colored output; the command does run). I'm thinking there's something else I haven't configured right, which would explain why even colorls wasn't showing colors when invoked.

I'll have to investigate some more.
 
Old 12-11-2018, 10:12 AM   #12
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
It worked here. Can you post the exact alias you used?
 
Old 12-11-2018, 11:51 AM   #13
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
!

Quote:
Originally Posted by cynwulf View Post
It worked here. Can you post the exact alias you used?
I will list the contents of my .profile file below:

Code:
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:.

alias ls='gls'
alias la='ls -la'
alias cls='clear'
I can confirm that the aliases are being applied because I have run cls and it has worked. I have also run ls with the --color=auto option, which I think would otherwise fail with the BSD port.

According to the man page, it's assumed to leave color on always by default. So, I tried without the color option and also setting it to always.

Incidentally, I'm running this machine as a guest on Virtualbox. I don't know if that would have anything to do with it, though.
 
Old 12-11-2018, 04:44 PM   #14
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by That Random Guy View Post
alias ls='gls'
That should be
Code:
alias ls='gls --color=auto'
and the LS_COLORS environment variable should be set in your system.

color=auto means: use color on an interactive terminal but NOT when ls is used within a script, crontab etc as the colors may disturb further processing (like in a ls|grep pipe).
See the man page of the GNU version of ls about using colors.
Note that displaying colors is DISabled by default so you do need to use the --colors option (with a value other then 'never').
 
Old 12-11-2018, 07:11 PM   #15
That Random Guy
Member
 
Registered: Jun 2017
Posts: 81

Original Poster
Rep: Reputation: Disabled
Got it

Quote:
Originally Posted by ehartman View Post
That should be
Code:
alias ls='gls --color=auto'
and the LS_COLORS environment variable should be set in your system.

color=auto means: use color on an interactive terminal but NOT when ls is used within a script, crontab etc as the colors may disturb further processing (like in a ls|grep pipe).
See the man page of the GNU version of ls about using colors.
Note that displaying colors is DISabled by default so you do need to use the --colors option (with a value other then 'never').
I forgot to read that part in the man page—but after some trifle and a few Google searches, I was able to get it working.

It turns out my TERM variable wasn't one that supported colorization as prescribed in the dircolors man page. After changing that, and running gdircolors -b (and editing my profile), I've now received colored output when invoking ls.

What I need to figure out now is how to make the TERM change permanent. So far, I've only been able to do that via export TERM=vt100.

In any case, I'm marking this thread as solved.
 
  


Reply

Tags
bash, openbsd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/bashrc ,dircolors and /root/.bash_profile ,/.bashrc not exist in LFS-7.5(sec9.3) jaassi Linux From Scratch 2 09-20-2014 05:04 PM
~/.bashrc, /etc/bash.bashrc files not read? Tachtory Slackware 3 01-04-2014 12:25 AM
[SOLVED] How to use my /home/kangjoo/.bashrc rather than root/.bashrc kangjoo.lee Linux - Newbie 2 11-05-2012 03:38 PM
.bashrc / .bash_profile /etc/profile /etc/bashrc deadeyes Red Hat 2 02-13-2010 11:22 AM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 10:59 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 12:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration