LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2023, 06:25 AM   #1
Llyich
LQ Newbie
 
Registered: Mar 2023
Location: Switzerland
Distribution: PC Xubuntu/Devuan laptop Xubuntu 12.04 LTS
Posts: 7

Rep: Reputation: 0
mv --dereference


mv --dereference

Bonjour,

Question: "cp" has the option "-L, --dereference", does "mv" have a similar option? It seems not.

I only found a warning with [info '(coreutils) mv invocation'], and nothing in Linux-Newbie...

I plan to write a script to do this, I would have needed it this morning!
The question is funny, isn't it.

Kind regards,
Llyich
 
Old 03-18-2023, 06:48 AM   #2
lvm_
Senior Member
 
Registered: Jul 2020
Posts: 1,020

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
If you move a file referenced by a symlink you break this symlink, don't you?
 
Old 03-18-2023, 07:51 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by lvm_ View Post
If you move a file referenced by a symlink you break this symlink, don't you?
In the case of cp -L it's supposedly dereferencing the source file. Perhaps in some cases cp may simply copy the link itself (although I just did some experimentation and it seems to always copy the source). The option -L enforces an actual copy of the file content itself, even if the source is a symlink.

If you use mv on a link, it simply moves the link itself. I suppose what the OP wants is to have mv not move the link itself, but instead create a new copy of the file and destroy the old link.

Basically,
Code:
cp -L $1 $2 && rm -f $1
would do the job.

Last edited by goumba; 03-18-2023 at 07:53 AM.
 
1 members found this post helpful.
Old 03-21-2023, 05:13 AM   #4
Llyich
LQ Newbie
 
Registered: Mar 2023
Location: Switzerland
Distribution: PC Xubuntu/Devuan laptop Xubuntu 12.04 LTS
Posts: 7

Original Poster
Rep: Reputation: 0
Bonjour, thank you for your answers.

"cp -L $1 $2 && rm -f $1", delete the links.
I had written "rml.py", I would have to adapt it and test it more thoroughly.

(I was organizing my personal data and wanted to do an mv instead of a cp to avoid duplicating data. To explain why I use links would be off topic here).

Kind regards,
--
Llyich

Last edited by Llyich; 03-21-2023 at 05:14 AM.
 
Old 03-21-2023, 06:38 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,132

Rep: Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374
when copying files, both the original [symbolic] link and the [real] file remain in place (and you can decide if you want to copy the file or the link). move does not care about the type of the directory entry, it can be file, dir, link, whatever, that will be used (moved). If you wish to follow the link you need to implement it yourself, but it looks like you have already solved it.
 
1 members found this post helpful.
Old 03-21-2023, 07:57 AM   #6
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by Llyich View Post
Bonjour, thank you for your answers.
(I was organizing my personal data and wanted to do an mv instead of a cp to avoid duplicating data. To explain why I use links would be off topic here).
If avoiding duplication is what you want, consider hard links, or a filesystem that supports reflinks like xfs. I would hate to use symlinks for such a purpose as if you rename the target, you end up with a dangling symlink.
 
Old 03-21-2023, 03:19 PM   #7
Llyich
LQ Newbie
 
Registered: Mar 2023
Location: Switzerland
Distribution: PC Xubuntu/Devuan laptop Xubuntu 12.04 LTS
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
I would hate to use symlinks for such a purpose as if you rename the target, you end up with a dangling symlink.
Bonjour, why I use links?

Here is a thunar action to quickly create links
Quote:
ln -s %F /home/serv/Link/000/
I am grouping file links that can come from different HDs, and I delete them after use.

Uses:
I perform batch processing on the server, for example a switch to x265 codec.
Quote:
ffmpeg -i "$fic" -map 0:0 -map 0:? -c:v "lib$codec" "$fic.$codec.$contener"
The "source" stays on the HD 3.5".
The processing is faster than if it was done directly on the HD.
The server: Intel Quad Core I7 8550U, Samsung SSD Internal 970 EVO Plus NVMe M.2.

I also perform subtitle and audio extraction, using links on the files to be processed.

I do sorting, grouping, renaming of links, when it's files of the same HD, a "mv -L" would be faster than a "cp -rvL".

Kind regards,
--
Llyich

Last edited by Llyich; 03-21-2023 at 04:12 PM.
 
Old 03-21-2023, 04:26 PM   #8
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
I don't understand

Hello Llyich,

I don't understand what you are doing.

Symlinks are good! I use them a lot. But why would you want to have "mv -L"? To move the link do this:
mv <link> <place>
To move the link target do this:
mv `readlink -f <link>` <place>
To reduce the amount of typing that you do, write script "mvtarg", give it execute permission, and put in in /usr/local/bin:

Code:
#!/bin/sh
# mvtarg

# Joseph Rosevear 230321 I wrote this script.

# Check invocation.
if [ "$#" -lt "2" ]; then

   echo "Usage: mvtarg <link> <target> <other arguments>"
   exit
fi

# Definitions.
link="$1"
place="$2"
target=`readlink -f "$link"`

# Shift twice to give easy access to remaining arguments.
shift; shift

# Move the link target to $place and use remaining arguments.
mv "$target" "$place" $*

Last edited by jrosevear; 03-22-2023 at 01:08 PM. Reason: remove indent tags
 
Old 03-22-2023, 03:53 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,132

Rep: Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374Reputation: 7374
Quote:
Originally Posted by jrosevear View Post
Hello Llyich,

I don't understand what you are doing.

Symlinks are good! I use them a lot. But why would you want to have "mv -L"? To move the link do this:
mv <link> <place>
To move the link target do this:
mv `readlink -f <link>` <place>
To reduce the amount of typing that you do, write script "mvtarg", give it execute permission, and put in in /usr/local/bin:
#!/bin/sh
# mvtarg

# Joseph Rosevear 230321 I wrote this script.

# Check invocation.
if [ "$#" -lt "2" ]; then
echo "Usage: mvtarg <link> <target> <other arguments>"
exit
fi

# Definitions.
link="$1"
place="$2"
target=`readlink -f "$link"`

# Shift twice to give easy access to remaining arguments.
shift; shift

# Move the link target to $place and use remaining arguments.
mv "$target" "$place" $*
please use code tags if you want to post code.
Do not use backtick, but $( )
Do not use $*, but "$@"
I guess you wanted to use bash, not sh (see your shebang)
Also use shellcheck to check your script
 
1 members found this post helpful.
Old 03-22-2023, 02:13 PM   #10
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
Thanks for your help

Quote:
Originally Posted by pan64 View Post
please use code tags if you want to post code.
Do not use backtick, but $( )
Do not use $*, but "$@"
I guess you wanted to use bash, not sh (see your shebang)
Also use shellcheck to check your script
Hello pan64,

Thank you for taking an interest in my code and my post.

I did not know about the code tag, thank you!

Let me tell you about my code and about myself. First about myself. I am not a professional coder, but I have been coding long enough to have established a base of experience. Perhaps you are a professional coder?

You may not like my choices, but they were my choices. I will talk about them briefly so you and other readers will know what I did purposefully:

I like back tics and I used them on purpose. I have found that they work well for me, although I have occasionally used $(). I understand that the two are not equivalent, although I cannot tell you off hand how they are different. Perhaps I have something about that in my notes.

The story regarding my use of $* instead of $@ is similar, although I know a little more about the differences in this case. I have in my notes an example of the use of $@, and I do use this in code when I want to pass arguments that contain spaces from one invocation to another. (I hope I said that right--I can give you an example if you like.)

My post contained this shebang: #!/bin/sh. Did you miss it?

I think my spelling is pretty good. Bear in my mind the possibility of regional differences in spelling, however if you think I misspelled a word, or made other errors of presentation, please let me know.

So that is the story about my code and myself. Thank you for your comments.

-Joe
 
Old 03-22-2023, 02:42 PM   #11
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,655

Rep: Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582

I've no idea why Pan64 wrote "I guess you wanted to use bash, not sh (see your shebang)" - there's no Bash-specific syntax there, so no benefit in requiring Bash.

For the difference between command substitution syntax, see BashFAQ #82 Why is $(...) preferred over `...` (backticks)?

On the passing arguments bit, you should be using '"$@"' not '$*' - see SC2048 Use "$@" (with quotes) to prevent whitespace problems for an example of why.

ShellCheck is useful for highlighting these issues - it's both a website and an offline tool, and BashFAQ/BashPitfalls are both useful references. (Not everything in them is Bash-specific.)


Last edited by boughtonp; 03-22-2023 at 02:44 PM.
 
1 members found this post helpful.
Old 03-22-2023, 03:50 PM   #12
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
I mis-read your post. I'll try again.

Quote:
Originally Posted by jrosevear View Post
Hello pan64,

Thank you for taking an interest in my code and my post.

I did not know about the code tag, thank you!

Let me tell you about my code and about myself. First about myself. I am not a professional coder, but I have been coding long enough to have established a base of experience. Perhaps you are a professional coder?

You may not like my choices, but they were my choices. I will talk about them briefly so you and other readers will know what I did purposefully:

I like back tics and I used them on purpose. I have found that they work well for me, although I have occasionally used $(). I understand that the two are not equivalent, although I cannot tell you off hand how they are different. Perhaps I have something about that in my notes.

