简体   繁体   中英

Why Linux mv command can operate both file and directory whitout option -r?

rm and cp command should use option -r to distinguish file and directory. I think it means that they operate file and directory in a different way? However, mv command dosen't need it. This my problem. I want to understand how they work and their differences.And also, i want to know where do I go to find the answer the next time I have a similar problem?

My english is poor. Please forgive me if there are any mistakes. Any answer maybe helpful. Thanks.

You may picture a directory as a "list" of what it actually contains (rather than a physical folder).

When you move a directory to another place using mv , you simply need to move the reference to this list on the disk, the content remaining unchanged.

rm and cp , however, need to browse this list because each item inside it need to be processed individually. Thus the -r if they contain subdirectories.

If you have files in your folder and you want to copy or move it, you need to do the -r. It means recursive, it copys/moves the folder and also the files inside the folder.

When you have a folder without any files inside, you don't need to put that -r in the code, because the folder is empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM