The one thing that trips me up time and again when using the command line in Terminal or other terminal emulator is being able to navigate the directory structure and target files or folders. After struggling getting the correct file or folder path I’m usually greeted with No such file or directory reminding me that the command line doesn’t like spaces in file and folder paths.
With that in mind here are a few ways to enter file and folder paths on the command line.
I’m going to change the current directory to /Users/steve/Library/Application Support using the cd command.
The first method is to enclose the full path in single quotes…:
cd '/Users/steve/Library/Application Support'
…or double quotes:
cd "/Users/steve/Library/Application Support"
The second is to escape any space with a backslash \. The backslash should be placed immediately before each space:
cd /Users/steve/Library/Application\ Support
If the file or folder exists in the current user’s home folder we can use ~/ as shorthand to denote the user’s home folder:
cd ~/Library/Application\ Support
If we want to use single or double quotes, the opening quote must come after the ~/ shorthand:
cd ~/"Library/Application Support"
The one I tend to use most is to first type the command at the command line with a trailing space. Then locate the file or folder in the Finder and drag it to the open Terminal window:
The full path is copied at the Terminal window’s current cursor position: