i bought a course from codecademy and at beginner was a lesson about git bash. I install it , but if i want to change directories with "cd" i cant't.
enter image description here
Also , when i double-click on shortcut the program doesn't run.
Try changing to you home directory first
$ cd
then
$ pwd
/c/Users/yourname
Try going to you root directory with : cd / (make sure you add a space between cd and /)
Then do cd yourfilename/yourfilename....you can add multiple directories
Make sure your spelling is correct
Few other tips :
To navigate to your home directory use "cd ~".
To navigate to the previous directory use "cd -"
I am using ubuntu 16.04 and created a virtual environment called 'tensorflow1' as shown above. I am using putty to access a machine remotely. So I was trying to change directory by typing "cd /tensorflow1/models/research" but it says "-bash: cd: /tensorflow1: No such file or directory" in ubuntu, but the file is there. I typed "ls" and it also shows the file. Why is it so?
When you type ls you see the content of the current directory. When you type cd /tensorflow1 you're trying to enter a directory tensorflow1 at the root (/) of the filesystem and the directory is certainly not there. You just need
cd tensorflow1/models/research
to enter a subdirectory of the current directory. Or
cd ./tensorflow1/models/research
because . means "the current directory".
You probably want cd ./tensorflow1/models/research or just cd tensorflow1/models/research.
Read about root directory, home directory, working directory then about path_resolution(7)
How can I change my working directory in bash script in windows. I have
~dp0 = C:\test\docker\windows and I want to change my directory to C:\test\build
So it means 2 levels up and then int o build folder
Thanks
Since C:\ is mounted by default into /mnt/c this will work.
Create a .bashrc in your home path by following command:
echo "BUILDDIR=/mnt/c/test/build" >> ~/.bashrc;source ~/.bashrc
cd $BUILDDIR
# Do your work below for example ./configure.
./configure
On my system in Git bash the C:\ root is just /c/ and other dirs from there are whatever they are, so it would be cd /c/test/build/.
You could also still say cd ../../build/.
Good luck.
To change the directory using a bash script is just like you would using normal bash.
cd "C:/test/build"
echo "You're now in the folder, do what you will."
Save the file as .sh and it can be used as such.
Note, when navigation your folders using a bash script remember the directory you'll be starting from is always the home directory.
I have installed MinGW-w64 and MSYS2. But how do I change the HOME directory in MSYS2? So that when I type cd $home or cd ~ it goes to another directory that I defined.
And how do I write a code so that the starting directory is always where the .bat file is placed on?
In cmd I used this code:
%~d1
cd "%~p1"
call cmd
so when I open cmd on my desktop, it starts from the directory on desktop.
How can I do a similar thing with msys2?
If you would like to use your windows home folder as the home folder for MSYS2, you can edit /etc/nsswitch.conf and write:
db_home: windows
Msys2 will use windows %HOME% as it's $HOME dir. If you set %HOME% in environment variables (to the windows directory you need Msys2 to use) it will work.
I prefer to just update /etc/fstab
# fstab.
# cat /etc/fstab
# For a description of the file format, see the Users Guide
# https://cygwin.com/cygwin-ug-net/using.html#mount-table
# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
##################################################################
# Canonicalize the two home directories by mounting the windows #
# user home with the same path mapping as unix. #
##################################################################
none /c/Users/Edward /home/Edward binary,posix=0,noacl,user 0 0
In one of your shell startup scripts (e.g. ~/.bash_profile where ~ is the default/original home directory) you can change the $HOME environment variable:
export HOME=/something/else
If you want your shell to open in that directory you might need to run cd (with no arguments) after setting $HOME; I have not tested it.
Besides the above anwsers, there is another way using the Windows command mklink to make a directory symbol link, similar to ln of Linux.
First make a directory of e:\msys\home, then run cmd as Administrator, then run:
cd c:\msys64
mklink /j home e:\msys\home
no other change required.
Occasionally after specific base updates, the link got invalid, need to be made once again, after the newly generated 'home' directory cleared or renamed.
Create or modify an MSYS2 /etc/passwd file. Two ways of doing this are shown below.
The following command can be run from an MSYS2 shell, and works safely whether or not the file exists and whether or not it already contains the current user:
$ grep "^${USERNAME}:" /etc/passwd >/dev/null 2>&1 || mkpasswd | grep "^${USERNAME}:" >>/etc/passwd
Next, edit /etc/passwd, and change the relevant user's home directory field (the 6th colon-delimited field).
$ vim /etc/passwd
BONUS: It is also possible to change the MSYS2 username by editing the first field.
As desired, move current home directory content to the new home directory.
Log off, then log back in.
The /etc/passwd edits can be done without manual editing, but this makes for a more complex command-line to paste into the MSYS2 shell, and, it might not work if the /etc/passwd file already exists and has the username in it already:
__DIR="/path/to/home"
mkpasswd | grep "^${USERNAME}:" | \
awk -v DIR="${__DIR}" -v RS=":" -v ORS="/n" \
'NR == 6 { printf(DIR ":"); next } { printf("%s", $0) } NR < 7 { printf(":") }' - >>/etc/passwd
I add HOME='E:/Users/your_directory' in /etc/profile. It looks as follows:
...
# Setup some default paths. Note that this order will allow user installed
# software to override 'system' software.
# Modifying these default path settings can be done in different ways.
# To learn more about startup files, refer to your shell's man page.
MSYS2_PATH="/usr/local/bin:/usr/bin:/bin"
MANPATH='/usr/local/man:/usr/share/man:/usr/man:/share/man'
INFOPATH='/usr/local/info:/usr/share/info:/usr/info:/share/info'
HOME='e:/Users/HP'
case "${MSYS2_PATH_TYPE:-minimal}" in
...
but the shell shows the path fully, not just ~.
I've created a batch file which sets the HOME variable:
set HOME=C:\Users\%USERNAME%
C:\LocalApp\PortableGit\git-bash.exe
This allows me to put my .bash_profile in this HOME (rather than on the default network location which performs very slowly).
I am using cygwin and I am trying to set up an .ssh/config file. Cygwin's folder is in my C: drive. My Home directory is C:\Users\USER. I have noticed that when I edit C:\Users\USER.ssh\config, cygwin does not even notice it (even though it notices the other files I have in my USER folder, i.e. .bashrc). But it does notice the config file if I put it in C:\cygwin64\home\USER.ssh\config.
Is there a way to get cygwin to read the .ssh folder in my USER home directory instead?
Make sure your home directory setup in /etc/passwd matches /home/ Often it is not set at all (second to last field in the ':' delimited line. Then you'll need to restart your cygwin session (exit the terminal, and restart)
That should fix your problem.
This isn't the greatest solution but it works:
ln -s /cygdrive/c/Users/username/.ssh /home/username/.ssh
If /home/username/.ssh already exists, perhaps rename it to .ssh_original or move the files into the other .ssh folder.