Ubuntu: how to enter a directory in shell - linux

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/

Related

am in the Desktop but I cd is not see the desktop

How can I fixs that problem meanwhie I fix last code Selenim
Selenium but I am take same error. And cd is not see the Desktop but I am in the Desktop.
Here ~ is equal to /home/levidonates so when you type cd ~/Selenium it's actually cd /home/levidonates/Selenium but the folder Selenium is in your folder Desktop, so you need to type :
cd ~/Desktop/Selenium
~ is a shorthand for your home directory, /home/levidomates. The directories you're accessing are under there, not under the root, /. That is, ~/Desktop is not the same as /Desktop.
Firstly I see which folder do you try to enter / at the beginning? this is not true method.
/ characters means top of all folders root level.
You should not confuse it with the root user's home folder.
cd: change directory
cd .. : Back to the previous folder or up folder.
Firstly You can check your home folder
echo $HOME
then you must be enter pwd
if the your home folder /home/levidomates/
you must only cd ~ command
than cd Desktop
You shouldn't use / at the beginning of folders
Your absolute way to Deskotp is not correct...You forgot /home/levidomates
So then it should be cd /home/levidomates/Desktop instead of cd /Desktop

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.

How to make Git-bash command line start up with home directory?

Git-bash.exe is installed at this location:
C:\Program Files\Git
Git-bash.exe starts up with these prompts:
bash: /c/Users/GodCoder/git-prompt.sh: No such file or directory
GodCoder / $
(GodCoder is just the username)
This file named, 'git-promt.sh' is definitely present at that location, still that promt!
Now, after I tried to print the current working directory which is the same directory where Git-bash is installed i.e. C:\Program Files\Git , it showed this:
GodCoder / $ pwd
/
Now, how to change this, default startup directory to my home directory location which is C:\Users\GodCoder i.e. I want Git-hub.exe to start up like this
GodCoder ~ $
Instead of starting up in this way
GodCoder / $
How to achieve this GodCoder ~ $?
Start your git bash with a /dir like this: git-bash.exe /dir "C:\Users\GodCoder"
If you are on Windows, do this
Right click on the Windows shortcut that you use to launch git bash, and click Properties. Change the value of "Start In" to your desired workspace path i.e.
Replace the start in values with "C:\Users\GodCoder"
For more information go to this link: https://classroom.udacity.com/courses/ud775/lessons/2980038599/concepts/33417185870923
It may help you in setting up your enviroment further and also, make sure you restart the application or even the pc and try running in admin or different user modes too!

How to navigate to a single child directory without knowing its name using shell command?

I need to run a script in a remote machine from my JAVA code using runCommand() method. Now I can't always know the full path of the script as a particular directory name keeps changing. For example the path looks like this : /a/b/xxxxx/script . xxxx is the directory name that keeps changing and its the only single directory under /a/b/. Is there any shell command using which I can get the directory name ? I know using JAVA,but I specifically need shell command.
If there is only a single self-directory, another fool-proof way of doing it would be
cd */.
*/. is that this expands to the "self directory" (named .) in any subdirectory, which is of course the sub-directory itself. Refer the below example of how it works.
E.g.
$ pwd
/home/dude/
$ mkdir -p a/b/ldsnds/c
$ cd a/b/*/.
$ pwd
/home/dude/a/b/ldsnds
$ cd -
/home/dude/
$ cd a/b/*/./c
$ pwd
/home/dude/a/b/ldsnds/c
Below should give you the name of the directory in the directory "b".
$ find /a/b -type d -maxdepth 1 2> /dev/null
If you are so sure that it would always be one directory in /a/b then just store the output of find in a variable and move ahead.
Note: 2> /dev/null is just to get rid of errorneous warnings.

What directory is the default bash directory

I am using the bash console for Ubuntu and my console location is
user#MyServer:~$
If user#MyServer:/$ is the root directory, what is user#MyServer:~$ ?
~ represents your home directory. If you are logged in as root, this will typically be /root if you are logged in with another user (say with username user) this will typically be /home/user. The best way to know for certain though is either run echo ~ which will print where ~ points to, or you can run the pwd command while in ~ which will show your present working directory - this command is generally useful to know when navigating.
As noted in other replies, it's your home directory, which is shortened to ~.
You can find out what directory you're in using the pwd command. eg:
[atticus:pgl]:~ $ pwd
/home/pgl
“user#MyServer:~$” is the command prompt. You can echo $PS1 to see the setting of your environment.
Its your home directory you can go to your home directory by cd ~
Not always, you can list all users' home directory by:
cut -d : -f1,6 /etc/passwd
so you will get different paths, some under /export/home/USERNAME, some under /home/USERNAME, some has no home directory. For root account, normal / is its home directly.

Resources