How to modify a sftp symlink - sftp

Creating a symlink via sftp is as easy like that:
symlink oldpath newpath
but how can I modify the symlink newpath afterwards to point to anotherpath?

Remove the symlink and create a new one pointing to the other path:
rm newpath
symlink anotherpath newpath
OpenSSH calls symlink() function from standard C library, which does not have any possibility to overwrite the symlink.

Related

How to create a symbolic link with the api.jar file in unix?

I have jar file for eg abc-api.10.1.jar; i want to create symlink so that next time new jar comes like abc-api.10.2.jar i just point the link to new jar
On RHEL you could use something like this :ln -s <real object> <symlink name>
ln -s abc-api.10.1.jar current_jar

Symlink dotfiles

I am having trouble symlinking dotfiles. I have a folder in my home directory ~/dotfiles which I have synced to a github repo. I am trying to take my .vimrc file in ~/dotfiles/.vimrc and create a symbolic link to put it at ~/.vimrc. To do this I type in
ln -s ~/dotfiles/.vimrc ~/.vimrc
But when I run that it says
ln: /Users/me/.vimrc: File exists
What am I doing wrong?
That error message means that you already have a file at ~/.vimrc, which ln is refusing to overwrite. Either delete the ~/.vimrc and run ln again or let ln delete it for you by passing the -f option:
ln -s -f ~/dotfiles/.vimrc ~/.vimrc
There is a better solution for managing dotfiles without using symlinks or any other tool, just a git repo initialized with --bare.
A bare repository is special in a way that they omit working directory, so you can create your repo anywhere and set the --work-tree=$HOME then you don't need to do any work to maintain it.
Approach
first thing to do is, create a bare repo
git init --bare $HOME/.dotfiles
To use this bare repo, you need to specify --git-dir=$HOME/.dotfiles/ and --work-tree=$HOME, better is to create an alias
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME
At this point, all your configuration files are being tracked, and you can easily use the newly registered dotfiles command to manage the repository, ex :-
# to check the status of the tracked and untracked files
dotfiles status
# to add a file
dotfiles commit .tmux.conf -m ".tmux.conf added"
# push new files or changes to the github
dotfiles push origin main
I also use this way to sync and store my dotfiles, see my dotfiles repository and can read at Storing dotfiles with Git where I wrote about managing for multiple devices.
How to symlink all dotfiles in a directory recursively
Have a dotfiles directory that is structured as to how they should be structured at $HOME
dotfiles_home=~/dotfiles/home # for example
cp -rsf "$dotfiles_home"/. ~
-r: Recursive, create the necessary directory for each file
-s: Create symlinks instead of copying
-f: Overwrite existing files (previously created symlinks, default .bashrc, etc)
/.: Make sure cp "copy" the contents of home instead of the home directory itself.
Tips
Just like ln, if you want no headache or drama, use an absolute path for the first argument like the example above.
Note
This only works with GNU cp (preinstalled in Ubuntu), not POSIX cp. Check your man cp, you can install GNU coreutils if needed.
Thanks
To this and this.

Force create existing folder with Meteor

When I use the command:
meteor create myfolder
It won't by default allow meteor to install itself if the folder is already existing. I can't find an option to force it. Is it really necessary that Meteor creates the directory by itself first or is this just because of 'good practice'?
I want to automate the creation of a folder first and run the meteor command afterwards, hence the question.
Maybe you want a shell script like the following:
$DIR = <some variable>
if [ ! -f "$DIR" ]; then
meteor create tempDir
mv tempDir/* "$DIR/"
rmdir tempDir
fi
which will copy the contents into your new directory, as long as it doesn't contain any Meteor files already.

Symlink ~.zshrc

If my .zshrc file is ~/.dotfiles/zsh/.zshrc, how can I create a symlink so that the file appears as ~/.zshrc?
The cd step in Alexej's answer isn't needed as you can call ln -s target destination explicitly.
ln -s ~/.dotfiles/zsh/.zshrc ~/.zshrc
run:
cd ~/ ; ln -s ~/.dotfiles/zsh/.zshrc
for me, when using relative path for symlink, it can show error: ~/.zshrc: No such file or directory error as #astephen2. You should change to absolute path then it working fine
You don't actually need a symlink. Add the following to ~/.zshenv:
ZDOTDIR=~/.dotfiles/zsh
zsh sources ~/.zshenv before any other files, and will use the value of $ZDOTDIR as the location for local configuration files in lieu of your home directory.
On MacOS, you can't use ~ in a symlink where the directory is quoted. You need to use full paths. I'd recommend running ln -s "$HOME/.dotfiles/zsh/.zshrc" "$HOME/.zshrc" Alternatively, you can forget the quotes, and use ~ in place of $HOME, however if there are any spaces (or variables with spaces) you'll probably run into problems.

Symbolic link to a non existing file

I tried to create a symbolic link to a non existing file
ln -s non_existing_file.txt $HOME/dir1/dir2/my_symbolic_link
Then I tried to write something in the non existing file using the symbolic link
vi $HOME/dir1/dir2/my_symbolic_link
Now after saving and exiting non_existing_file.txt is created under dir2.
Can someone explain why?
ln -s target linkpath
creates a symlink at linkpath which holds the name target. Operations on the symlink interpret the name target relative to the directory where the symlink resides, not the present working directory.
So, if you have a symlink holding, say, ../usr in /tmp/link-to-usr, then ls /tmp/link-to-usr will list the contents of /usr (which is /tmp/../usr) regardless of where the ls command is executed.

Resources