MacOS Terminal go to a folder with spaces and parenthesis - macos

I'm trying to configure Cyberduck to read the Bookmark files from my Dropbox folder.
This is usually accomplished by this command:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
Super easy!!
But... Dropbox has since changed and if you have a Pro Account the Dropbox folder is renamed "Dropbox (Personal)".
I've tried to do this:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox\ \(Personal\)/
And I get this error:
not parse: [...]/Dropbox (Personal)/Apps/Cyberduck/. Try single-quoting it.
I tried single quoting like this but same error:
defaults write ch.sudo.cyberduck application.support.path '~/Dropbox\ \(Personal\)/'
How can I solve this?

You can single quote escape your parentheses by wrapping them in a double quote:
Instead of: ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
Do: ln -s "'/Users/username/Dropbox (Company Name)/'" DropboxCompanyName
Notice the double quotes added to /Users/username/Dropbox (Company Name)/

So I cannot find a way to do a "defaults write" to a path with parentheses, but I did this workaround and it seemed to work for me (in my case I needed to link to my enterprise Dropbox account):
cd to your home folder and create a symlink of the directory that has the parentheses:
ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
At that point, I was able to do do a defaults write that wrote ~/DropboxCompanyName as part of the path and it worked just fine.
All that said, your personal folder already has a hidden symlink: "Dropbox" that's in the same directory and pointing to "Dropbox (Personal)", so you should be able to do you original command as such:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
… because the "Dropbox" part of the path should still lead to your personal folder. This both what I've observed locally (when viewing hidden files) and what Dropbox says on their site: https://www.dropbox.com/help/9031

I am assuming you are using Unix in Terminal.
I have set up a folder of the same name in my Public Folder to test as shown below.
Your current referencing to the folder would seem correct. Dragging the folder into the Terminal window current command line will automatically give you the correct referencing to that folder.
As an alternative I suggest putting the name of the folder in double quotation marks. Even though there are brackets in the name, there is no need to escape these characters in Unix in Terminal in this instance when using double quotation marks. This makes it easier to humanly type the correct reference.
To reference a folder in the image below, for example, the following referencing works for the cd (change directory command):
~/Public/"Dropbox (Personal)"
Hence I suggest try:
ch.sudo.cyberduck application.support.path ~/Public/"Dropbox (Personal)"
As for the rest of this command, I am not sure that ch is a valid Unix command. I do not yet have enough Unix experience to guide you from here.

you have to put "" in the whole address
more like this
ch.sudo.cyberduck application.support.path "~/Public/Dropbox (Personal)"

Related

zsh prompt replace named directory with it's alias

As I understand, if you create an alias for a directory in your .zshrc file, that directory is now considered a "named directory". I could be mistaken there, so let me know.
Based on the documentation here, it sounds like if you use "%~" in your zsh prompt and the current working directory is a named directory, then the prompt should show the alias for the directory, rather than the full path (i.e. ~{alias}). This does not seem to be working for me currently and I'm having a hard time finding examples or posts regarding this.
In my .zshrc file I have an alias like repo = "~/src/apps/repo". My hope is that when I am in that directory, the zsh prompt would show ~repo, but it always shows the full thing.
Any help is greatly appreciated!
In zsh, you can add a named directory with hash -d repo=~/src/apps/repo (not an alias). Also, ~ isn't expanded inside quotes, so you should remove them or use $HOME instead.
hash usage: https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-hash-1
Static named directories: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Static-named-directories

Can't Copy folder to specific location using terminal - Mac

