I'm looking at a batch file and I see the line below. I know what %LOG% is, but I do not know what the "rm" command is doing. Can anyone tell me?
rm "%LOG%"
rm is a commandlet in Windows Powershell.
NAME:
Remove-Item
SYNOPSIS:
Deletes the specified items.
DESCRIPTION:
The Remove-Item cmdlet deletes one or more items. Because it is supported
by many providers, it can delete many
different types of items, including
files, directories, registry keys,
variables, aliases, and functions.
%LOG% is a variable defined in that batch file using
set LOG="Something"
(NOTE: It is not a global Variable or alias)
So what it will do is delete the item pointed by variable LOG.
The rm is a command that's being run, rather than anything special for the batch file. Does the system which ran this batch file include the cygwin package? That provides Windows / DOS versions of various standard unix utilities, including rm - which is the remove command - similar to del on such boxes.
%LOG% - variable that contain path to log file and that command remove it.
rm is not a standard ms-dos command. If you type it on the command line, what comes up?
perhaps it is short for rmdir (a synonym of rd) which removes the specified directory.
rm is the *NIX version of del
so its deleting %LOG%, unless it fails b/s its not a command on Windows. ( PowwerShell maybe)
Even if this is not Unix, rm is going to be a command to delete a file. For example, see http://www.mkssoftware.com/docs/man1/rm.1.asp or http://www.cygwin.com/
Related
I made this script below to make a backup of some files. It works fine, but i wanted make a list for the files that need be skipped from compressing.
For example:
my list.txt has all the files that will be compressed. But i wanted to make another list for the files that need be skipped, like exclusion_list.txt. Actually i put all files that i want be ignored from compressing into the command line, as shown below -x*\Test1 -x*\Test2.
But i really wanted to make a exclusion list for not keep changing the command line everytime i need to exclude a file or folder.
How i can do it?
"%winrar%\winrar.exe" a -x*\Test1 -x*\Test2 -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
From the documentation: the exclusion option -x also supports a list file when it is preceded by #:
"%winrar%\winrar.exe" a -x#exclusion_list.txt -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
with the file exclusion_list.txt containing:
*\Test1
*\Test2
By the way, there is even a console version of WinRAR, called rar.exe, which is a non-GUI version.
I'm currently trying to set up a batch file or something similar to run a search through a series of different file shares at my workplace.
I'm fairly new with CMD, but have managed to get what I'm looking for in one instance, and I'm now looking to apply that through several different files at once.
C:\Users\My Username> dir c:\Users\My Username\documents -path \appdata -prune -o *.xml /b /s >c:\users\My Username\documents\Filename
Above is the code I'm using currently to source from one file, omitting the Appdata file, as that was being returned & I didn't want its contents in the output.
However, this code above is simply a test that I've used; my end goal is to apply that to several different files accessible through the company, so for example,
DriveLetter:\SiteLocationFolder\SpecificFileShare\> dir DL:\SLF\SFS\ -path \UselessFolder -prune -o *xml /b /s >DL:\SLF\FileShareReportsFolder\
For the sake of anonymity, I've substituted in placeholder names in the file path.
My issue exists in that, in the Site Location Folder, all of the Specific File Shares are accessed through shortcuts, and I was wondering whether there was a string to allow CMD to run the dir through these shortcuts, or if I would instead have to run the batch file for each different Specific File Share?
The cmd.exe shell DIR command will not follow shortcuts in the same way as a link. If you must use Windows shortcuts, you might need to look into https://www.computerhope.com/forum/index.php?topic=80659.0
Another way would be to make links using the Windows mklink command. Use mklink /? to read about it. Search the net to learn the differences between links and junctions.
I have a undoubtedly silly problem. I need to change the attribute of a file to read only. I know to use...
atrrib +r c:\somefile.txt
And it works. However in my program I want to use a variable in place of the path to be built up beforehand. Now if I write...
set File=c:\somefile.txt
attrib +r %File%
Then I get an error saying 'attrib' is not recognized as an internal or external command etc.
However if I echo %File% beforehand then I know the path to the file is correct and being read properly.
What is my error? Thanks a lot!!!
Edit:
set File=Main.xaml
set Folder=C:\Users\yef03111\Desktop\His0164\WINDOW\ALS026-01~EDF
set Path=%Folder%\%File%
echo %Path%
However if I change the echo to attrib +r and nothing else...
attrib +r %Path%
I get the 'attrib' not recognized error. This is the current example that is not working. Hope you can spot something from it!
The problem is that you are setting an environment variable called PATH. This is overwriting the system PATH variable which contains the location of the executable files such as attrib. The way it works is that in order to find a program to run, the OS looks up the PATH variable and searches in the folders listed there for executable files with the name of the program you are trying to run. When you change the PATH variable, the OS can no longer find the attrib command.
Change the name of your variable from path to filepath and it will work.
Path is a system variable that tells CMD, Explorer, and CreateProcess where to look for commands.
As you are trashing the system variable CMD no longer looks in system32 for commands like attrib.
set Path=%Folder%\%File%
As a general rule avoid likely names used by the system in naming your own things. A lot of people will do MyFile or ProgPath.
Also commands like attrib will always be found if the current directory is System32. The current directory is always searched first for commands (programs). I suspect RunAs is setting the current directory to System32.
I have tested your script using Cmd on windows 7. Works a treat, so I cant recreate what you are seeing.
I did quite a lot of batch scripting at one point, and I used to get random errors using standard windows notepad. Tell tail signs of issues in the script were whitespace characters. If you are using notepad, switch to using notepad++ to write this and see if you still get errors.
I ran a program on Windows 7 that was compiled under Cygwin and passed "NUL" as an output file name. Instead of suppressing output it actually created a file named "NUL" in the current directory. (Apparently it expects "/dev/null", even on Windows.) Now I'm stuck with this "NUL" file that I cannot delete!
I've already tried:
Windows Explorer - error: "Invalid MS-DOS function" (yes, that is seriously what it says!)
Command prompt using "del NUL" - error: "The filename, directory name, or volume
label syntax is incorrect."
Deleting the entire directory - same deal as just deleting the file
remove() in a C program - also fails
How can I get rid of these NUL files (I have several by now), short of installing the full Cygwin environment and compiling a C program under Cygwin to do it?
Open a command prompt and use these commands to first rename and then delete the NUL file:
C:\> rename \\.\C:\..\NUL. deletefile.txt
C:\> del deletefile.txt
Using the \\.\ prefix tells the high-level file I/O functions to pass the filename unparsed to the device driver - this way you can access otherwise invalid names.
Read this article about valid file / path names in Windows and the various reserved names.
If you have Git for Windows Installed (v2.18) do the following
Open the directory containing the files you want to remove
Left Click and select Git Bash Here
Type rm nul.json at the command prompt and hit ENTER, the file now should be removed.
NOTE: These screenshots show the removal of file nul.topo.json which is another file that I could not removed with a simple delete.
If you have git on windows, just right click on the folder containing the nul file -> go to gitbash here -> and type "rm nul" or "rm nul.json" depending upon the file type.
I had a similar issue. It was probably caused by Cygwin as well (since I use this regularly), but I've since forgotten exactly how the file was created.
I also had trouble deleting it. I followed the advice of some other posts and tried booting into safe mode to delete the file, though this did nothing. The tip from +xxbbcc didn't work for me either.
However, I was able to delete the file using the Cygwin terminal! Cygwin createth and Cygwin destroyeth.
To remove a nul file situated here:
C:\unix\cygwin\dev\nul
I simply use (tested only on Windows 10) :
Del \?\C:\unix\cygwin\dev\NUL
I solved this in a slightly different way.
I thought I would add this here because it is high in the google results and I had a similar issue for a folder named NUL.
I tried rmdir\\?\C:\My\Path\NUL and rmdir\\.\C:\My\Path\NUL without any success and also tried several commands using bash from my SourceTree installation. No joy.
In the end I used DIR /X /A from cmd to list the short names in the parent directory. This showed me NUL~1 for my NUL folder and identified the crux of the problem.
This was then used in the standard command rmdir /s NUL~1 and finally resolved the issue.
I was having this same issue.
If you have WSL2 installed just go to that directory and run:
rm -f nul
In my case the file was lowercase. You should be good.
Try writing a short C program that calls the Windows API to delete that file.
http://msdn.microsoft.com/en-us/library/aa363915%28v=vs.85%29.aspx
If that doesn't work, try opening a handle to the file with CreateFile() with FILE_FLAG_DELETE_ON_CLOSE, and then close the handle.
I'm running an exe with multiple arguments that may or may not contain spaces. I encloses them with quotes but they are somehow not passed to the exe correctly.
Here's the command i'm using:
makeblastdb -in "D:\d b\sequence.fasta" -input_type fasta -dbtype prot -title xd -out "D:\d b\xd"
which I think cmd should pass 10 arguments to the exe but somehow it isn't passing correctly.
this is the result i get
BLAST options error: File "D:\d" does not exist.
which is basically saying that the second argument is being chopped for some reason?
Any help will be appreciated, thanks!
Based on your comments to your question, the BLAST utility does not properly handle quoted paths with spaces, and your volume does not support short file names.
Obviously you can move your working directory to a path that does not contain spaces.
An alternative is to use SUBST to temporarily create a virtual drive that points to your problematic path.
subst K: "d:\d b"
makeblastdb -in "K:\sequence.fasta" -input_type fasta -dbtype prot -title xd -out "K:\xd"
subst /d K:
Type subst /? for help with the command.
Update based on fact that you are running the command from within python
In your comment to this answer, you state you will attempt to get the command to work from within python. That could be the entire source of your problem.
You should try to run the command in your question directly from a Windows command prompt (cmd.exe console).
If the command does not work from the command prompt, then the problem is indeed with the BLAST utility, and SUBST is a good solution.
If the command does work from the command prompt, then the problem is with how you are shelling out the command from python, and the SUBST command should not be required.
I'm not a python user, but I see that many people have similar problems when using python on Windows. Perhaps this will help: How do I execute a program from python? os.system fails due to spaces in path
makeblastdb has an odd escaping convention. Try this:
-in \""D:\d b\sequence.fasta"\"
Unfortunately this doesn't work for -out, so dbenham's answer is probably best.
Alternative is you can try using directory shortname for "D:\d b" which you can find by running dir /X command on your D drive. For instance if I run dir /X on my C drive here is what I get:
01/21/2013 09:47 AM <DIR> PROGRA~1 Program Files
So you want to use C:\Program Files you can alternatively use C:\PROGRA~1.