2

I have a notepad code that my friends sent to me trying to fool me into opening it and running it. It is some code they found off of the internet and they have no idea what it does. Here it is:

@echo off
Del C:\ *.* |y

Can someone please explain to me what this does? It would be greatly appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
James Kropp
  • 33
  • 1
  • 4
  • 1
    `@echo off` just makes it quiet, so you won't see the next command. `Del` just deletes, so `C:\` will be deleted, which is hard drive. I would expect adding a `/S`, so all the subfolders will be deleted, too. But the Computer won't start after it, I think. – flaschenpost Aug 28 '15 at 22:55
  • It would delete all the files in your root folder, hiding what it does, and skipping any confirmation prompt. So don't execute it! – E. Serrano Aug 28 '15 at 22:55
  • "they have no idea what it does". Oh, I think they probably do. Are you sure they're really "friends"? – paulsm4 Aug 28 '15 at 23:02
  • does it _really_ read `|y`, or is it perhaps `/y`? the latter would make more sense to me (delete without prompting)... – aschipfl Aug 29 '15 at 13:48
  • @aschipfl If `/y` would have been used, the result would be also an error message: `Invalid option - "Y".` because command [del](https://technet.microsoft.com/en-us/library/cc771049.aspx) does not support `/Y` like __copy__ or __move__. __del__ and __rd__ require `/Q` for a quiet (non prompt) deletion of files and folders. – Mofi Aug 30 '15 at 17:03
  • you're right, @Mofi, I confused the switches and commands, sorry... anyway, I recognised a space in between `C:\` and `*.*`, so `del` is instructed to delete the root dir. of drive `C:` (which should result in an error anyway), and then every files in the current directory... – aschipfl Aug 31 '15 at 05:10

3 Answers3

2

It will do nothing except create an error message:

'y' is not recognized as an internal or external command,
operable program or batch file.
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • 1
    Yes, exactly that happens as `| Y` is a completely wrong method to disable confirmation on deleting files using wildcards. – Mofi Aug 29 '15 at 10:31
1

del deletes files. c:\ is where you run it, and *.* is the file pattern to delete - i.e., all of them. This is piped into y, which simply answers yes to any confirmation message.

TL;DR - don't run scripts from sources you don't trust.

Bond
  • 16,071
  • 6
  • 30
  • 53
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • That explanation is incorrect. [foxdrive](http://stackoverflow.com/users/2299431/foxidrive) was the only one which gave the correct answer. Using __del__ parameter `/Q` would suppress user confirmation, but luckily the "friends" of the questioner were too silly to run in a command prompt window `del /?` and read the output help. – Mofi Aug 29 '15 at 10:36
0

.Bat files are also known as Batch files.

As @foxidrive pointed out, this example will result in

'y' is not recognized as an internal or external command, operable program or batch file.

Basically it is a file that contains runnable script on your computer, often used for automating some routines.

Now what your script does.

@echo off - turn off the output, often used on top of the script files.

Del C:\ *.* |y - Delete all files in directory "C:\", and confirm any popup.

This script is very dangerous, but it's not as harmful as if you run it as Administrator. At that point it would delete a lot of System files (Not all of them, it would not delete any running file or file owned by System user or TrustedInstaller), but really, do not try running it on your computer.

  • Also that explanation is partly not correct. [foxdrive](http://stackoverflow.com/users/2299431/foxidrive) was the only one which gave the correct answer regarding line with command __del__. – Mofi Aug 29 '15 at 10:40