Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put something in in bashrc to hide text editor (~ extension) files?

Tags:

linux

bash

I'd like to do ls without seeing all the ~ files generated by vim. Is it possible?

like image 352
rick Avatar asked May 10 '09 03:05

rick


3 Answers

This is better solved from within vim, as opposed to bash.

Use

set backupdir=~/.backup,/tmp

to put all your ~ files in the ~/.backup directory. Change that directory to whatever you want. The /tmp means that it will act as a fallback to the ~/.backup directory.

If you don't want backup files to be generated at all, you can use

set nobackup
set nowritebackup

to disable it, but you will of course lose that functionality.

EDIT:

Although the above solution is still the one I recommend because you can do more with it, I just realized that ls has a -B option which will hide files ending with ~. I've aliased it myself, and never noticed. If you really want, you can alias ls -B and go with that.

EDIT v2.0:

As noted by Wesley, some platforms' ls command have different meanings for -B, some may not have it at all. I'm using the GNU ls, and it has had this switch for as long as I can remember.

like image 174
sykora Avatar answered Nov 04 '22 09:11

sykora


Many editors use the ~ files to represent backup files. (I use this trick to hide the backup files from gedit.) To disable them from showing, add this command to your bashrc:

alias ls='ls --hide=*~'

Edit: Mac OS X ls does not appear to have this option, so it follows that BSD ls probably doesn't have it either. Ubuntu does have this option, so many Linux distributions probably do; check your manual pages. In addition, Mac ls appears to have a different -B, so consider this when using Sykora's advice.

like image 32
Wesley Avatar answered Nov 04 '22 11:11

Wesley


You'll be sorrrrryyyy if you just hide them from ls. They'll still be there as far as grep and other tools are concerned except that now you can't see them. Moving them to /tmp is a much better way to go.

This problem is ESPECIALLY severe with .svn directories, which have all kinds of useless cr*p that you really don't want to edit. I don't know a solution to that one.

like image 34
Brad Cox Avatar answered Nov 04 '22 10:11

Brad Cox