7

I am a new user of the Mac terminal. What is the meaning of "./"? What is the difference between the commands

rm image.png
rm ./image.png
rm *./image.png
3
  • You had two questions in here. This site works better when there is only one question per question. That way, it's easier for other people to find solutions if they have the same problem. I've edited out your second question, but feel free to ask it separately.
    – nohillside
    Jul 4, 2013 at 10:27
  • 1
    In response to the second (removed) question, SymbolHound is a search engine that doesn't ignore special characters. Also, the OS X Terminal is a Unix-like environment, meaning you can often find answers using search terms such as "dot slash linux".
    – deizel.
    Jul 4, 2013 at 12:02
  • And what is the meaning of "open ."? Is it like "open current folder"? Sep 3, 2018 at 14:33

2 Answers 2

20

./ is part of the path to a directory/file.

If used as part of a parameter to a command

  • rm image.png and rm ./image.png are exactly the same and identify a file in the current directory
  • rm *./image.png is a pattern which looks for files named image.png in all subdirectories of the current directory which end with a dot

The key use for ./ usually is to call a script/executable in the current directory. When you execute a command without specifiying it's directory (e.g. cp instead of /bin/cp), the shell searches for this in all directories listed in the $PATH variable. The current directory is usually not part of that variable (for security reasons) so you can use ./command-name to tell the shell to look for the command in the current directory.

1
  • 3
    +1 - In addition if one types ls -a, they will see entries for . and ... One probably already knows that .. is the parent directory, so naturally . is the current directory. However, such things have no special meaning if used in the middle of the string rather than from the start, so rm *./image.png is the red herring in this question (It's just a glob matching things such as directorywithadot./image.png.)
    – deizel.
    Jul 4, 2013 at 11:48
-4

The expression in a file path, (./) means 'move up' (from the current location), i.e., 'this' = '.' and / = 'up' so ../ means 'move up 2 directories', or, move to the parent of this (./), i.e., take the current location and move up to '/' the new location.

1
  • 1
    That would be cd ../ to move up one directory, cd ../../ for two. Same for file paths
    – anki
    Oct 7, 2019 at 12:49

You must log in to answer this question.

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