I could not find a usable solution to this seemingly simple problem, despite my best efforts.
I'm using MacOS High Sierra 10.13.6
I have a folder I want to copy with the following location:
/Users/ep9k/Desktop/Key-LogEcovaluator/whereami
I want to copy it to this directory using the terminal:
/Users/ep9k/Library/Application/Support/QGIS/QGIS3/profiles/default/python/plugins
I tried the following commands in the terminal. Notice I am in the 'whereami' folder when doing this:
whereami ep9k$ cp -r /Users/ep9k/Desktop/Key-LogEcovaluator/whereami /Users/ep9k/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
whereami ep9k$ cp -a /Users/ep9k/Desktop/Key-LogEcovaluator/whereami /Users/ep9k/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
I'm met with the following message indicating I am not using it correctly:
However, I created a "tester" folder on my desktop and can copy to this folder with no problems, using exactly the same command (except with the pathname changed to my tester folder).
I can also copy and paste things to this directory using the GUI "finder". What am I missing?
Your destination path contains at least one whitespace character ("Application Support"), which causes the "cp" command to think it's being given three arguments instead of two. Enclose the destination path in single or double quotes and you should be all right.

How to change $PATH variable in bash_profile in OSX?

I am trying to install a 3rd party library from GitHub through terminal. Before this installed Anaconda Python distribution on my system and that has modified my root directory of my terminal to;
Vinos-MBP:~ Vino$
So when try to navigate to a particular directory to install the said library using
cd /Users/Vino/<install location>
The terminal prints the following message;
-bash: cd: /Users/Vino/Documents/My: No such file or directory
I know this problem is because Python has modified my bash_profile startup file. I tried various online methods to fix this issue, but nothing actually works. Whenever I restart my terminal and navigate using cd, I get the same error. How do I reset $PATH to $HOME (like as before installing Anaconda), so that I can navigate to any folder on my system?
This is not a problem with $PATH or $HOME -- it looks to me like you have a space in the folder name, and aren't properly quoting/escaping it. If they aren't quoted or escaped, spaces are taken as separators between arguments (e.g. folder paths) rather than part of the path. If the folder you're trying to cd to is "/Users/Vino/Documents/My Installation Location", you could use any of these:
cd "/Users/Vino/Documents/My Installation Location"
cd '/Users/Vino/Documents/My Installation Location'
cd /Users/Vino/Documents/My\ Installation\ Location
cd ~/Documents/My\ Installation\ Location
cd ~/"Documents/My Installation Location" # Note that the ~/ part must not be quoted
There are a number of other characters that're perfectly legal to have in filenames that will cause trouble when used on the command line without quotes or escapes (including the quote and escape characters themselves!). One way to avoid trouble is to drag-and-drop an item from the Finder into the Terminal window, and it'll fill in a (properly escaped) path to that item.

How can I cd to an alias directory in the Mac OSX terminal

