Posts tagged ‘shell’

How to add color to your SSH sessions in FreeBSD so files of different types have different colors when using ls?

Hey this was really easy. Really, it is just a matter of aliasing your ls commands. However, it is only really easy if you know how to do it. When you forget, it is annoying. So here is another post to store the info I once knew but forgot and had to learn again.

Using sh, the default shell

  1. Edit your .shrc file in your home folder:
    # ee /usr/home/username/.shrc
  2. Add/Change the alias commands as follows:
    alias ls=’ls -G’
    alias ll=’ls -laFoG’
    alias l=’ls -lG’

    The first one I added, the second two I only added the -G parameter to the already existing aliases for ls.

  3. Save and close the file.
  4. Logout and login and your shell should have colors when you use ls.

Using bash

  1. Edit your .shrc file in your home folder:
    # ee /usr/home/username/.shrc
  2. Add/Change the alias commands as follows:
    alias ls=’ls -G’
    alias ll=’ls -laFoG’
    alias l=’ls -lG’

    The first one I added, the second two I only added the -G parameter to the already existing aliases for ls.

  3. Save and close the file.
  4. Copy the .profile file to .bash_profile.
    # cp /usr/home/username/.profile /usr/home/username/.bash_profile
  5. Edit the .bash_profile and add the following:
    # Source the .shrc
    source .shrc
  6. Logout and login and your bash shell should have colors when you use ls.

Using csh, the default shell for root

  1. As root, edit your .cshrc file in either your home folder or in the home folder for root:

    Your home folder:

    # ee /usr/home/username/.cshrc

    Home folder for root:

    # ee /root/.cshrc
  2. Add/Change the alias commands as follows: (The syntax is slightly different than for sh or bash)
    alias ls ls -G
    alias la ls -aG
    alias lf ls -FAG
    alias ll ls -lAG

    The first one I added, the others I only added the -G parameter to the already existing aliases for ls.

  3. Save and close the file.
  4. Logout and login and your shell should have colors when you use ls.

bash and sh for all users

  1. Edit your .shrc file in your home folder:
    # ee /usr/home/username/.shrc
  2. Add/Change the alias commands as follows:
    alias ls=’ls -G’
    alias ll=’ls -laFoG’
    alias l=’ls -lG’

    The first one I added, the second two I only added the -G parameter to the already existing aliases for ls.

  3. Save and close the file.
  4. Cat this file to /etc/profile.
    # cat /usr/home/username/.shrc > /etc/profile
  5. Logout and login and your shell should have colors when you use ls.

csh for all users

  1. As root, edit your .cshrc file in either your home folder or in the home folder for root:

    Your home folder:

    # ee /usr/home/username/.cshrc

    Home folder for root:

    # ee /root/.cshrc
  2. Add/Change the alias commands as follows: (The syntax is slightly different than for sh or bash)
    alias ls ls -G
    alias la ls -aG
    alias lf ls -FAG
    alias ll ls -lAG

    The first one I added, the others I only added the -G parameter to the already existing aliases for ls.

  3. Save and close the file.
  4. Cat this file to /etc/csh.cshrc.
    # cat /usr/home/username/.cshrc > /etc/csh.cshrc
  5. Logout and login and your shell should have colors when you use ls.

Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

How to remove the ^M characters in a file on FreeBSD?

How to remove the ^M characters in a file on FreeBSD?

This is simple:

There are multiple ways to do it. One is actually included in the FreeBSD-tips file:

tr -d \\r < file > newfile
— Originally by Dru

So if you installed the “games” distribution, you get tips every time you log in. And once in a while the above tip will show up.

I had never used that one however, I had always used this one (which I modified) that I found here: http://sed.sourceforge.net/sed1line.txt

sed -i.bak ‘s/^M$//’ filename # in bash/tcsh, press Ctrl-V then Ctrl-M

However, this one works with the sh, tcsh and bash but not with the csh shell.

This one worked on csh but I am not sure if it is recommended as it assumes every line ends with ^M.

sed -i.bak ‘s/.$//’ filename # assumes that all lines end with CR/LF

Anyway, I like how FreeBSD supports the -i parameter. Because if I am doing lots of files, I can have a script that does each file in a directory and then (of course I have a back up just in case) I can run sed -i.bak ‘s/.$//’ filename on each file and then do delete all .bak files so every file “appears to be” edited in place.