LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 09: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, 11:01 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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 11:16 AM.
 
Old 08-12-2013, 11:50 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 11:56 AM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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, 12:20 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
why dont you just rename the alias ?
 
Old 08-12-2013, 12:24 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
You can always 'unalias' it. Or you can tmp login to a subshell without aliases.
 
Old 08-12-2013, 12: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, 12:49 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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, 01:01 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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, 02: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



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 12:39 PM
how can i turn "Mic Front Input" option on for alsamixer from cmd line gujedan Linux - Newbie 5 02-28-2011 05: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 05:33 PM
right click to see terminal option - how to turn it on feetyouwell Linux - Software 0 05-12-2005 09:24 PM
how to turn on FTP option on Linux Redhat Advance Server 2.1 ashley75 Linux - General 1 08-27-2003 11:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:29 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