LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-12-2013, 10:49 AM   #1
Jeff9
Member
 
Registered: Jun 2013
Posts: 36

Rep: Reputation: Disabled
How do you turn off an option in an alias?


I don't care for the default linux file listing. So I made an alias in my .bashrc (or maybe .bash_profile - one of those two), like this

Code:
> alias ls
alias ls='ls -al -p --color=always --group-directories-first'
This gives me the files' date and size along with the name.

But now I want to list just the files, nothing, and one per line. That is, if I didn't have the alias, I'd want to do ls -1.

But when I try that, I get my standard listing. Obviously the -al and -p options are still in effect. How would I turn those options off temporarily?
 
Old 08-12-2013, 12:01 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
much of what you are doing is 'redundant'

assuming your dircolors is setup correctly the colour should indicate a directory
also with -l the permissions field will indicate directory ( have a d in it ) so do you really need the trailing / to also indicate dir?

personally I have
Code:
alias ls='ls --color=auto'
and I just add what I need when I need it
but it is common to setup other aliases
Code:
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
so you could have
Code:
alias ls='ls --color=auto'
alias ls='l1 -1'

A more direct answer,
Code:
function ls () { /bin/ls -1 $@; }
when done with your temporary ls
Code:
unset ls
but is it 'worth it'?

edit: actually, that doesn’t work...

you could have separate 'source' alias files
Code:
cat > ~/.bashrc_lsAll << "EOF"
alias ls='ls -al -p --color=always --group-directories-first'
EOF
cat > ~/.bashrc_lsOne  << "EOF"
alias ls='ls -1 --color=always'
EOF
and 'source' those with

Code:
source ~/.bashrc_lsOne
# or
. ~/.bashrc_lsOne
When done, go back to
Code:
. ~/.bashrc_lsAll
# or even
. ~/.profile # but that will 'reset' everything you have setup in that shell session
if you ask me, it is simply not worth it


I just add what I need, when I need it, on the command line.

you may also like to use --color=auto instead of always, that will save you some pain if you want to pipe your output through other programs such as grep, sed, awk or into a text file.

Last edited by Firerat; 08-12-2013 at 12:16 PM.
 
Old 08-12-2013, 12:50 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
If you don't want your alias come into effect you can simply invoke the command with its full path, for example
Code:
/bin/ls -1
Alternatively, precede the command with a backslash, like
Code:
\ls -1
 
3 members found this post helpful.
Old 08-12-2013, 12:56 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by TobiSGD View Post
Alternatively, precede the command with a backslash, like
Code:
\ls -1
nice, didn't know about the backslash..
 
Old 08-12-2013, 01:20 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
why dont you just rename the alias ?
 
Old 08-12-2013, 01:24 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
You can always 'unalias' it. Or you can tmp login to a subshell without aliases.
 
Old 08-12-2013, 01:42 PM   #7
Jeff9
Member
 
Registered: Jun 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
...
I just add what I need, when I need it, on the command line.

you may also like to use --color=auto instead of always, that will save you some pain if you want to pipe your output through other programs such as grep, sed, awk or into a text file.
Thanks for the tips. I'll use some of them (well, not the one you crossed out!).

I have the trailing slash on the directories so that I can pull out directories only from long file listings with ls | grep "^d". But I also like them colored so that I can identify them in shorter listings (and on top, where they belong! ).

---------- Post added 08-12-13 at 01:42 PM ----------

Quote:
Originally Posted by TobiSGD View Post
If you don't want your alias come into effect you can simply invoke the command with its full path, for example
Code:
/bin/ls -1
Alternatively, precede the command with a backslash, like
Code:
\ls -1
What Firerat said.
 
Old 08-12-2013, 01:49 PM   #8
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,163
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
Code:
type ls
ls is aliased to `ls --color=auto'
escaping with "\" works as does unalias <suspected_alias>
Code:
bash --norc
caused one on another host to 'default' to
Code:
ls is /bin/ls
or....
Code:
alias ls=<enter>
"works" until you re-source, or re-bash, or logout|in.

HTH.
 
Old 08-12-2013, 02:01 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by Jeff9 View Post
Thanks for the tips. I'll use some of them (well, not the one you crossed out!).

my post is pretty much redundant given the \ trick
 
Old 04-26-2014, 03:05 PM   #10
Jeff9
Member
 
Registered: Jun 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
(Just cleaning up old threads I started now that I know you guys like solved threads marked "solved".)

From the posts above, realized that my profile was best setup as
Quote:
alias ls='ls -al --color=auto --group-directories-first'
alias lsd='ls -al -p --color=auto --group-directories-first | grep ''^d'''
And use the "slash trick", \ls, otherwise.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
autofs doesnt turn ghost option off ted_chou12 Linux - Software 0 08-27-2012 01:39 PM
how can i turn "Mic Front Input" option on for alsamixer from cmd line gujedan Linux - Newbie 5 02-28-2011 06:44 PM
How to Add Subtitles to Divx file with Option to turn it On or Off RedNeck-LQ Linux - General 2 02-12-2011 06:33 PM
right click to see terminal option - how to turn it on feetyouwell Linux - Software 0 05-12-2005 10:24 PM
how to turn on FTP option on Linux Redhat Advance Server 2.1 ashley75 Linux - General 1 08-27-2003 12:54 PM


All times are GMT -5. The time now is 12:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration