2020年12月20日星期日

Is mv * a destructive command on a directory with 2 or more files? What other linux commands have similar behavior?

When I run mv * with no destination directory on a directory with say 10 files, I get an error as follows

root@tryit-apparent:~/test2# ls                                                                                                                          file1.txt  file10.txt  file2.txt  file3.txt  file4.txt  file5.txt  file6.txt  file7.txt  file8.txt  file9.txt                                            root@tryit-apparent:~/test2# mv *                                                                                                                        mv: target 'file9.txt' is not a directory         

When I run it on a directory with two files it overwrites the file with one just file.

root@tryit-apparent:~/test# ls                                                                                                                           tempfile  tempfile2                                                                                                                                      root@tryit-apparent:~/test# mv *                                                                                                                         root@tryit-apparent:~/test# ls                                                                                                                           tempfile2                                  

I read the man pages but couldn't understand this behaviour. Would like to know what's causing this behavior and what's going on under the hood?

What other linux commands have such pitfalls and have destructive actions that are executed silently if the user is not aware of such behavior?

https://stackoverflow.com/questions/65387698/is-mv-a-destructive-command-on-a-directory-with-2-or-more-files-what-other-li December 21, 2020 at 12:58PM

没有评论:

发表评论