35

I would like to understand what full path name really means. I have a file in my home directory called my_script. I assumed the full path name is ./my_script, meaning that it is in the root folder, but I am not sure. Can someone please enlighten me on that?

1
  • Can you ask "is it possible to write a command that will display the list of files with their names?" in another new question?
    – Braiam
    Aug 27, 2013 at 17:12

6 Answers 6

46

No, your assumption is wrong. The full path name for my_script file from your home directory is: /home/your_user_name/my_script. When you type ./my_script in terminal you actually try to execute the script (if is executable) and it will be executed only if your current working directory is /home/your_user_name/. To execute the script you can use also the full file path which is, as I said /home/your_user_name/my_script.

It is believed that a UNIX path name looks and feels like Internet addresses, thus result into compatibility. The full path name of the current working directory can be found in terminal by using the following command:

pwd

To find out the full path for your user home directory, you can use:

echo ~
echo $HOME
echo /home/$USER

The above three commands are equivalent.

To find out the full path name for a file you can use readlink command. For example, in your case:

cd ~
readlink -f my_script
2
  • +1 readlink reveals soft links' actual path
    – lamino
    Sep 5, 2018 at 0:06
  • The home folder need not reside in /home, so /home/$USER is not necessarily equivalent with the other two examples. (e.g. /root for the root user)
    – Bwerf
    Oct 8, 2020 at 20:34
8

Full path name really means the full path to that file or folder from the filesystem's / directory.

For example, the full path to your script is:

/home/your_username/my_script

Or, the full path name to the grep executable is

/bin/grep

As for the ./my_script, the symbol . stands for the current directory, so you actuallly say "Look under the current directory for a file or folder named my_script"

3

In order to understand the full path, you must first know the starting point.

The root directory / it is the starting point of *nix based operating systems. It contains all the other directories both system's and user's.

User's home directory /home/USERNAME/ or ~/ for short, contains user's files and directories. For example Pictures, Music, Documents, etc. Each of these directories is referenced as /home/USERNAME/DIRECTORY for example Documents is located at /home/USERNAME/Documents.

Like with directories, files are referenced in the same way, for example a file named my_script located at the home directory of the user sosytee can be referenced using the full path /home/sosytee/my_script or ~/my_script for short.

Both files and directories can be referenced/accessed using their full paths from everywhere in the system. Additionally one can access them using only their name if it is in the same directory. For example if the user is at ~/ when using the terminal, he can access my_script file by using just my_script.

Additionally one can access directories and files by using their name only, if they are placed at his PATH variable. You can see what is store in PATH by using echo $PATH.

Simple examples on how to access files using the command line:

  • The user is currently at /home/USERNAME/ and wants to use the cat command on a file located at /home/USERNAME/Documents named foo.txt:

cat Documents/foo.txt

  • The user is inside ~/Documents and wants to run a script named foo.sh located ad ~/Scripts/Foo:

    sh ../Scripts/Foo/foo.sh

    or

    sh ~/Scripts/Foo/foo.sh

by all means this is just a summary.

Further information

2

The full path name is the path from the root directory (i.e., /). ./my_script is the relative path name, because the path is given relatively to the current directory, which is denoted by .. So if you are in your home directory the full path is s.th. like /home/sosytee/my_script. For your home directory there is the "short-cut" ~, meaning you can also write ~/my_script. But that will of course resolve to a different path for every user.

To see the full path of your current directory call pwd.

2

I assumed the full path name is ./my_script

No, it is not. That path is relative. The point at the beginning indicates the current directory:

$ ls ./my_script
my_script
$ cd ..
$ ls ./my_script
ls: cannot access ./my_script: No such file or directory

As you can see, I changed the directory and the my_script is not found, which means that ./my_script is not an absolute path.

I assumed the full path name is ./my_script, meaning that it is in the root folder, but I am not sure.

From the Wikipedia:

[...] A full path or absolute path is a path that points to the same location on one file system regardless of the working directory or combined paths.

Since the ./my_script don't fill the condition that whenever I'm I can find the my_script file, we should infer that is a relative path.

A relative path is a path relative to the working directory of the user or application, so the full absolute path will not have to be given.

0

Here... i assume you're asking because you installed Ubuntu server on windows...

copy this code to your folder explorer on windows %userprofile%\AppData\Local\Packages

that will show you the home location... its hidden somewhere on your system

In this folder, double-click the folder for the Linux distribution whose files you want to view:

  1. Ubuntu: CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
  2. openSUSE Leap 42: 46932SUSE.openSUSELeap42.2_022rs5jcyhyac
  3. SUSE Linux Enterprise Server 1246932SUSE.SUSELinuxEnterpriseServer12SP2_022rs5jcyhyac

The names of these folders may slightly change in the future. Just look for a folder named after the Linux distribution.

your home will be under LocalState\rootfs\home

Most of this info was gotten from How to Access Your Ubuntu Bash Files in Windows (and Your Windows System Drive in Bash)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .