Two .bashrc files in my home dir

0

I'm using Ubuntu on Windows and I was attempting to modify my .bashrc file to add a directory to my PATH variable. I used redirection to do it like so:

pwd >> ~/.bashrc

Now I have two .bashrc files in my home directory, and I can't get that back down to one. I've tried the following:

mv .bashrc copy.bashrc
rm .bashrc

That mv command successfully breaks them up so that ls -a shows one .bashrc and one copy.bashrc file, where the copy is the real one. That rm command, however, doesn't work and instead tells me that .bashrc doesn't exist.

I considered deleting copy.bashrc instead, but then I would lose everything that's supposed to be in .bashrc. I've also tried the following:

cat copy.bashrc > .bashrc

This simply leads me back to where I started with two .bashrc files in one directory.

What is going on here?

joshisanonymous

Posted 2019-05-03T00:03:04.510

Reputation: 21

Answers

1

pwd > ~/.bashrc overwrote the .bashrc file in your home directory. This operation is not reversible and will not have created a second .bashrc (in fact having two files with the same name in a directory is impossible).

mv .bashrc copy.bashrc moves .bashrc to copy.bashrc, which means that the subsequent rm .bashrc will definitely fail - the file has been moved away and there is no longer a .bashrc file.

Another point of confusion is that .bashrc is the full name of the file. So if you by "two .bashrc files" mean that you have two files whose name end with ".bashrc" that's weird but not actually a problem - only the one named literally and only ".bashrc" will be used when starting your shell. There is not supposed to be any prefix to it, because it is not a file extension (extensions are anyway mostly meaningless, more so in *nix systems than on Windows).

Does that clarify things?

l0b0

Posted 2019-05-03T00:03:04.510

Reputation: 6 306

Thanks for the response. Unfortunately, I already knew all of this, but you did help me to realize that I accidentally wrote pwd > ~/.bashrc in my question when I mean pwd >> ~/.bashrc. – joshisanonymous – 2019-05-03T14:22:24.763

0

.bashrc as a string contains only printable characters from the ASCII set. If there was any common unprintable character, then ls -a would show it to you one way or another (I mean ls in Ubuntu, in general this depends on implementation), so you would already know.

But there are Unicode non-ASCII characters that look like ASCII (or may look, depending on the font used). E.g. these three strings are pairwise different:

.bashrc
.bаshrc
.bashrс

Ubuntu should have no problem creating files with these names on any modern Linux filesystem. You can test it (hint: in an empty directory, so it's easy to rm -r it as a whole later):

touch .bashrc .bаshrc .bashrс; ls -a

The first one is what you would expect. The second one uses this letter instead of ASCII a. The third one uses this letter instead of ASCII c. It's quite obvious one can easily create yet another impostor – with these two non-ASCII letters.

Then there are "uncommon" unprintable characters ls would not show to you. This command (in Bash)

touch $'.bas\xE2\x80\x8Ehrc'

creates yet another impostor (with left-to-right mark). For this file all characters you see in the output of ls -a are ASCII characters. You need like ls -a | xxd to spot what hides inside the name.

So this is one possible answer to "what is going on here?"


It's virtually impossible your first command created the impostor file, unless

  • you had copied the command from somewhere,
  • or your keyboard settings are weird (but then the string .bashrc you typed here on Super User would probably be affected; I have checked it's ASCII).

I suspect the extra file was already there, unnoticed. Maybe because of

  • a prank,
  • or some rogue software,
  • or some other not-entirely-ASCII code you had copied, pasted and executed.

If you can see the file in your GUI file manager (hint) or mc, then use its features to peek into / move / delete the troublesome file.

Or you can build a glob pattern that catches just the two files, temporarily move the real .bashrc to another directory and use the pattern to refer to the sole impostor. Few ideas:

ls .b?shr?
ls .*b*a*s*h*r*c*

Kamil Maciorowski

Posted 2019-05-03T00:03:04.510

Reputation: 38 429

Thanks for the response. This imposter character thing seems probable. I didn't copy+paste the original command that generated the problem file, but I use four different keyboards. Unfortunately, regardless of which I use, can can't target the problem file with cat .bashrc or ls -a .bashrc or anything. In fact, even ls -a *.* doesn't list the file, even though ls -a still does. I tried mc, but it doesn't seem to work right for the Windows version of Ubuntu, which also means I don't have a GUI. I also tried ls -a | xxd but I don't understand what the output is telling me. – joshisanonymous – 2019-05-03T14:29:42.217

I also tried ls -a *.* with all four keyboards to make sure that it wasn't a weird . character or something, but no luck. – joshisanonymous – 2019-05-03T14:31:28.913

Try ls -a | LC_ALL=C cat -vet and see what weird characters that shows. It'll add a "$" to the end of each line, but other than that normal things will display normally and weird characters should stand out. For example, it displays Kamil's examples as ".bashrc$", ".bashrM-QM-^A$", and ".bM-PM-0shrc$". – Gordon Davisson – 2019-05-03T16:45:38.557