Too often I figure out how to do this or that on Linux systems and in my haste to complete whatever task I've been assigned this "How To" knowledge gets lost. So here, I will begin posting little odds and ends in hopes of not needing to re-research past efforts for Linux tips, tricks, hacks, and other good to know things. If you find yourself here and know of smaller, faster, better ways of doing any of this please let me know - only through cooperation can we all get better.
Thursday, June 21, 2012
Set tabstop in VI - Mac OSX
From within VI
(Assuming you would like to use four spaces for your tabs)
:set tabstop=4
To make this behaviour the default:
user@machine:~$ cd ~
(if ~/.exrc does not exist, create it. Otherwise skip to next cmd.)
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc
Add the following line to the file:
set tabstop=4
Save and close .exrc
user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt
Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set tabstop=4"
Save .exrc
Source .exrc
Test to verify function.
This should also work in most flavors of *nix.
~Fin
Thursday, March 31, 2011
Using custom shell scripts on Linux & OSX
1. Create a `bin` directory to store your script.
machine:~ user$ mkdir ~/bin
For Linux users this will create /home/[user]/bin, for OSX you'll have /Users/[user]/bin. You could name this directory whatever you'd like, but bin seems fitting.
2. Modify .bashrc or .bash_profile to put `bin` on your path.
If you're comfortable with vi you can: (Alternatively use any text editor you are comfortable with)
machine:~ user$ vi ~/.bash_profile [OSX]
user@machine:~$ vi ~/.bashrc [Linux]
Either way, add the following line:
PATH=$PATH:$HOME/bin
3. Save and exit.
4. Source your file for it to take effect:
machine:~ user$ . ~/.bash_profile [OSX]
user@machine:~$ . ~/.bashrc [Linux]
5. Now you can drop a shell script into your bin directory and have executable from anywhere on your filesystem (don't forget to make it executable!)
Example:
Last login: Thu Mar 31 11:07:30 on ttys004
machine:~ user$ pwd
/Users/user
machine:~ user$ touch example
machine:~ user$ vi example
...
#!/bin/sh
echo "Somewhere in Russia a little girl is warming up with your max."
...
machine:~ user$ mv example ~/bin/
machine:~ user$ chmod +x ~/bin/example
machine:~ user$ ls -l ~/bin | grep example
-rwxr-xr-x 1 user staff 80 Mar 31 14:25 example
machine:~ user$ cd /tmp/
machine:tmp user$ example
Somewhere in Russia a little girl is warming up with your max.
machine:tmp user$
Fin
Lift weights - Lift spirits
Monday, October 12, 2009
Show line numbers in VI - Ubuntu Linux 9.04 Jaunty/Mac OS X
Update - verified to work also with Mac OS X
From within VI
:set number
To make this behaviour the default:
user@machine:~$ cd ~
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc
Add the following line to the file:
set number
user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt
Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set number"
Save .exrc
Source .exrc
Test to verify function.
Update (as I've had to look this up twice now...)
To turn off line numbers from withing VI
:set nonumber
~Fin