/cygdrive path is broken - cygwin

My cygwin used to work properly before, but suddenly it starts to complain: "file does not exist" under /cygdrive/d ...
The problem looks like this: if I cd to that folder I can saw that file and cat/ls afile without any problem, but if I use something like ls /cygdrive/d/afile it will complain "file does not exist".
So I traced backwards on the file system, and found there's some issue with the virtual path /cygdrive
/cygdrive
cd /cygdrive/
Error: Current working directory is a virtual Cygwin directory which
does not exist for a native Windows application. Can't start native
Windows application from here.
Seems this /cygdrive is broken, does anyone know how to fix it?
Adding more detail:
$grep cygdrive /etc/fstab
# none /cygdrive cygdrive binary,posix=0,user 0 0
$type -a cd
#cd is a shell builtin

I get that error message if I do a cd /cygdrive and then try to execute a (non-Cygwin) Windows command. I don't get it if I just cd /cygdrive.
The only explanation I can think of is that you've assigned a value to the bash special variable $PROMPT_COMMAND.
Quoting the bash documentation:
'PROMPT_COMMAND'
If set, the value is interpreted as a command to execute before
the printing of each primary prompt ('$PS1').
For example:
$ PROMPT_COMMAND=cmd.exe ; cd /cygdrive
Error: Current working directory is a virtual Cygwin directory which does
not exist for a native Windows application.
Can't start native Windows application from here.
-bash: /cygdrive/c/Windows/system32/cmd.exe: Not a directory

move to the right directory by replacing (if you are in C drive for example)
cd /cygdrive
by
cd c:/cygdrive
also suitable:
cd /c/<rest of your path>

Related

How do I move files out of a broken directory in linux?

I know the premise of the question may be confusing, but I want to understand what happened.
Recently I have been experimenting with the rockchip OK3399 single-chip computer(see here) and have installed a linux system on it with TF card installation. Using Putty and connecting with serial protocol, I was able to establish a connection with the OK3399 computer and control it through my laptop.
I am trying to self-learn some linux with the OK3399 system. I created a bash code by the name of displayvids.sh inside the directory /usr/bin, which is meant to take a variable number of pictures with a mipi camera and then save in a directory for work.
I finished writing the code, but for some reason I cannot run the .sh file when my working directory is not the /usr/bin directory, despite /usr/bin being in the %PATH% environment variable. So, I executed the following command:
mv /usr/bin/display* /usr/local/bin
... attempting to move the file to /usr/local/bin instead. The command ran successfully, but when I tried to run the command:
cd /usr/local/bin
It tells me that I cannot cd to bin
As seen from the above image, the /usr/local/bin is not even a directory. Why would mv succeed if the target was not a directory? How can I retrieve my bash file?
Why would mv succeed if the target was not a directory?
mv can also rename files:
mv foo.txt bar.txt
You renamed your script to bin and moved it under /usr/local.
You may want to remember to add a trailing slash next time, to have mv barf if the target isn't a directory:
mv /usr/bin/display* /usr/local/bin/
How can I retrieve my bash file?
Rename it back.
mv bin displayvids.sh
For future reference, you can use the file command to (try to) identify the contents of a file, if it's installed:
file bin
would have probably said bin: Bash script or similar.

How to fix cd command does not work in Kali Linux

This is what happens when i type cd.
kali#kali:~$ cd
kali#kali:~$
Nothing pops out
kali#kali:~$ cd
kali#kali:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
kali#kali:~$ pwd
/home/kali
kali#kali:~$ cd Desktop
kali#kali:~/Desktop$ cd
kali#kali:~$
still nothing
Without arguments, cd changes directory to your $HOME directory.
If you look to your output, something has changed. You were in directory Desktop kali#kali:~/Desktop$ and after cd, the shell changed the directory to ~ (kali#kali:~$) which is the $HOME directory of the current user.
By default if the cd command executes with success no output is displayed and the directory is changed, but if you try to change to some directory that does not exist an error message will be output.
For instance, assuming you don't have directory abc in your root, doing the following in a bash shell will output an error:
$ cd /abd
bash: cd: /abd: No such file or directory
In the newest versions of Kali anyway (2020+), there is no cd command. Simply type the directory name (e.g. Downloads -no slashes brackets or flags at all), this is why nothing happens. I've only done this from root but I expect it works the same from a regular user account as well.

