What does / , ./ , ../ represent while giving path?
Root directory, current working directory, and parent directory, respectively.
Difference between ./ and ~/
./
means "starting from the current directory". .
refers to the current working directory, so something like ./foo.bar
would be looking for a file called foo.bar
in the current directory. (As a side note, ..
means refers to the parent directory of the current directory. So ../foo.bar
would be looking for that file one directory above.)
~/
means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/foo.bar
would be looking for a file called foo.bar
in your home directory, something like /home/totzam/foo.bar
. In many web applications, ~/foo.bar
would be looking for a file called foo.bar
in the web application root, something like /var/http/mywebapp/foo.bar
.
Add a bash script to path
Try this:
- Save the script as
apt-proxy
(without the.sh
extension) in some directory, like~/bin
. - Add
~/bin
to yourPATH
, typingexport PATH=$PATH:~/bin
- If you need it permanently, add that last line in your
~/.bashrc
. If you're usingzsh
, then add it to~/.zshrc
instead. - Then you can just run
apt-proxy
with your arguments and it will run anywhere.
Note that if you export
the PATH variable in a specific window it won't update in other bash instances.
Path difference between ../ and ./
./
means the current directory
../
means the parent of the current directory, not the root directory
/
is the root directory
myfile.text
is in the current directory, as is ./myfile.text
../myfile.text
is one level above you and /myfile.text
lives in your root directory.
Why do you need ./ (dot-slash) before executable or script name to run it in bash?
Because on Unix, usually, the current directory is not in $PATH
.
When you type a command the shell looks up a list of directories, as specified by the PATH
variable. The current directory is not in that list.
The reason for not having the current directory on that list is security.
Let's say you're root and go into another user's directory and type sl
instead of ls
. If the current directory is in PATH
, the shell will try to execute the sl
program in that directory (since there is no other sl
program). That sl
program might be malicious.
It works with ./
because POSIX specifies that a command name that contain a /
will be used as a filename directly, suppressing a search in $PATH
. You could have used full path for the exact same effect, but ./
is shorter and easier to write.
EDIT
That sl
part was just an example. The directories in PATH
are searched sequentially and when a match is made that program is executed. So, depending on how PATH
looks, typing a normal command may or may not be enough to run the program in the current directory.
extending default lib search path in ubuntu
create (as root) a new file in /etc/ld.so.conf.d/
containing, the new path. For example:
sudo echo "/path-to-your-libs/" >> /etc/ld.so.conf.d/your.conf
after that run
sudo ldconfig
No need to change libc.conf.
find: paths must precede expression: How do I specify a recursive search that also finds files in the current directory?
Try putting it in quotes -- you're running into the shell's wildcard expansion, so what you're acually passing to find will look like:
find . -name bobtest.c cattest.c snowtest.c
...causing the syntax error. So try this instead:
find . -name '*test.c'
Note the single quotes around your file expression -- these will stop the shell (bash) expanding your wildcards.
windows equivalent of ./ (current directory)
A period denotes the current directory in Windows.
For your example you would use the following:
c:\> cd c:\windows
c:\Windows> .\System32\ipconfig.exe
Alternately, you could forego the .\ and do it like this:
c:\Windows> System32\ipconfig.exe
What does ./ (dot slash) refer to in terms of an HTML file path location?
./
is the the folder that the working file is in:
So in /index.htm
./
is the root directory
but in /css/style.css
./
is the css folder.
This is important to remember because if you move CSS from /index.htm
to /css/style.css
the path will change.
Related Topics
How to Run a Mips Binary on X86 Platform
How to Filter the Running Nodes
Colored Shell Script Output Library
Sed Insert Line with Spaces to a Specific Line
Does Linux Kill Background Processes If We Close the Terminal from Which It Has Started
In Linux, What Do All the Values in the "Top" Command Mean
Copying Files Based on Modification Date in Linux
Choosing Between Multiple Executables with Same Name in Linux
Testing Out of Disk Space in Linux
About Process Control Block in Os
How to Check All Columns Data Types of Table Using Awk Script
Bash Script to Calculate Time Elapsed
Best Practices for Git Repositories on Open Source Projects
X11/Xlib.H Not Found in Ubuntu