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.
CodePudding user response:
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.
CodePudding user response:
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.