Tilde (~
) will not be expanded by shell when put inside quotes. Just remove the quotes :
#!/bin/bash
dir_path=~/Desktop/param_bind_b
cd "$dir_path"
Some useful things to know when doing things with files:
- Linux is case sensitive (so
dog
, Dog
and DOG
are all different files)
- How commands work depends on where you are in the filesystem
- Based on where you are you can use relative or absolute pathnames
So, if you are in the parent directory of Cat
and Dog
you can use relative pathnames, like this:
mv Cat/puppies Dog
An easy mistake to make is to type the pathname starting with /
mv /Cat/puppies /Dog
This will give a no such file or directory
error, because /
is the root directory and there are no Cat
and Dog
directories under /
. Have a look:
ls /
One reason for this confusion is that the system uses a helpful shortcut for the user's home directory, so instead of /home/username/somefile
you can type ~/somefile
as the absolute pathname of somefile
in your user's home directory, so, assuming Cat
and Dog
are at the top of your user's home directory, you can move puppies
from Cat
to Dog
from anywhere in your filesystem with
mv ~/Cat/puppies ~/Dog
A couple of examples using relative pathnames
If you are in the directory Cat
, you can move puppies
like this
mv puppies ../Dog
..
specifies the parent directory of the current working directory
If you are in the directory Dog
you can move puppies like this
mv ../Cat/puppies .
.
specifies the current working directory
To find out where you are, you can usually look at your prompt, but just to be sure, you can always check with pwd
which stands for 'print working directory'
Best Answer
In UNIX systems the "/" is always the main folder (the start of the tree).
When you are in /home/username you have to write relative path to this directory in order to navigate deeper in the tree e.g.
cd Desktop
(without "/" in front of Desktop) or you can use the absolute pathbut absolute paths are usually not a good way to move in the tree, because if you are somewhere in a deep place in the tree you don't want to write all the folders just to get one level deeper or go to at the upper level.
To move one level upper you have to write
cd ../
which is again relative to the folder where you are at the moment.