I would like to find and analogue directory in Powershell.
In Linux I can use /dev/null as a directory, and anything moving there or copying there disappears:
jack@JACK-HP:/mnt/c/Users/jack$ sudo mv /mnt/f/Proba/XXX.txt /dev/null
[sudo] password for jack:
But in Powershell with $null is not possible to do the same:
PS C:\Users\jack> move-item F:\Proba\XXX.txt $null
Move-Item: Cannot process argument because the value of argument “destination” is null. Change the value of argument “destination” to a non-null value.
The examples are only for showing the problem, the real goal is to use this moving in more complicated cases.
Thank you, but as I noted, it was a symplified example to show the difference. With the Remove-Item the file is disappearing. When I copy a folder from a distant NAS, a lot of details can not be seen about the directory, and in the process of copying it with robocopy, after copying it can be an unsuitable for me because of the size, or some other case. In the process of copying or moving to /dev/null, I can receive all details of the folder, and decide download it or not. In Linux this directory is /dev/null, in windows command line it is C:\dummy. So I use this time for this purpose in windows C:\dummy, in Linux /dev/null. The problem is solved of course, it can be done in Windows command line and in Linux, too. It was only interesting me to find an analogue in Powershell. The $null is good for redirecting any output, but it can not function as a destination directory, so it is not an analogue.
So my goal with this question not to solve a problem, Powershell is very elastic and it is possible to find other ways to solve any real problems. I would like to know whether there is a 100% analogue for /dev/null or not.
I also do not have C:\dummy as it is not a real directory. But still I can “copy” there more than 1 TB data while my C drive is in only 500 GB.
See the ps1 script below:
$M = Read-Host “Enter the name of the folder to measure”
robocopy $M c:\dummy /l /xj /e /nfl /ndl /njh /r:0 /mt:64
and an example output from a synology nas folder:
Total Copied Skipped Mismatch FAILED Extras
Dirs : 263 263 0 0 0 0
Files : 3268 3268 0 0 0 0
Bytes : 1.039 t 1.039 t 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Saturday, November 20, 2021 6:13:12 PM
So I have a lot of information about a distant folder, while my “C” drive is only 0.5 TB
It is not a 100% analogue to /dev/null but a good solution for people who are new to Powershell but use CMD for a lot of years. For a time it is easier while studying Powershell and find solution on a “real Powershell way”.