U
U
unclechu2014-09-19 17:24:57
linux
unclechu, 2014-09-19 17:24:57

How to make BASH/ZSH replace relative paths with absolute ones?

The situation is as follows: I work with a symlink to a directory, there is a certain file above the level of this symlink. Trying to call "mv" and move the file to the current directory:
symbolic_link_to_dir $ mv ../somefile .
But I get an error that the file ../somefile doesn't exist even though auto-complete worked. For a beginner, such behavior can generally lead to a stupor and a deep misunderstanding of the ongoing processes. And in fact "mv" reads the real inode of the directory and goes higher in level of it, and not the symbolic link.
The question is: how can I make it so that there is a rise in level relative to the symbolic link, that is, the current directory. So that in fact something like this happens: UPD: if this is possible at all, for example, on ZSH , I ask you to go to the studio.
symbolic_link_to_dir $ mv `pwd -L`/../somfile .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2014-09-19
@BuriK666

readlink -em filename

S
steep-user, 2015-02-15
@steep-user

[email protected] ~ % ls -ld ./Загрузки          
drwx------ 2 user user 4096 Фев 15 11:35 ./Загрузки
[email protected] ~ % ln -s ./Загрузки ./blabla
[email protected] ~ % ls -l ./blabla 
lrwxrwxrwx 1 user user 18 Фев 15 11:37 ./blabla -> ./Загрузки
[email protected] ~ % cd ./blabla 
[email protected] ~/blabla % mv ../zfsonlinux_4_all.deb .
[email protected] ~/blabla % ls -l         
итого 1996
-rw-r--r-- 1 user user 2040076 Дек 17 18:00 zfsonlinux_4_all.deb
[email protected] ~/blabla % cd -
~
[email protected] ~ % mkdir ./Загрузки/tmpdir
[email protected] ~ % mv blabla/zfsonlinux_4_all.deb .
[email protected] ~ % rm ./blabla 
[email protected] ~ % ln -s ./Загрузки/tmpdir ./blabla 
[email protected] ~ % cd blabla 
[email protected] ~/blabla % mv ../../zfsonlinux_4_all.deb . 
[email protected] ~/blabla % ls -l
итого 1996
-rw-r--r-- 1 user user 2040076 Дек 17 18:00 zfsonlinux_4_all.deb
[email protected] ~/blabla %

What did I do wrong that I have no problems?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question