Well, you could just add this line to your ~/.profile
1:
HOME=/user/home/
However, that really isn't a good idea. Problems it would cause include (but are probably not limited to):
That will only work if /home/user
is owned by your user. If it isn't, you won't even be able to log in.
This will work for your user only. For everyone else, your home directory will be whatever is stored in /etc/passwd
. This means that, for example, cd ~user
will fail. In other words, if I log in as bob
and bob
has the line HOME=/home/bob/foo
in ~/.profile
, then bob
thinks that his home directory is /home/bob/foo
but nobody else knows that:
$ whoami
bob
$ echo $HOME
/home/bob/foo
$ cd ## this moves to your $HOME
$ pwd
/home/bob/foo
So far so good. But:
$ whoami
terdon
$ cd ~bob
$ pwd
/home/bob
- This will drive your sysadmin insane. You do not want to anger your sysadmin for you are crunchy and taste good with ketchup.
In any case, it is rarely a good idea to mess with variables like $HOME
, as it can often have unintended consequences. Instead, a much cleaner solution would be to make sure every new shell session starts in the target directory. Just add this line to your ~/.bashrc
:
cd /user/home/
Now, each time you log2 in or open a terminal, you will find yourself in /user/home
.
1 Or ~/.bash_profile
if it exists.
2 Log in to Debian-based systems like Ubuntu, anyway. For other distributions/OSs, you might need to add it to ~/.profile
as well.See here.
Besides copying the binary from another machine and hoping it is the correct version, this can also be solved by using apt
or apt-get
to install the sed
package and passing the --reinstall
option so that the .deb
file will be downloaded and installed even though Ubuntu's package manager thinks it is already present.
sudo apt install --reinstall sed
This works with apt-get
instead of apt
, too. It uninstalls and reinstalls the package in a single step. The situation in this problem is that the se
package is already installed but the executable has been deleted, so reinstalling solves that. Without the --reinstall
flag, the package manager assumes nothing has to be done, because the package is installed already.
You can run sudo apt update
first if you want, though it will not typically be necessary in this case, unless you've modified your software sources without doing so. You can pass the --purge
flag too if you want but it's unnecessary here, since that just causes conffiles for the package to be removed when it is uninstalled.
sed
is a utility that programs are generally allowed to assume exists and to rely on themselves. As you noticed, the scripts that run when installing, removing, or upgrading software can use sed
. That's the source of your specific error messages. In theory APT or dpkg
could rely on it directly and be unable to reinstall it. In practice, this does not appear to happen, and I don't expect it to. I've tested this on Ubuntu 16.04 LTS.
I cannot think of any situation where replacing the binary fixes the problem but reinstalling neither works nor shows an error immediately (see comments on the post). Although I cannot be 100% sure that these instructions would work for you--because perhaps more was broken than documented in the question--they should generally work at least as reliably as manually replacing /bin/sed
for others who experience this problem.
Best Answer
To achieve this manually, an in a simple manner you could use the
mv
command with some strong quoting to ensure that the shell doesn't interpret the colon as a special character:An alternate approach is to use a variable and the one of the features of Bash parameter expansion, which may be more useful if you wish to automate this directory name change into a script:
The expansion of
"${dir//:/}"
will replace any occurrence of the colon character with nothing, giving the expected result of Lang-32b-BranchLine. Using"${dir/:/}"
would result in only the first occurrence of the colon being removed, though that would still work for your given example.As a one-liner to move and cd into the directory:
Or if you wished to capture the modified directory name into a variable named new_dir:
A great guide to Bash parameter expansion is available here.