Alright thanks guys, turns out the files are different on the new version and if you install a older version if works out just fine. I started learning how to use terminal and i got kinda confused about the the cd ./ command. Its used to change to a directory inside the current one according to some sources. What the point of this is the normal cd command navigates from the current directory to the next one as long as it is not cd /. So what is the usage of the ./ command??
./
isn't a command, it's a relative path which specifies the current directory.
Likewise
../
is a relative path which specifies the parent directory of the current directory. In other words, the directory that is one level up from the current working directory.
So if you want to run an executable script called script.sh which is in the current working directory (AND if the current directory is NOT a location listed in $PATH) - you would execute the script using:
Or if you want to open the script to edit it:
However, the default behaviour for most commands is to look in the current working directory for files, so you could also just use:
So in that particular context the ./ is optional.
But if you were trying to run a script that is not in $PATH, then you would need to specify a relative path, or an absolute path.
So the relative path is relative to where you currently are in the file-system.
If you wanted to edit a file that is a couple of sub-directories deeper than where we are, you could use a relative path like this:
Bash:
vim ./sub-dir1/sub-dir2/somefile.txt
Note: I use vim as my terminal editor - you might use nano, or emacs, or perhaps you're one of these crazies who opens a GUI editor from the terminal - use whatever floats your boat!
If it is two directories above where we are, you would use something like this:
If it is in a sub-directory that is two directories above where we are, you would do this:
Bash:
vim ../../somedir/somefile.txt
Likewise, if you want to run a script in a sub-directory that is outside of
$PATH
- you can run it using a relative path like the first example I gave where we specified
./script.sh
to run a script in the current directory.
But if you're not in the directory containing script.sh - you will need to use
./
or multiple
../
's to specify the path to script.sh, relative to where you are in the file-system.
e.g.
./sub-dir1/someotherdir/script.sh
or
../../../sub-dir1/someotherdir/script.sh
That's how relative paths work. They describe a path to a file-system object, in a way that is relative to the current working directory - in other words relative to where we currently are in the file-system.
Other than relative paths, there are also absolute paths. An absolute path is the complete path from the root of the file-system.
So examples of absolute paths are:
/home/yourusername/sub-dir/script.sh
or
~/sub-dir/script.sh
(~ is a bash shortcut for /home/yourusername) or
/usr/bin/vim
, or
/bin/cat
.
Absolute paths can be used to specify the paths to file-system objects too.
When to use a relative path and when to use an absolute path:
Typically, you'd use a relative path if the file-system object you are referring to is close to where you are. If it is some distance away - it would be more practical to use an absolute path.
So if you're deep in the file-system somewhere and you want to run a script in your home directory - rather than using a ton of relative
../
's in the path to the script - it would be simpler to use:
Bash:
/home/yourusername/script.sh
or using ~ as a shortcut:
Or if you wanted to open the file in an editor whilst you are deep in the file-system:
Again, I use vim - but feel free to use whatever you normally use!
I think that just about covers relative and absolute paths.
If you have any questions regarding anything in this post - fire away.
If you have any further terminal related questions, feel free to make another thread in the command-line forum here. I tend to lurk there quite often!