move text files with specific name using bash on windows machine - bash

I am trying to move all text files with a specific name in them from one directory to another using bash on a windows machine in cygwin. The code is below and but I am not sure how to reference a windows path in bash. Thank you :).
for i in "C:\Users\cmccabe\Desktop\annovar"; do
mv $i"\"*multianno.txt "C:\Users\cmccabe\Desktop\all""\"basename $i`multianno.txt
done
mv: cannot stat ‘C:\\Users\\cmccabe\\Desktop\\annovar\\*multianno.txt’: No such file or directory

You should use cygpath, which is a cygwin utility for converting windows to/from cygwin paths.
Without additional arguments it will transform a given windows path to its cygwin equivalent, which is what you want :
mv $(cygpath "windows_src") $(cygpath "windows_dst")
I wasn't sure it would work with paths containing jokers, but it looks like it does :
$ cygpath "C:\path\*a*"
/cygdrive/c/path/*a*

Related

Bash cannot find any files at all [duplicate]

This question already has answers here:
Difference between ./ and ~/
(6 answers)
Closed 1 year ago.
I am quite new to using Bash, so apologies if this is a rather rudimentary question;
I am trying to open a text file in Bash, but Bash does not seem to be able to find any of my files or directories at all. Whenever I try to use the cat command or cd command (for example, cd Desktop/), no matter what file or directory I specify, Bash tells me "No such file or directory". pwd says that I am in /mnt/c/WINDOWS/system32 . ls shows me a very long list of files, but none of them are that for which I am looking. I am trying to open a .txt file on my Desktop, but neither the Desktop nor the txt file are showing up in that list. I'm running Bash via the Linux subsystem on Windows 10.
He are tips to start with WSL:
Your windows files will be found at /mnt/c/
cd /mnt/c
from here use ls to see the folders and find the files you want to use, I personally tend to put the files I use with windows subsystem for linux on the C: directory for easier use, like c:\FilesForWSL you can just create the folder on windows or cd /mnt/c and mkdir FilesForWsl then cd FilesForWsl.
After this setup anytime you want to put a file to be used by windows or from windows into linux just go to cd /mnt/c/FilesForWsl substitute FilesForWsl with your preferred folder name. Hope this clarify a little how WSL works.

Navigating with cd and assigning a directory path to a shortcut variable name in Windows Bash

Is it possible to assign a directory path to a shortcut variable name that can be used to access quickly over and over again through commands like cd?
I am navigating consistently between several directories and I would like to avoid typing out the full directory path every time. I recall having the capacity to enter the shortcut for a path to access a commonly used directory in Linux. I was wondering if it is possible to use the same cd [SHORTCUT_DIRECTORY_NAME] in Windows Git-Bash or if there is an alternative permanent solution that would limit typing out the full directory paths.
Here is an example of such command to access C:\Users\[NAME]\Documents\common directory in a linux machine shortened to com:
[USER]#DESKTOP /c/Users
$ cd com
[USER]#DESKTOP /c/Users/[NAME]/Documents/common
$
I have mostly found ways to use .bat files and I'm not sure this applies to Windows. I was thinking my next best bet would be trying to create a Shell script, but any input on the most convenient method would be greatly appreciated.
Thank you!
Environment: Windows 10, Git Bash v. 4.4.12
is this what you require:
you can assign the directory path to a string and do cd $string. Example:
sh-4.4$ dir="/home/cg/root/abc/xyz/tyh/"
sh-4.4$ pwd
/home/cg/root
sh-4.4$ cd $dir
sh-4.4$ pwd
/home/cg/root/abc/xyz/tyh

How to change directory under git bash

Could you tell me please how to change directory using git bash?
Exactly I want go to C:/Program Files
I type cd c:/ - move to c:/.
I type cd Program Files and I get message that "there is no such directory Program".
So the problem is how to go to the directory name of which consists of two words that are separated by whitespaces.
I'm using Windows 7 operating system.
cd gets just one argument, so if you say cd Program Files it does cd Program. So you need to quote Program Files if you want cd to it as just one argument:
cd "Program Files"
otherwise it is trying to find the directory Program.
You could also type the space as escape seqence:
cd /c/Program\ Files/Git/
Please find below to add windows path in git bash or in unix
export PATH=$PATH:/c/Program\ Files/Java/jdk1.8.0_221/bin:/c/Program\ Files/apache-maven-3.6.1/bin

How to send a file to Desktop with bash script?

I am trying to send a file or folder to Desktop with Linux Command Prompt but I don't know how.
Please tell me what command can I use for this?
The move command mv. Use man mv for more information, as this command is a lot more complex than it seems. With cd Desktop/ you should be able to find your desktop on variations of linux like Mint or Ubuntu. To find your present working directory, as in your current path for the terminal, type pwd. This will give you your directory which will be similar to /home/Desktop.

Location of windows command prompt command files

In Unix, the terminal commands are in /etc folder. Similarly, I'd like to know where the command files of Windows are located eg., mkdir, cd, etc. Thanks in advance.
You can use where to find where the executables are located.
Some as #sb9 said, are not separate exe's and they are built in. Using where you can find out if they have their own exe file or not.
where ftp
where at
where cd
In this case cd will error as it is built in.
Some commands are located in windows\system32, and some others (like mkdir and cd) are built in internally into the shell cmd.exe, so you won't find them on the hard disk.

Resources