6

I started to study Solaris in my university. Teacher told me to remove a file with mv command.
I tried to move a file to /dev/null. But that did not work.

How can I remove file with mv command?

  • 2
    Are you sure your teacher isn't joking, or just mixed up mv and rm? Moving a file to /dev/null can only damage /dev/null, it won't delete the file. – John WH Smith Oct 24 '14 at 6:21
  • @JohnWHSmith Teacher isn't joking. He said that it's very easy. I don't know, may be he means to use not only mv command – Nikolay Bildeyko Oct 24 '14 at 7:12
  • Must be the most stupid exercise ever given by a teacher. Please ask him what he's smoking. Must be doggone good stuff. – syntaxerror Nov 21 '14 at 10:24
  • The question is not so bad, it did make some people think and try something which may have been the intention. Anyway, do we answer other people's homework here? – Ned64 Apr 23 '17 at 21:41
17
mv other-file file-to-be-deleted
mv file-to-be-deleted other-file
5

Here is a (dumb) way to remove your file using mv:

mv file /tmp
init 6

Of course, rm file is significantly faster, more efficient and reliable, and less intrusive.

2

rm unlinks your file, and it'll be really hard to get it back.

Perhaps your teacher means something like:

mv myfile  ~/.trash   

(After first having done a mkdir ~/.trash of course )

This does a “move to trash” like you see on Windows and OSX (and some linux desktops), instead of unlinking the file.

Later, you can then cd ~/.trash and find your file.

1

Something is removed if it is no longer there where it used to be, that doesn't necessarily imply that it no longer exists or is inaccessible via other means. Both when using computers and in real life we often remove things by first moving them to the trash, from where it still can be retrieved.

Literally a simple

 mv filename ../some_other_directory_next_to_the_one_you_re_in/filename

already removes the file (from your current directory).

If you need to remove the file from your computer using mv you can, if networked, use mv to move the file to a different computer and assign it a new name (mv filename /mountpoint/otherfilename gives you a different file otherfilename on the remote system which happens to have the same content as your original filename)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.