command not found in bash-3.2$

I tried running a script file using bash but it showed an error
bash-3.2$ example.sh : command not found
I also tried
ls -l example.sh
I found that it was not executable, so I used
sudo chmod 777 example.sh
I again tried running it but same error was coming. I double checked that I am in the same folder as the file using ls. But still I am not able to execute the script file.
I finally tried making a dummy script file and running it , and found the same error
I think there is some problem with BASH. Can some one help me with what is the problem?
I am working on redhat, bash was already installed in my system
Since I am newbie on linux any help would be appreciated
bash search for commands in your $PATH. Apparently the current directory, ., is not in your $PATH. (This is a good thing; having . in your $PATH is insecure.)
You'll need to specify a directory name. Just type:
./example.sh
Incidentally, doing:
sudo chmod 777 example.sh
is two kinds of overkill. First, you don't need to use sudo; use sudo only when you actually need to. Presumably your personal account owns the file, so you can just use chmod directly.
Second, 777 is way too permissive. It allows anyone on the system to read, execute, or modify example.sh. (If you're the only person on the system it may not matter much, but it's still a bad habit.) Typically you should use 755 for directories and for files that need to be executable, and 644 for files that don't need to be executable.
Or just use
chmod +x example.sh
to set execute permission (your umask will prevent that from setting the permissions too loosely).
. (the current directory) is probably not on your path. Try ./example.sh or bash example.sh. You could also add . to your PATH environment variable, but that's generally frowned upon.
Your bash PATH probably doesn't include ., try running it by typing:
./example.sh
When you type a command, your shell searches your path to try to find the command, if the current directory (e.g. .) isn't part of the path, the script that you are trying to run won't be found. You'd have to explicitly give it the path to where this command is. And since it's in your current directory, you can just add ./ in front of the command.
first confirm the bash path
to check the path of bash use:
which bash
if you get "/bin/bash"
then add
#!/bin/bash
...
...
or whatever is the path on first line of your bash script

Cannot execute bash script in redhat linux

I write a simple shell script to clean log files in redhat:
Filename: clean.sh
#!/bin/bash
rm -f *.log core.*
But when I typed clean or clean.sh, it always prompt
-bash: clean: command not found
-bash: clean.sh: command not found
What's the problem?
You probably don't have . (the current directory) in your $PATH (and that's a good thing; having . in your $PATH can be dangerous.)
Try this:
./clean.sh
And if the script file's name is clean.sh you can't run it as just clean, with or without a directory. The file name is clean.sh, and that's how you need to execute it.
Or you can change the name from clean.sh to just clean. Unix-like systems (that includes Linux) don't depend on file extensions the way Windows does.
problem 1: maybe the execute permission on clean.sh is not set. Do this:
chmod +x ./clean.sh
problem 2: RH Linux does not include CWD on the path by default. So, when you are in the same directory as clean.sh, type:
./clean.sh
That should execute it.

shell script cd fails even though the path is correct

I need to do a script to extract a tar at a specified location.
I did something simple like:
cp test.tar /var/www/html
cd /var/www/html
tar xvf test.tar
If I execute the commands by hand everything is OK. If I save them in a .sh then use #bash script.sh, I get the following error ": Not a directory cd: /var/www/html". Any ideea why?
Ty for your time.
Notes: I tried the script version on a virtual machine (CentOS 5.5) and the script worked fine, the problem occurs on the real machine where I want to use it (I used same OS disk image, same configurations as on the virtual machine... this makes it really really odd for me).
Added: Also I try invoking something like service mysqld start... this also fails saying that a dir doesn't exist (still if I run by hand it works.).
I solved the problem - it is quite interesting).
I created the script on a virtual machine running on windows with a centos os, the enter in windows is "\r\n" while in linux is "\n".
The script worked on the vm because the code for enter was correct, while on the second computer, with native linux it was incorrect. I created exactly the same script on linux and everything went back 2 normal ;).
Note... the mkdir part worked because I used another, simplified script written on linux.
On a related note, I have found that the "~" character does not seem to work in bash, so if you are using that, try replacing it with the full path.
It looks like your cp might be coping test.jar to the file html under the www directory. Make sure that html exists and is a directory before you try to cp.
mkdir -p /var/www/html
cp test.tar /var/www/html
cd /var/www/html
tar xvf test.tar

Resources