# user space command



## uslanmaz (Nov 29, 2009)

Hi Folks;

Can I create a new user space command in FreeBSD and how? I mean when a type "mycommand" I want to run something. is that possible?


----------



## aragon (Nov 29, 2009)

Trivially easy.  Could be as simple as an alias or as powerful as a shell script.


----------



## Beastie (Nov 29, 2009)

Or a binary program (written in C for e.g.) and located in $HOME/bin or - as a standard port - in /usr/local/bin/.


----------



## CodeBlock (Dec 2, 2009)

Just add the directory that the binary file (or chmod +x'd script) is in to your $PATH, or to make it globally available, throw it in /usr/local/bin/. If it's just for one user, I'd make a ~/bin/ and add that to $PATH.


----------



## vivek (Dec 3, 2009)

Spoon feeding examples:


```
mkdir ~/bin
```
create a script ~/bin/showopenports

```
#!/bin/sh
sockstat -4 -6
```
Set perms

```
chmod +x ~/bin/showopenports
```
Set path (add to your profile file):

```
set PATH = ( $PATH\:$HOME/bin )
```
OR

```
setenv PATH $PATH\:$HOME/bin
```
Run it

```
showopenports
```

For more info read tcsh man page.


----------



## Beastie (Dec 3, 2009)

Vivek, ~/bin/$HOME/bin already exist in both the filesystem and environment path.


----------



## vivek (Dec 3, 2009)

my bad  

this is what happen when you work with 12 types unix like oses everyday. Sometime at the end of day I type bsd or linux command on AIX or HP-UX and then wonders why it is not working .. lol


----------

