Skip to content

BASH: alias ls problem

Marie-Louise edited this page May 4, 2019 · 5 revisions

The quickest way to open the file an edit it type:

nano ~/.bashrc

UPDATE: my ~/.bashrc currently has this alias ls='ls -C' after I removed an Atom.app shortcut.

I posted this problem

"Hello, I'm new to this slack group and I have a question about the mac terminal, in particular how to remove access control list 'trailing'

so to elaborate, whenever I type ls, then i see this kind of text

drwxr-xr-x+

firstly, is this the right channel to ask about this problem ? secondly, if so - does anyone know how to fix it ? I allowed someone to use my computer and he took the liberty to re-configure the terminal settings...and I haven't been able to get rid of it since"

these were the responses i got:

@ML you could also try alias ls, to see if it’s been aliased to anything

ML [11:47 AM] thanks @stain88, this was the result 👇 So I'm assuming that the alias is creating this problem. if so, how do i remove it ? Untitled alias ls='ls -alG'

Gabriel Ostrolucký [11:49 AM] you should be able to finish resolving this with help of google

stain88 [11:49 AM] partly depends on what SHELL you’re using, but it’s probably in something like ~/.bashrc or ~/.zhsrc

ML [11:51 AM] ok @stain88 it's bash

stain88 [11:53 AM] then start looking in ~/.bashrc, and if that sources any other files, keep looking through until you find the line alias ls='ls -alG' might also be ~/.bash_profile i suppose, but just depends how the person who used your computer set it up if all else fails, grep -r 'ls -alG' ~ will just do a recursive search until you find it, but that might take a while (edited)

ML [12:01 PM] ok thanks for your help @stain88 🙏! I'll let you know how I get on

chadthecoder2 [12:49 PM] joined #general.

ML [12:58 PM] @stain88 I found alias ls='ls -alG' in the file .bash_aliases. but after deleting the whole line, nothing changed. I'm trying to figure out how to delete the file and hopefully that will resolve the issue (edited)

stain88 [1:04 PM] When changing things like that, you need to open a new terminal window for the changes to take effect

ML [4:26 PM] thanks @stain88. I ended up changing the alias to alias ls='ls -C', which worked for a bit and displayed a neat list (when i opened a new window) but now whenever in ls it returns nothing 😫

ML [4:39 PM] I'm trying to find out the name of person (used my comp at a bootcamp) and contact details so that he can undo the mess that he made in my terminal . But thanks for your help 🙏

ML [4:58 PM] ignore that, I had to overwrite the file so now it's working, thanks again @stain88 🙏

then finally the best one!! below:

Glen Jarvis [Dec 30th at 2:16 PM] @ML Although you solved the 'ls' problem, I'd like to take a moment to make this a learning opportunity (for all interesting). I'll put my comments within the thread attached to this line.

18 replies Glen Jarvis [4 days ago] First, I want to say: KUDOS for asking, "Is this the right channel?" It is a specific question about Linux/Unix command line and shell. I don't know of a particular channel that may have been made for these types of questions. Since it's in #general, we can chat in this thread so that those interested can drill down and those aren't can skip it. (edited)

Glen Jarvis [4 days ago] As you may have figured out by now, alias is a way of taking a particular command that you want to type and make an alias so that another command can do it. A classic example is dir.