Is there a way to get into an alias directory from shell with the command "cd" ? It always returns that "htdocs" isn't a directory.
Edit: I made the shortcut with the OS GUI -> rightclicked the htdocs directory and chose "Alias..." (i'm using a german OS if it's not alias maybe it's called shortcut in english?) then i moved it to my home directory (because my terminal starts from there when i open it).
All i want is to open my terminal and type "cd htdocs" so that i can work from there.
you can make symbolic link to it.
ln -s EXISTING_PATH LINK_NAME
e.g.
ln -s ~/Documents/books ~/Desktop/
Reference
Enter into a directory through an alias in Mac OS X terminal
All i want is to open my terminal and type cd htdocs so that i can work from there.
The easier approach is probably to ignore the links and add the parent directory of your htdocs directory to the CDPATH environment variable. bash(1) will check the contents of the CDPATH environment variable when you type cd foo to find the foo directory in one of the directories listed. This will work no matter what your current working directory is, and it'll be easier than setting symbolic links.
If the path to your htdocs is located /srv/www/htdocs/, then you could use CDPATH=/srv/www. Then, cd foo would first look for /srv/www/foo/ and change to it if it exists; if not, then it would look for foo in the current working directory and change to it if it exists. (This might get confusing if you have multiple htdocs directories on your system; in that case, CDPATH=.:/srv/www would let you change into a child directory easily but still use the /srv/www/htdocs/ version if no ./htdocs directory is present.)
You can add the CDPATH=/srv/www line to your ~/.bashrc file so it works every time you start a terminal.
I personally use this to quickly work in the directory which is present deep inside one of my Volumes in my Mac.
Open your ~/.bash_profile, create an alias to the directory by adding this:
alias cdh="cd /Volumes/Haiku/haiku/src/apps/superprefs"
Save it, restart your terminal. Now on typing cdh in your terminal should change the working directory to the one mentioned as the alias.
I am not sure how OSX exposes Alias links but since you are using bash you can just create a variable in your .bashrc file.
On its own line put:
htdocs=YourDirectoryPath/
Once you have restarted bash you can just type cd $htdocs
There is a old hint on macworld to do this in a way that is integrated with BASH: Enable 'cd' into directory aliases from the Terminal
Plus, here is an answer that uses this solution on superuser.
You may be able to use osascript to do this -- this command seems to work:
cd "`osascript -e "on run aFile" -e "set aFile to POSIX file aFile as alias" -e "tell application "\""Finder"\"" to return POSIX path of ( ( original item of aFile ) as text ) " -e "end run" path_to_my_Finder_alias 2>/dev/null`"
Basically this command is running an AppleScript that finds the destination path of the argument (path_to_my_Finder_alias) in a subshell, then wraps it in double quotes, and changes the directory to it.
Maybe someone with a little more bash expertise can turn it into a bash alias or function.
try:
alias cdgo=`echo cd /root/go/`
cdgo will run, then get command "cd /root/go/" and enter, and it will change your directory in current terminal process
It works on my centos, no test with osx

Running python batch file that has a path with SPACE character

The batch file is something like this, I put the python in some directory that has SPACE character in its path.
C:\"Documents and Settings"\Administrator\Desktop\bracket\python\python
C:\\"Documents and Settings"\\Administrator\\Desktop\\bracket\\[10,20]\\brackettest.py
When I run this one, I get this error.
C:\Documents and Settings\Administrator\Desktop\bracket\python\python: can't ope
n file 'C:\Documents and Settings\\Administrator\\Desktop\\bracket\\[10,20]\\bra
ckettest.py': [Errno 2] No such file or directory
C:\Documents and Settings\Administrator\Desktop\bracket>
What might be wrong?
Wrapping the path doesn't solve this problem.
"C:\\Documents and Settings\\Administrator\\Desktop\\bracket\\[10,20]\\brackettest.py"
Are the brackets ('[]') cause of the problem? On Mac, python works well with bracket character.
There's no backslash escaping in the Windows console, it should read
"C:\Documents and Settings\Administrator\Desktop\bracket\python\python" "C:\Documents and Settings\Administrator\Desktop\bracket\[10,20]\brackettest.py"
Looks like you almost had it; just replace the double-slashes with single slashes.
If you're ever unsure and need a reminder of the right format. Try using the tab key to automatically complete your folder or filename. For example, at your command prompt just type:
C:\docu
then hit the tab key and it will automatically complete your folder name. From there you just type in the rest. Whenever you want to automatically complete the rest of the folder or filename, just hit the tab key. This will always produce a properly specified path that is runnable.
path = r"C:\Users\mememe\Google Drive\Programs\Python\file.csv"
Closing the path in r"string" also solved this problem very well. This tells python that it is exactly that string and avoids backslash and space errors. I use it for my files because it allows me to copy and paste directly from the navigation bar at the top of the window.
Can you
cd "\Documents and Settings"
cd "\Documents and Settings\Administrator\Desktop\bracket\python\python"
cd "\Documents and Settings\Administrator\Desktop\bracket\"
cd "\Documents and Settings\Administrator\Desktop\bracket\[10,20]\"
If all that works, do
cd "\Documents and Settings\Administrator\Desktop\bracket\python\python"
python "\Documents and Settings\Administrator\Desktop\bracket\[10,20]\brackettest.py"
Why do you have such a weird, nondescriptive dirname ([10,20])? Didn't even know that NTFS allowed that.

Resources