Locating `subl` in OS X - sublimetext2

I have the subl command line tool installed in my machine (OS X 10.9.2). It works fine. But I need to know where it is. So I type:
which subl
in a Terminal window. But the behavior is as if the command did not exist.
As you can imagine, Googling "which command yields no output" is not very helpful.

To find if something is an alias, a shell builtin, or an executable program, use type:
# on my system
$ type dir
dir is aliased to `ls -FaGl`
$ type pwd
pwd is a shell builtin
$ type du
du is /usr/bin/du
It's much faster than using an unindexed locate command.

Use locate to find all filenames with subl
locate subl

Related

Using MySQL in the command line in OS X - command not found?

I'm trying to get MySQL up and running on my Mac OS X 10.9.5.
I've installed the latest version 5.6.21 of MySQL Community Server. I've gone to system preferences and started the mysql server, then launched terminal and typed this:
/usr/local/mysql/bin/mysql --version
which should return the version. But when I type any of the mysql commands I get command not found.
I've also tried:
sudo mysql_secure_installation
mysql -u root --password=password`
I do have web hosting with MySQL etc installed, but I want to be able to get to grips with it in the command line first.
So there are few places where terminal looks for commands. This places are stored in your $PATH variable. Think of it as a global variable where terminal iterates over to look up for any command. This are usually binaries look how /bin folder is usually referenced.
/bin folder has lots of executable files inside it. Turns out this are command. This different folder locations are stored inside one Global variable i.e. $PATH separated by :
Now usually programs upon installation takes care of updating PATH & telling your terminal that hey i can be all commands inside my bin folder.
Turns out MySql doesn't do it upon install so we manually have to do it.
We do it by following command,
export PATH=$PATH:/usr/local/mysql/bin
If you break it down, export is self explanatory. Think of it as an assignment. So export a variable PATH with value old $PATH concat with new bin i.e. /usr/local/mysql/bin
This way after executing it all the commands inside /usr/local/mysql/bin are available to us.
There is a small catch here. Think of one terminal window as one instance of program and maybe something like $PATH is class variable ( maybe ). Note this is pure assumption. So upon close we lose the new assignment. And if we reopen terminal we won't have access to our command again because last when we exported, it was stored in primary memory which is volatile.
Now we need to have our mysql binaries exported every-time we use terminal. So we have to persist concat in our path.
You might be aware that our terminal using something called dotfiles to load configuration on terminal initialisation. I like to think of it's as sets of thing passed to constructer every-time a new instance of terminal is created ( Again an assumption but close to what it might be doing ). So yes by now you get the point what we are going todo.
.bash_profile is one of the primary known dotfile.
So in following command,
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bash_profile
What we are doing is saving result of echo i.e. output string to ~/.bash_profile
So now as we noted above every-time we open terminal or instance of terminal our dotfiles are loaded. So .bash_profile is loaded respectively and export that we appended above is run & thus a our global $PATH gets updated and we get all the commands inside /usr/local/mysql/bin.
P.s.
if you are not running first command export directly but just running second in order to persist it? Than for current running instance of terminal you have to,
source ~/.bash_profile
This tells our terminal to reload that particular file.
That means /usr/local/mysql/bin/mysql is not in the PATH variable..
Either execute /usr/local/mysql/bin/mysql to get your mysql shell,
or type this in your terminal:
PATH=$PATH:/usr/local/mysql/bin
to add that to your PATH variable so you can just run mysql without specifying the path
for me the following commands worked:
$ brew install mysql
$ brew services start mysql
You can just modified the .bash_profile by adding the MySQL $PATH as the following:
export PATH=$PATH:/usr/local/mysql/bin.
I did the following:
1- Open Terminal then $ nano .bash_profile or $ vim .bash_profile
2- Add the following PATH code to the .bash_profile
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/mysql/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
3- Save the file.
4- Refresh Terminal using $ source ~/.bash_profile
5- To verify, type in Terminal $ mysql --version
6- It should print the output something like this:
$ mysql Ver 14.14 Distrib 5.7.17, for macos10.12 (x86_64)
The Terminal is now configured to read the MySQL commands from $PATH which is placed in the .bash_profile .
modify your bash profile as follows
<>$vim ~/.bash_profile
export PATH=/usr/local/mysql/bin:$PATH
Once its saved you can type in mysql to bring mysql prompt in your terminal.
You have to create a symlink to your mysql installation if it is not the most recent version of mysql.
$ brew link --force mysql#5.6
see this post by Alex Todd

Solaris 10 sudo configuration Issue

I am using SunOS 5.10 Generic_147441-24 i86pc i386 i86pc
if i run
which sudo
i get the below
/opt/sfw/bin
when i run "sudo -l" i get the below
User localuser may run the following commands on this host:
(root) NOPASSWD: /sbin/ifconfig
for "visudo"
visudo
-bash: visudo: command not found
also /etc/sudoers file does not exist in the box.
Please help me configure sudo, how it is possible with out the sudoers file.
Perhaps you should have a look at Sun (Oracle) RBAC for accounts, rather than rely on sudo in Solaris? It is unclear from your post why you must use sudo, but if you are not calling sudo from a script, it might be worth your while to read: http://docs.oracle.com/cd/E23824_01/html/821-1456/rbac-1.html
I've never seen the sudo binary exist in /opt, so my first thought would be that your visudo binary is not in your path, or the sudo package you installed does not contain the visudo binary. Either way you may consider downloading the sudo package again and reinstalling.
To see if your visudo binary exists anywhere:
find / -name visudo -print
If you find nothing, remember you do not explicitly need visudo to use sudo -- it's there as a checkpoint for making sure that you do not save and exit a sudoers file that has errors, thus possibly compromising your ability to edit it again or to break sudo for all users on the host.
Also note that /etc/sudoers can start off empty, just fill it in with your sudo rules. For example, to provide sudo all commands on that host for a user without prompting for a password:
userid ALL=(ALL) NOPASSWD: ALL
That particular user ID can run "sudo -l" to list the sudo rules available to it. You could do this even just to test that sudo is in fact working on your host.
You could easily get the location of the sudoers file from sudo binary itself by doing this
cat $(which sudo) | strings | grep /sudoers
Then, you would know what file to modify.

Sublime Text 2: can't create symlink to subl, says "bin/subl: No such file or directory"

I've downloaded and installed Sublime text 2. I am following the directions here: but I am stuck at this part:
The first task is to make a symlink to subl. Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run:
ln -s "/Applications/Sublime Text " ~/bin/subl
However, when I do this it tells me /Users/User/bin/subl: No such file or directory.
What should I do?
Thanks!
I'd recommend adding it to your local bin:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Edit: Make sure your local bin directory exists before running this command:
mkdir /usr/local/bin
I add my sym links to /usr/local/bin, for Sublime Text 3 I set mine up like so:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then you can open up the current directory list using:
subl .
If you find subl abbreviation annoying as some people I know seem to do, then change it to 'sublime'
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
And call it using:
sublime .
Alternatively, you can run this:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl
Note: The above snippet puts the symlink in /bin/subl rather than ~/bin/subl.
and that you have a ~/bin directory in your path
First, you need that directory for the ln command to work, and eventually, it will need to be in your path to do whatever it is you are trying to do.
To make the directory:
mkdir ~/bin
Adding it to your execution path is trickier, but there are plenty of resources available.
Following Simon's example above, For Sublime Text 3, here is what worked for me:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Please note, to install (on Mac OS Sierra 10.12.6) in /usr/local/bin sudo was required.
Info
OS: Mac OSX High Sierra 10.13.6 (17G65)
Sublime Version: Version 3.1.1 Build 3176
I took the command from SublimeText website
Got An Error
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln: /Users/jkirchoff/bin/subl: No such file or directory
Did Some Checking
Just to make sure the path exists.
NOTE: the "'s allow the space in the path.
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
ln: ./subl: File exists
Compared Note from this page
What #NotSimon wrote on this page, Then Ran:
ln -s "/usr/local/bin/subl"
ln: ./subl: File exists
and then followed the rest.
The Complete Line that worked for me:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Success
Now I can run subl as a command in Terminal!
This command opens the directory as a "Project" in SublimeText.
subl ~/Desktop
Optional
I followed the SublimeText recommendation & added this to my
~/.bash_profile.
The command works without it, just following guidelines.
echo "export EDITOR='subl -w'" >> ~/.bash_profile
Just remove tilde ~ from ~/bin/subl
If you're using mac terminal,
just replace "Sublime Text 2.app"
with "Sublime\ Text\ 2.app/" anywhere within the command.
That should do it.

How can I access the mysql command line tool when using XAMPP in OS X?

I've got a vanilla install of XAMPP in OS X. How can I access the mysql command line tool? I've tried typing "mysql" at the command line, and it spits back "-bash: mysql: command not found".
XAMPP is installed in Mac OS X in the following directory:
/Applications/XAMPP/
You can look what's inside that directory and run mysql command line tool providing the full path to it:
$ /Applications/XAMPP/xamppfiles/bin/mysql
If you need, you can modify your PATH environment variable to include XAMPP binaries and you won't need to specify the whole path all the time.
Open your .profile file in Mac. This can be done by entering the terminal and typing
pico ~/.profile
Add the following line to your ./profile file. Replace the path where you installed Xampp, however by default this is the route and should work:
export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
Open a new terminal window (Recommendation is to quit all terminal windows and then reopen) and type:
mysql
That is all, isn't easy!!
Before using the mysql command, make sure that you start up the server first by running
$ mysql.server start
Then you will be able to use the commands mysqladmin and mysql.
To shut it down, run
$ mysql.server stop
and to restart just use
$ mysql.server restart
Very intuitive.
Open terminal and Follow this bellow step to add mysql to your mac environmental variable
step 1:
sudo nano ~/.bash_profile
step 2:
export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
save it by control+x and then y and hit return. That's it!! now close the terminal and reopen
mysql --version
this will tell you which MySQL version you are using with xampp
Since I cannot comment on the accepted answer by Pablo Santa Cruz - Here's some additional info. If you're going to modify your PATH environment variable to include XAMPP binaries, make sure you add
/Applications/XAMPP/xamppfiles/bin
and not
/Applications/XAMPP/xamppfiles/bin/mysql
to the /etc/paths file. To do this run the command
sudo nano /etc/paths
then add the path to the file. Save using Ctrl+O and exit using Ctrl+X. Quit terminal and open again.

To have Vim-like K in Screen for MySQL

This question is based on this thread.
Problem: to access MySQL's manual when the cursor is at the beginning of the word by
Ctrl-A Esc Ctrl-m
where m reminds about Mysql.
How can you build a Vim-like K in Screen for MySQL's manuals?
Assuming you've installed the man pages from MySQL's documentation site:
Put the following in /path/to/mysql-help.screen:
# mysql-help.screen
# prevent messages from slowing this down
msgminwait 0
# copy term starting at cursor
copy
stuff " e "
# write term to a file
writebuf /tmp/screen-copied-term
# open that file in man in a new screen window
# (use `read` to pause on error, so user can see error message)
screen /bin/sh -c 'man `cat /tmp/screen-copied-term` || read'
# turn message waiting back on
msgminwait 1
# vi: ft=screen
Then add this to your ~/.screenrc
# Have CTRL-A ESC put you in a mode to accept commands in the 'escaped' class
bind \033 command -c escaped
# add CTRL-M as an 'escaped' class command to run the given screen script
bind -c escaped ^M source /path/to/mysql-help.screen
Then your keybinding should work. If you're using a different program to display
the manual other than man, you'll have to change the script accordingly.
The man pages for mysql that I found at the link above only include documentation
for the following commands:
mysqlbug mysqlhotcopy perror mysqldump resolveip mysqltest_embedded mysql_setpermission mysql_client_test mysql_find_rows mysql_fix_privilege_tables mysql_waitpid mysql_config mysql_client_test_embedded myisampack replace msql2mysql make_win_bin_dist my_print_defaults mysql-stress-test.pl mysqlaccess mysql_secure_installation mysql.server mysql_convert_table_format mysql_zap mysql_fix_extensions myisamlog myisam_ftdump mysqlbinlog mysql_install_db resolve_stack_dump mysqlslap mysql-test-run.pl mysqld_safe mysqladmin mysqlshow mysql_tzinfo_to_sql mysqltest mysqlbackup mysqld_multi mysql mysqldumpslow mysqlcheck mysql_upgrade mysqlimport comp_err mysqld myisamchk innochecksum
You may also want to consider adding
zombie kr
to your .screenrc, so that if you run the manual on a term that it doesn't recognize, screen doesn't automatically close the window (and hide the error message).
While I'm not sure how to start you off creating a wrapper for vim to do exactly what you want, I might make a suggestion on how you can achieve a similar effect with a function built into vim.
:! <command> will allow you to run shell commands with a similar interface to vim's K command. It might not be the cleanest way to do it, but by using :! you should be able to call the MySQL manuals for a given term quickly without completely leaving vim.
If you really need to write your own plugin for vim, this article might be able to give you some pointers and a handhold on where to start.
I hope this helps!
I love to recycle my Man -pages such that I can read easily manuals.
I suggests the following improvement to Rampion's command.
Rampion
screen /bin/sh -c 'man `cat /tmp/screen-copied-term` || read'
Me
screen /bin/sh -c 'man `cat /tmp/screen-copied-term` > /tmp/manual | less /tmp/manual'
My code gives you the percent sign to the bottom of a manual.