Glen Jarvis [4 days ago] If you are used to the dir command (what is typically used in Windows to list directories (these days called folders), you may prefer to keep that command. Linux/Unix originally called the command ls short for list while Windows calls the command dir for directory.

Glen Jarvis [4 days ago] To make that happen, you can type alias dir=ls

Glen Jarvis [4 days ago] The spaces in your shell (I'll assume bash for this conversation) can be very important. notice there is no space between the dir, =, and ls.

Glen Jarvis [4 days ago] Here's an example:

-bash: dir: command not found
$ alias dir=ls
$ dir
AndroidStudioProjects        Pictures
Applications            Public
Backups                VirtualBox VMs
Desktop                bin
Documents            .....```
(edited)


Glen Jarvis [4 days ago]
So, I "made" a `dir` command. As far as my shell is concerned, I have a command called `dir`. In reality, whenever it sees `dir` it knows, oh, you mean `ls`. I can do that.

Glen Jarvis [4 days ago]
Now, if you close your shell window and open it again, the `dir` command should not work (assuming it didn't in the example above -- this is such a common pattern someone may have already done it on your computer).

Glen Jarvis [4 days ago]
To go through the exercise, you can also do a "Hey, I'll make up my *own* word other than `dir` to show that this also works." You may do something like `showme` as seen here:

```$ showme
-bash: showme: command not found
$ alias showme=ls
$ showme
AndroidStudioProjects        Pictures
Applications            Public
Backups                VirtualBox VMs
Desktop                bin
Documents            .....```

Glen Jarvis [4 days ago]
Either way, when you leave the shell, and come back, the alias is forgotten. There are ways of teaching it this `alias` each time you start a new shell, but that's outside the scope of the question and I don't want to overwhelm you.

Glen Jarvis [4 days ago]
Now, here's a side lesson, what does `ls -alG` do?  It's the `ls` command with the `-a` and the `-l` and the `-G` options. Can you determine what those options do in this page?:

http://man7.org/linux/man-pages/man1/ls.1.html

Glen Jarvis [4 days ago]
You can alias a command that already exists into another set of options for that command that already exists. It gets kinda of meta there :slightly_smiling_face:  Instead of `dir` being `ls` it's going to be `ls` with `ls` (with some extra options). Let's assume that I want my `ls` command to do a long listing every time (the `-l` option). I can do this:
`alias ls='ls -l'`

Glen Jarvis [4 days ago]
And, now, when I type `ls` I get a different output - the same output that I would get if I had typed `ls -l`:

```$ alias ls='ls -l'
$ ls
total 24
drwxr-xr-x   5 glenjarvis  staff   160 Dec 24  2015 AndroidStudioProjects
drwx------  11 glenjarvis  staff   352 Jun  4  2016 Applications```


Glen Jarvis [4 days ago]
(I clearly hadn't done anything with AndroidStudioProjects in a long time and had forgotten that this was there).  The `-l` option is incredibly useful to tell things that I would not have seen normally (for example, if an execute bit was set on a file). But, you can turn it on or off.

Also, notice how the quotes and spacing are very important, there needs to be no spacing around the `ls`, `=`, and `'ls -l'` components.

Additionally, the single quotes are needed (technically double quotes would work in this example too - again, outside the scope of this question), around the `ls -l` -- this is because that command itself also has spaces.


Glen Jarvis [4 days ago]
With all of that said, @ML, some of the suggestions that you were given answered your questions but had other, possibly, unintended consequences. They were certainly outside the scope of how you asked your question (intentionally or not). For example, what happens if you have a file that has the name `.hey_look_at_me`. It would have shown up before, but it wouldn't have shown up now. Why is that?  I direct you again to this page:

http://man7.org/linux/man-pages/man1/ls.1.html

So, now, what would be the exact alias command answer that would have "removed the trailing `rwxrw-rw-` type of stuff" but would have kept the other options setup by the person doing your tutorial?

There's certainly an option that you removed that you may have intended to keep. I leave that as a challenge - I believe you have all of the information in this thread to answer it.

Also, if you are doing a tutorial and they set this up, removing this `-l` option from the alias as you want would remove the `rwxrw-rw-` that you asked for -- but it may also hide some information that you need to know. But, if you want that freedom, really understanding the `-l`, `-a`, and `-G` options from this page will get you past that issue and have the freedom of changing `ls` as you like:

http://man7.org/linux/man-pages/man1/ls.1.html

From the path that you took, there *will* be files missing that you may or may not need in your tutorial (whoever had made that tutorial may have wanted you to know).

Hopefully those things help. (edited)


angelocordon [4 days ago]
Great learning write up!



linda [4 days ago]
@Glen Jarvis Great write-up! I encourage you to paste this into a blog post so we can reshare in #blogbuddies or #please-retweet :slightly_smiling_face:



ML [1 day ago]
@Glen Jarvis I've literally only just seen this! Thank you so much, I really appreciate the time that you've taken to write such a detailed and comprehensive explanation:raised_hands: ! The bulk of my learning up until this point has been mostly focused around specific front-end and backend languages, but now I realise how much I've underestimated the importance of learning about the command line etc . I'm currently on holiday but when I return home, I'll read through the links you've suggested and experiment a little a bit in order to gain a thorough understanding. I'll definitely write about my findings and would like to keep this conversation going - so will post again because I agree that is can be opportunity for everyone interested to learn. Once again, thank you so much :smiley::ok_hand: !!

Clone this wiki locally