How to fix cd command does not work in Kali Linux - 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.

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.

command l to access downloads directory in raspian

lines I have tried:
cd ~/downloads
cd /home/pi/downloads
cd ~/user/home/downloads
ls ~/downloads
cd ~./downloads
If I use the nano command the screen will come up but if Try to change directory it says "no such file or directory". Don't laugh its probably simple but I'm new to Linux and trying to learn command lines.

Ubuntu: how to enter a directory in shell

On my Desktop I have created a folder called "Files", I would like to know how to access that folder through a shell script
When in Linux file system using bash you can navigate to the home directory in many ways:
After you reach the home directory everything is easy from there including reaching Desktop.
The ~ or $HOME reference:
In Linux based systems the keyword ~ or $HOME refers to the home directory of the computer.
For example say you are currently at /bin, to navigate to home if you know your username you would do :
$ cd /home/yourusername
#The directory is now switched to :
$ pwd #This command stands for print working directory
'/home/yourusername'
Now you can do it alternatively by:
(Again assuming you are in /bin)
$ cd $HOME
$ pwd
'/home/yourusername'
#Alternatively
$ cd /bin
$ cd ~
$ pwd
'/home/yourusername'
These shortcuts let you go to home without writing much and are even recommended.
Now for your problem you can easily navigate to your folder by:
cd ~/Desktop/Files/

Move script.sh to bin

I'm new to shell programming and I'm trying to create a simple script that gives me some infos on the status of the machine (i.e date, time, users logged in etc) on Scientific Linux 6 (I know it's old, but the department of my university runs on it so there's no escaping)
Basically I've created my script "sysinfo.sh"
#!/bin/sh
....
exit 0
as root user I want to move it so that I can be able to execute it anywhere and I thought the right way to do it was
sudo mv sysinfo.sh usr/local/bin
but I get the error message
mv: cannot move `sysinfo.sh' to `usr/local/bin': No such file or directory
then I looked for the PATH and it gives me
$ echo $PATH
/u/geo2/sw//System/tools/bin:/usr/bin:/bin
What is the right place to move my script?
Best practice for these kind of manipulation or learning is to have scripts in your $HOME/bin directory.
mkdir $HOME/bin
export PATH=$PATH:$HOME/bin
mv sysinfo.sh $HOME/bin
chmod +x $HOME/bin/sysinfo.sh
If you anyway want to move it to /usr/local/bin, why not do that with:
sudo mv sysinfo.sh /usr/local/bin
chmod +x /usr/local/bin/sysinfo.sh
chmod command will make the script executable.
from chmod man:
x -- The execute/search bits.
The command that you posted indicates that you were trying to use the absolute path for copying, but you missed a leading slash --
the directory should be /usr instead of usr.
Try
sudo mv sysinfo.sh /usr/local/bin
Note that unless an absolute path is specified, the shell looks for the path relative to the current working directory.
In this case, the shell was looking for the subdirectory usr under the current directory which was not found;
hence the error message.
Thank you very much!
In the end, I didn't realize that the directory /usr/local/bin wasn't in the PATH
So i just needed to
export PATH=$PATH:/usr/local/bin
sudo mv sysinfo.sh /usr/local/bin
:D

/cygdrive path is broken

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>

Resources