Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Rep:
On FreeBSD, ls shows colors if the CLICOLOR environment variable is set or if -G is passed on the command line. The actual colors are configured through the LSCOLORS environment variable. For example to show directories in light blue, use :-
Code:
export LSCOLORS=Exfxcxdxbxegedabagacad
Here e means dark blue, E means light blue, x means default, f in the third position makes symbolic links magenta, and so on.
With GNU ls, e.g. on Linux, ls shows colors if --color is passed on the command line. The actual colors are configured through the LS_COLORS environment variable, which can be set with the dircolors command.....
From:
man ls
Using color to distinguish file types is disabled both by default and with --color=never.
With --color=auto, ls emits color codes only when standard output is connected to a terminal.
The LS_COLORS environment variable can change the settings. Use the dircolors command to set
it.
from:
info coreutils 'ls invocation'
(1) If you use a non-POSIX locale (e.g., by setting `LC_ALL' to `en_US'), then `ls' may produce output that is sorted differently than you're accustomed to. In that case, set the `LC_ALL' environment variable to `C'.
LS_COLORS; if enabled will be an environment variable.
At the prompt type `set`
the screen will fill with information and if set,LS_COLORS will be shown and any parameters will be obvious. The colors and other variables and information concerning colors will be found in /etc/DIR_COLORS if the file exists.
Then, lisle2011, according to your post, LS_COLORS and LC_ALL are the only two possible environment varibles than can affect ls. My question is in connection with the following: suppose I have
alias v='/bin/ls $LS_OPTIONS --format=long -h'
where I have
$ echo $LS_OPTIONS
$ -F -b -T 0 --color=auto
Now, I can issue
$ v -a
and the -a option will be added to those options already contained in v. v is a comfortable alias for my personal use. But once in a while I want to have the same kind of output given by v but without the -h option. Is it possible to temporarily dissable the -h option?
I think it's impossible except for the following workaround:
to have a script with a very short name that sets LS_OPTION to one of two predetermined sets of options.
EDIT:
A solution: v --block-size=1. --block-size=1 will override -h in v. The only drawback is that "--block-size=1" is 14 characters long, 14 characters to type.
I have not tried it, so all I can say is that once an option is included in an alias you are stuck with it. This may not be true. But one also cannot invent options for command line programs. It seems a lot of work to make an alias then not want to have all the options included. My only suggestion would be a second alias that did not include the -h option.
ls -alh would work for me anyway. Or conversely ls -al.
In some OSs options to some commands can be both asserted or negated. For example, MS-DOS, DIR command. Here you can set a collection of switches (options) as default and, when issuing the command, negate one or more of the options in the collection.
LC_ALL overides every other environment variable starting with LS_. Read about LS_ and LS_ALL yourself in your documentation. LC_ALL is not specific to ls but will affect how the listing is shown depending on locale.
To solve your problem you should turn your alias into a script and put that script in your PATH. Exclude the -h from the script but put some scripting in so that it works like this:
scriptname alone will not use the human readable option
scriptname -h will use the human readable option.
You can unalias v and name your script v so the result is:
v - gives you a listing without human readable option
v -h will give you what you have now.
This based on the assumption that you can write a script. It needs to be only very simple. If you cannot manage it I'll help you.
Negating an option using ls is not possible except as I have illustrated above.
Last edited by lisle2011; 03-07-2012 at 12:51 PM.
Reason: letter replacement
I re-read one of your previous responses and you mentioned 14 letters being too many to type. If you wish to learn to use bash and the command line typing is a part of it. So just get used to having to type.
here is my solution for you, you can edit this file how you like.
touch v
chmod 0744 v
vim v
Paste this code into v
Code:
#!/bin/bash
# You do not need to put $LS_OPTIONS in the command string as it is already an environmental variable that has been set.
# For just one command line option you need only use $1
echo '/bin/ls -l $1'
/bin/ls -l $1
I only put the echo in so you could visualize. You can comment it out. If you want more options add more variables $2, $3, $4, etc. If only one option is on the command line the others will be ignored.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.