The story regarding my use of $* instead of $@ is similar, although I know a little more about the differences in this case. I have in my notes an example of the use of $@, and I do use this in code when I want to pass arguments that contain spaces from one invocation to another. (I hope I said that right--I can give you an example if you like.)

My post contained this shebang: #!/bin/sh. Did you miss it?

I think my spelling is pretty good. Bear in my mind the possibility of regional differences in spelling, however if you think I misspelled a word, or made other errors of presentation, please let me know.

So that is the story about my code and myself. Thank you for your comments.

-Joe
Hello pan64,

I made two mistakes when reading your post. I thought you wrote that I had not included a shebang. On re-reading I see that you questioned why I used sh instead of bash. The answer is that I wanted to use sh--I used it on purpose. In Slackware /bin/sh is a symlink to bash, although I believe that the use of #!/bin/sh is not equivalent to the use of #!/bin/bash.

My other mistake was that I thought you were recommending that I use a spell-checker. Ha! I was groggy from a good night's sleep when I responded. About shell-checkers and other such tools, I don't use them, as I don't find them to be helpful. I understand why these tools abound. Businesses need standards to keep odd coding techniques from creeping in to the code base. I code for myself and for those who wish to use my code, not for an employer.

Forgive me for these clumsy errors!

-Joe
 
Old 03-22-2023, 04:29 PM   #13
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
Perhaps you are correct

Quote:
Originally Posted by boughtonp View Post
I've no idea why Pan64 wrote "I guess you wanted to use bash, not sh (see your shebang)" - there's no Bash-specific syntax there, so no benefit in requiring Bash.

For the difference between command substitution syntax, see BashFAQ #82 Why is $(...) preferred over `...` (backticks)?

On the passing arguments bit, you should be using '"$@"' not '$*' - see SC2048 Use "$@" (with quotes) to prevent whitespace problems for an example of why.

ShellCheck is useful for highlighting these issues - it's both a website and an offline tool, and BashFAQ/BashPitfalls are both useful references. (Not everything in them is Bash-specific.)
Hello boughtonp,

Regarding the back tic, the site you referenced seems to say it is a matter of preference. It describes inconveniences associated with the use of the back tic. Certainly it does not say that one cannot successfully use the back tic. I use it when I can, which is most of the time, because I like it.

Regarding the use of "$@" (with quotes), I don't believe it is wrong to use $*. The error happens in the use of the script, not in the writing of the script. If the user wishes to pass arguments containing spaces--I think this is the matter in question--then yes he should write a script in the way that you recommend. Otherwise it doesn't matter, yes? As a kindness to others, perhaps it would have been better to have written it as you suggested.

Thanks, by the way, for your several references to interesting web articles/sites about coding.

-Joe

Last edited by jrosevear; 03-22-2023 at 04:56 PM. Reason: clarity
 
Old 03-22-2023, 04:59 PM   #14
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,655

Rep: Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582Reputation: 2582
Quote:
Originally Posted by jrosevear View Post
Regarding the use of "$@" (with quotes), I don't believe it is wrong to use $*. The error happens in the use of the script, not in the writing of the script.
It's a bug in the script - it incorrectly splits quoted arguments.

Code:
$ tail example{1,2}.sh
==> example1.sh <==
#!/bin/sh
file $*
==> example2.sh <==
#!/bin/sh
file "$@"

$ ./example1.sh test_file1 'test file2'
test_file1: ASCII text
test:       cannot open `test' (No such file or directory)
file2:      cannot open `file2' (No such file or directory)

$ ./example2.sh test_file1 'test file2'
test_file1: ASCII text
test file2: ASCII text
 
Old 03-22-2023, 05:07 PM   #15
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
Quote:
Originally Posted by jrosevear View Post
Hello boughtonp,

Regarding the back tic...
This is funny. I looked it up and learned that the correct spelling is "backtick". Back tic is something else altogether. See involuntary twitch.

-Joe
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
oops - made a file called "--dereference" - how do I delete it? BrianK Linux - General 2 06-21-2004 08:37 PM
Strange kernel error: "Unable to handle kernel NULL pointer dereference..." EcceVery Debian 4 04-12-2004 06:34 AM
Unable to handle kernel NULL pointer dereference.... kadaver Slackware 2 12-19-2003 07:46 AM
Unable to handle kernel NULL pointer dereference at virtual ...? severedhead Linux - Software 0 07-12-2002 04:46 PM
Kernel Message:unable to handle kernel NULL pointer dereference at virtual address... dave_d Linux - General 0 02-14-2001 05:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration