1.

Solve : Moving versus copying files and directories?

Answer»

Still playing AROUND with SSH.

I have some directories and files I'd like to move.

I figure I can either copy (cp) or move (mv) them.

Which is more practical?

I think moving would work better. But I am concerned about loosing files. So if I copy then delete afterwards.....

I get the cp command syntax. But am a bit murky on the mv syntax.

Comments?

Les

Use mv: there is no chance of losing files on the way, trust me. It is far quicker to mv a directory than to do a recusrive cp then delete - it's one file operation (changing the file index) rather than many. The only time mv will take longer is when you're moving between filesystems - i.e. if the files will end up on a different PHYSICAL disk, then a full recursive copy will be done behind the scenes. Even then, files will only be deleted once a succesful copy has TAKEN place.Quote

Use mv: there is no chance of losing files on the way, trust me. It is far quicker to mv a directory than to do a recusrive cp then delete - it's one file operation (changing the file index) rather than many. The only time mv will take longer is when you're moving between filesystems - i.e. if the files will end up on a different physical disk, then a full recursive copy will be done behind the scenes. Even then, files will only be deleted once a succesful copy has taken place.

Hi Rob - Okay that makes sense.

So for instance the directories I want to move are actually in the directory I want to move them to.... DUH! I want to move them up 1 level. Let me explain ---- My host's structure is /domains/sitename/html. I erroneously decompressed my archive so that all my files (2.5 gigs worth) are in /domains/sitename/html/public_html. In other words all the directories and files in /domains/sitename/html/public_html need to get moved into /domains/sitename/html (back on level). Can this be done?

Les

PS Still chuckling about your tar & feather quip.
Yep: cd /domains/sitename/html/public_html
mv * ..

".." means the directory above the current working directory.Quote
Yep: cd /domains/sitename/html/public_html
mv * ..

".." means the directory above the current working directory.

Hi Rob - So basically the "*" captures all files and directories and the ".." indicates a step back? Wow, this is simply too cool.

I still remember having to learn UNIX back in 1988 when I WORKED at AT&T. Pipes - it was all about pipes.

I appreciate the tutelage. You are prodding me into exploring and learning more.

Les
Yep, that's it. At a shell prompt, "*" represents any number of any characters (including zero characters), whereas "?" represents any single character. E.g. "*cat*" would match all of the following:

cat
cathode
fatcat
escatologyQuote
Yep, that's it. At a shell prompt, "*" represents any number of any characters (including zero characters), whereas "?" represents any single character. E.g. "*cat*" would match all of the following:

cat
cathode
fatcat
escatology

Perfect! I followed your instructions and it worked purrrrrfectly!

Les

PS Thanks again Rob!No PROBLEM. I hope you continue to enjoy working with Linux. Quote
No problem. I hope you continue to enjoy working with Linux.

I will - Linux is just Unix with a nice change of clothes!

Les Quote
Yep, that's it. At a shell prompt, "*" represents any number of any characters (including zero characters), whereas "?" represents any single character. E.g. "*cat*" would match all of the following:

cat
cathode
fatcat
escatology

I know that this solved your problem, but for completeness I thought you might like to know about the hidden files ...

Sometimes directories contain hidden files which start with a dot, such as .mozilla or .bash_history (find them with ls -a).

A simple * won't match those files but don't ever use .* [/tt]because that matches the current and parent directories, and you can seriously screw up the whole machine by accidently deleting the root directory! I've never seen anyone use a single-letter dot file, so use .??* to match your dot files.

e.g.
Code: [Select]mv * .??* ..
Quote
Quote
Yep, that's it. At a shell prompt, "*" represents any number of any characters (including zero characters), whereas "?" represents any single character. E.g. "*cat*" would match all of the following:

cat
cathode
fatcat
escatology

I know that this solved your problem, but for completeness I thought you might like to know about the hidden files ...

Sometimes directories contain hidden files which start with a dot, such as .mozilla or .bash_history (find them with ls -a).

A simple * won't match those files but don't ever use .* [/tt]because that matches the current and parent directories, and you can seriously screw up the whole machine by accidently deleting the root directory! I've never seen anyone use a single-letter dot file, so use .??* to match your dot files.

e.g.
Code: [Select]mv * .??* ..

Thanks a bunch as a fellow like me would sooner or later try exactly what you mention!

Les


Discussion

No Comment Found