I'm new in programming and I try to use gdal library for Python. I would like to execute gdalinfo command, but I don't know what "~" mean in "gdalinfo somedir/somefile.tif" example. Could you explain it to me?
-
Could you provide more information? What was the context? – Brian Jul 22 '15 at 15:19
-
2`~` generally refers to the home directory of the current user. – karthikr Jul 22 '15 at 15:20
-
1...you realise that `~` isn't actually in that *"example"*? In Python code, it's [unary invert](https://docs.python.org/2/reference/expressions.html#unary-arithmetic-and-bitwise-operations), in a path (as @karthikr points out) it's your home directory. – jonrsharpe Jul 22 '15 at 15:24
1 Answers
I assume you are looking at Obtain Latitude and Longitude from a GeoTIFF File, the line is:
dalinfo ~/somedir/somefile.tif
Here the ~
is UNIX style shell expansion and is a shortcut for the current user's home directory. The nearest equivalent on Windows is the environment variable %HOMEDIR%
.
On UNIX style systems it is also represented by the environment variable value $HOME
.
The user's home directory is the current directory ("folder", if you must) used when you first logon. On UNIX systems it holds files containing user preferences and start-up files, often using filenames beginning with a dot, for example .profile
. You won't see those using ls
, you need ls -a
. The home directory on Windows is used, but many end-users are not aware of it, although some software products (particularly portable ones) use it.
The ~
generally means something completely different in a programming language, and cannot be used as part of a filename without invoking a shell.
In Python, to get the home directory you would need to read the environment variable, for example os.environ['HOME']
.