Find batch command to copy relative path not working - batch-file

First of all, I don't know Batch programming at all. I came across a FIND command in a tutorial I was reading about OpenCV
http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html
find ./positive_images -iname "*.jpg" > positives.txt
It basically is supposed to copy all the relative paths of all the jpeg files inside positive_images directory to positives.txt file. I ran this in CMD(as Administrator) and got the following:
What is the meaning of Access Denied? I don't want to learn Batch Programming for this as I am already busy in my project. Please give me a simple-to-understand solution.

The referred tutorial uses the bash find command.But you're executing the Windows find command.Download from somewhere the windows port for the unix command put it in your directory and call it like
.\find.exe .\positive_images -iname "*.jpg" > positives.txt
mind also the windows path separator slashes.
you can use this port for example -> http://unxutils.sourceforge.net/
(probably there's a newer port but this should do the work)

Related

Creating mongoDB alias with .bash_profile on the cmder is not working

this is my first ever question. Okay..
Relevant to this problem :
I am using cmder
I am new to the terminal
I am using a windows PC
I'm following a tutorial on how to install mongoDB locally, after running the setup my first problem came when
On the terminal The tutor did
Cd ~
To go to the home directory but when I tried the same command on the cmder I received
The system cannot find the path specified
So I navigated manually using "cd.. " to
c:\Users\<username>
Which I think is the home directory,I created the ".bash_profile" file and saved the following commands in it
alias mongod = "/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo = "/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
But when I run the mongod or test if it's installed completely it returns
'mongod' is not recognized as an internal or external command, operable program or batch file
Please I don't know my way round the terminal that much, please be detailed with answers
Thanks in advance
alias mongod="/c/Program\ Files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/server/4.4/bin/mongo.exe"
Removing spaces and making uppercase the first letters of program files worked for me.
cmder doesn't interpret shell arguments like ~, which means tilde won't work in paths. Also, be aware the way you spelled Cd. It can cause an error in other command line tools (case sensitive ones like Git Bash).
1 - If you're using cmder/cmd.
Use doskey to create an alias/shortcut:
Create C:\bat\macros.txt to store your macros/aliases and paste:
cdhome=cd /d %HOMEDRIVE%%HOMEPATH%
mongo="C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" $*
mongod="C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" $*
Rename everything you want but %HOMEDRIVE%%HOMEPATH%. $* at the end means the command accepts arguments, like mongo --version.
Keep in mind that .bash_profile isn't related with cmder/cmd, that's why your mongo commands are there too.
Then Windows + R and type regedit.
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\
Right-click and add a new "String Value". Name it Autorun.
Right-click it and modify the value data to DOSKEY /MACROFILE="C:\bat\macros.txt"
2 - If you're using Git Bash, Hyper terminal, etc.
On .bash_profile, just remove the spaces around the equals sign. Like:
alias mongod="/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
or on Windows, you can just go to System properties/Advanced/Environment Variables. Under System variables, find the Variable called Path. Click edit, then New and paste in the path of the mongoDB bin folder:
C:\Program Files\MongoDB\Server\4.4\bin
keep in mind to write version your mongodb correctly in path, now its 4.4
By adding a path to the path variable you can access the .exe files from that path no matter where you are in the directory. It serves the same purpose as the .bash_profile file. Doing it this way allows this to work with windows cmd prompt or cmder as well. Upon launching, the bash emulator gets the environment variables from Windows anyways.
After adding the mongoDB path, open cmd prompt or any bash emulator and type in mongo. It will load up mongo.exe regardless of your current working directory.
Be Specific about the spaces after alias.
alias alias_name ="path.."
I faced alot of issues despite so many answers so this worked for me.
1.First install git and hyper terminal
2.Click the '~' sign to enter the home directory and then make a new file ".bash_profile"
Enter the command "vim .bash_profile"
Now enter 'i' key to enter the insert mode
Copy paste the exact command below:
alias mongod="C:/Program\ Files/MongoDB/Server/5.0/bin/mongod.exe"
alias mongo="C:/Program\ Files/MongoDB/Server/5.0/bin/mongo.exe"
(make sure that you use forward slash '/' for path and "\" backward slash to indicate space between program and files)
enter esc
write the command ':wq!' and click enter
restart hyper terminal and check the installation by running the command 'mongo --version'
Use git bash instead of CMDER
OR
Try to install mongosh from this link:
[1]: https://www.mongodb.com/try/download/shell?jmp=docs
And after setup go to hyper terminal and write mongosh => to connect to MongoDB on port 27017 and then you will see => test>
now you are ready to use the Database and you can write help to see Shell Help.
Check if mongo.exe or mongod.exe files are exist. In my case the bin directory had mongos.exe instead of mongo.exe.

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

'ls' is not recognized as an internal or external command, operable program or batch file.
I get this error when I try to glance at the files of my folder.
cmd opened regularly(not as an admin).
I've recently downloaded anaconda for python.During the installation process, there was a time when I allowed to add a PATH which was not recommended.
'ls' used to work well be
Here are the paths
I'm fairly certain that the ls command is for Linux, not Windows (I'm assuming you're using Windows as you referred to cmd, which is the command line for the Windows OS).
You should use dir instead, which is the Windows equivalent of ls.
Edit (since this post seems to be getting so many views :) ):
You can't use ls on cmd as it's not shipped with Windows, but you can use it on other terminal programs (such as GitBash). Note, ls might work on some FTP servers if the servers are linux based and the FTP is being used from cmd.
dir on Windows is similar to ls. To find out the various options available, just do dir/?.
If you really want to use ls, you could install 3rd party tools to allow you to run unix commands on Windows. Such a program is Microsoft Windows Subsystem for Linux (link to docs).
We can use ls and many other Linux commands in Windows cmd. Just follow these steps.
Steps:
1) Install Git in your computer - https://git-scm.com/downloads.
2) After installing Git, go to the folder in which Git is installed.
Mostly it will be in C drive and then Program Files Folder.
3) In Program Files folder, you will find the folder named Git, find the bin folder
which is inside usr folder in the Git folder.
In my case, the location for bin folder was - C:\Program Files\Git\usr\bin
4) Add this location (C:\Program Files\Git\usr\bin) in path variable, in system
environment variables.
5) You are done. Restart cmd and try to run ls and other Linux commands.
you can use dir instead of ls in cmd
If you want to use Unix shell commands on Windows, you can use Windows Powershell, which includes both Windows and Unix commands as aliases. You can find more info on it in the documentation.
PowerShell supports aliases to refer to commands by alternate names.
Aliasing allows users with experience in other shells to use common
command names that they already know for similar operations in
PowerShell.
The PowerShell equivalents may not produce identical results. However,
the results are close enough that users can do work without knowing
the PowerShell command name.
when you use windows as operating system you should write dir
and you will find all folders including empty folders and their data bytes storage
and you can use git ls-files to show all folders but not including hidden folders
The reason you cannot run the ls command is because it does not exist on windows. The windows equivalent is the dir command, however it does not work the same way. The solution, Winls. It is
The ls command, written for windows.
According the the Winls github.
Had this error because i was using command prompt to access my files.
how did i solve it...
i opened my folder with vscode, and used bash from the terminal...the "ls" command worked as it should from bash.

Failing at Using PUSHD/POPD on Multiple Directories

I am automating a file download thorough CuteFTP using VBScript. At the end of the VBScript I am calling a batch file that will use 7zip's CLI to expand the zip file.
The batch file and the 7zip executable are stored on Server1 (nt950id3). The expansion takes place on Server2 (nt950a1). Due to corporate restrictions, this cannot be changed. Since the VBS is working, I have omitted its code. This is the batch command-
"\\nt950id3\c$\apps\CFI\7zip\7za.exe" e -y "\\nt950a1\filexfr$\Spectrum\File.zip" -o"\\nt950a1\filexfr$\Spectrum"
Expansion is accomplished awkwardly because 7zip will extract to the CWD of the batch file, as opposed to the directory the zip file is in unless I specify the -o switch.
When I double-click the batch file or run it via a scheduled task, it works just peachy. When VBScript calls the batch file, it fails stating UNC paths are not supported - I did not know there would be a difference. PUSHD and POPD should fix this.
Further research through this post on CLI Crash Course lead me to use PUSHD on each directory and set them as variables-
SET UZEXE=PUSHD "\\nt950id3\c$\apps\CFI\7zip\7za.exe"
SET ZSRC=PUSHD "\\nt950a1\filexfr$\Spectrum\File.zip"
SET ZEDST=PUSHD "\\nt950a1\filexfr$\Spectrum"
At the bottom of the code I use 'POPD' three times (also attempted at the end of each line) and despite having this very simple SO post on setting paths I am unable to make this work. I also attempted this without PUSHD-
SET UZEXE="\\nt950id3\c$\apps\CFI\7zip\7za.exe"
This also failed stating UNC paths are not supported.
Could the community kindly explain my errors and point me towards an example of how I can accomplish running a command using multiple, separate PUSHD/POPD directories?
Following Bill's guidance, I used only VBS - no calls to batch - for my issue. I was not aware this was so easily possible and will endeavor to do better research going forward. The working code - with stand-in UNC paths - is as follows:
Set wshShell = CreateObject("wscript.shell")
wshShell.Run"""\\server1\path\7z.exe"" e -y ""\\server1\path\srcfile.zip"" -o\\server2\path\unzipdest", 0, True
At first, the executing code stated it could not find the file. This turned out to be an issue with white space in the file paths. After using this Google groups topic to learn to properly place the quotes, it is now working within the CuteFTP script with no errors.

Cygwin ssh - Identity file not accessible

I've been trying to make ssh connection using Cygwin, but it doesn't recognize my id_rsa public key file.
My command lines are as follows:
$ssh XXX#XXX -i /home/XXX/.ssh/id_rsa
Warning: Identity file /home/XXX/.ssh/id_rsa not accessible: No such file or directory.
Permission denied (publickey,XXX).
(Sorry, I used XXX for the private information.)
I copied my .pub file to C:\cygwin\home\XXX.ssh folder. But it still spits out the same error message.
Thank you so much in advance.
Background
Most cygwin executables, map Unix path /home/XXX/.ssh/id_rsa to Windows path C:\cygwin64\home\XXX\.ssh\id_rsa. Except that ssh.exe maps the same Unix path to Windows path C:\home\XXX\.ssh\id_rsa.
That is if you do cat ~/.ssh/id_rsa, it will print out the contents of C:\cygwin64\home\XXX\.ssh\id_rsa, but if you do ssh XXX#XXX -i /home/XXX/.ssh/id_rsa it will try to read the key from C:\home\XXX\.ssh\id_rsa.
I assume this is bug in Cygwin. In any event, this is a workaround that worked for me (on Windows 10 and the latest version of Cygwin as of October 2020).
Solution
Open Administrator command prompt. Go to C:\ and issue the command mklink /D home c:\cygwin64\home
That's it.
But for me tat least, once I solved the above problem, I started getting the problem described in this Superuser question https://superuser.com/questions/1296024/windows-ssh-permissions-for-private-key-are-too-open. I used the solution from the most upvoted answer and ssh finally worked for me.
From your post it looks like SSH is looking for /home/XXX/.ssh/id_rsa and is not finding it. Ensure that the .pub file you copied is named correctly and has the right permissions.
Try putting the option before the hostname...

Windows: script/program for USB key that opens a console, and sets the path and the working directory

The goal behind this question is to create a portable Windows script/program that would help users run (console) programs directly from a USB key (not necessarily through autorun, though). The script/program would thus do the following when double clicked on:
Launch a console (cmd would do) and give a DOS command prompt,
Have the current directory set to a specific directory WorkingDir on the USB key (which contains various [Python] programs),
Set the path so that the user can run a command (python.exe) found in another USB key directory (so that the user can launch various Python programs found in WorkingDir).
The whole thing is based on Portable Python, which is on the USB key. I would also like to be able to simply put the contents of the key on a hard drive and use it from there.
I tried to write a file that contains commands like:
PATH=..\"Portable Python 2.7.2.1\App":%PATH%
cd WorkingDir
cmd
but I'm not sure how to call it so that Windows runs it (and I was therefore not able to see whether these command would work).
I don't know much about DOS and Windows, so any help would be much appreciated!
Actually, in windows you use ; for separating paths :) And you shouldn't use .. like that. You can use %CD% to get current directory and then navigate from it. And don't use quotes. Also, you could put # before any command that you don't wish to be echoed to the console.
You can put this into run.bat (this should work :P):
#PATH=%PATH%;%CD%\..\Portable Python 2.7.2.1\App
#cd WorkingDir
#cmd
And then just double click it and it will open commmand prompt just as you want it. Or maybe you can add autorun.inf file to open it automatically.
You need to create two files:
autorun.inf
[autorun]
open=cmd.exe "Python Console" /k autorun.cmd
action=Open Python Console...
autorun.cmd
#Echo Off
CD %~d0\WorkingDir
Path %Path%;%~d0\Portable Python 2.7.2.1\App
The phrase %~d0 represents the drive the command file resides, namely the flash drive's letter (E:).
Now, I encountered two slight hiccups. My USB drive had a hidden, system, readonly autorun.inf file on it already. I had to unprotect it with the following command before I could edit it.
Attrib autorun.inf -r -s -h
My second hiccup, is that Windows 7 won't autorun from a USB drive. You have to right-click the drive in Explorer and select "Run Python Console..."

Resources