Help - What happens when you give the following commands if the file named done alrea
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Those two commands (executed in a temporary directory, with a copy of a file) are
perfectly harmless. I recommend you TRY them - and then report your findings
back; both here and to your teacher, maybe?
A great idea for learning about Linux, would be to download & burn a LiveCD that you can boot and play with and learn with; you would not even need to install it if you don't want to - just boot it up and use it, and when you're done, you can shut down, remove the CD, and your computer is exactly as it was before you used the CD.
Nice LiveCD distros for beginners to Linux are Ubuntu and Mint, just as 2 examples.
Plus you could have answered your own question. If you have a computer (how'd you get here if you don't?). And have a blank optical media or thumb drive. And probably in less time that it took to post the question.
But to answer your question, IT DEPENDS.
There are flags to NOT overwrite existing files. Whether or not they are enabled via an alias on your system DEPENDS. If that's a test question, then your teacher is an idiot. As BOTH answers are, from a certain POV, correct. Or it's an easy A as you can do no wrong.
In the meantime go out into the wilderness and learn.
I thank you guys for being so nice about it, as I have just found out I have triple negative cancer, and I am just trying to get a little help, I really did not feel up to spending much time on this project, as I have to start my first chemo in the morning, so I guess right now I am feeling like an idiot and dont really care.
What happens when you give the following commands if the file named done already exists?
o $ cp to_do done
o $ mv to_do don
If the two commands are not setup with aliases, the file(s) would be overwritten. I assumed you meant to spell done instead of don.
Some distros will have commands setup with an aliases to warn you that it will overwrite or delete files before doing so. And some distros will not. In the bash shell the alias would look like this.
alias cp='cp -i'
alias mv='cp -i'
The -i is interactive mode, which means it will ask permission before doing the action.
If you don't want to be asked and still prevent overwriting add
the -n, --no-clobber option. Do not overwrite an existing file.
Tip
Have you ever hosed important files by using > when you meant to use >>
Add set -o noclobber to your /etc/bashrc or your hidden .bashrc in your home directory.
To disable noclobber so you can overwrite or append data to the file, use set +o noclobber
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.