UNIX/Linux

Adding users & groups on Solaris

March 20th, 2006

To create a group:

groupadd <groupname>

To create a user, create their home directory and add them to a group:

useradd -m -d <path/to/home/username> -g <groupname> <username>

To add an existing user to a group:

usermod -g <groupname> <username>

Comments are closed.

Finding files that contain certain text

December 11th, 2005

I keep forgetting how to do this and then having to look it up. So here, for quicker access next time I forget, is how it's done:

To find files in or below the current directory that contain the text string "if I only had a brain" enter the command:

find . -type f -print | xargs grep 'if I only had a brain' | more

Thanks to:
www.geocities.com/samarstan/linux/penguin/linuxuser.html
for reminding me how it was done on this occasion.

Comments are closed.



Find a host name given an IP address

November 8th, 2005

Question:
I'm logged in to a UNIX machine. How do I find out the host name of a computer on the local network if I only have its IP address?

Answer:
Use the command:
ypcat hosts | grep "<IP address>    "

Where that space before the closing quote is a tab that you enter by pressing the TAB key.

Note: If you're in the bash shell you will need to press Ctrl+v before pressing TAB. Ctrl+v means "treat what I type next literally". (You're most likely to use it in vi when you want to enter or search for a control character. For example, if you want to delete all Ctrl+M characters you can enter :%s/^M$//g by pressing Ctrl+v Ctrl+M to give you the ^M character.)

For example, if you enter:

ypcat hosts | grep "192.100.123.456    "

The output will be something like:

192.100.123.456 hermes.yourorg.com hermes
192.100.123.456 hermes.yourorg.com hermes

In which case the host name is hermes.

See also:
Find an IP address given a host name

Leave a comment



Listing the files/directories in a directory

June 2nd, 2005

In UNIX I enter the command ls and I get back a list of files and directories in the current directory. The trouble is, there's no way of knowing which are files and which are directories. What I really need is just a list of the files (not the directories), one per line, so that I can copy this into some document or program.

The first step is to use a long listing ls -l rather than just ls.

This lists the directory contents one per line, giving lots of information about each file and directory. The listing comprises 9 columns. If the first column start with a 'd' the item is a directory. If it starts with a '-', it's a file. The last column of the listing contains the file/directory names.

So what I want to do is:
1) Do a long listing.
2) Filter out the directories, based on the first letter of each line.
3) Remove everything except the last column, so that I have a simple list of files.

This is easily done using grep to filter out the listing and awk to print just column number 9. The following command uses pipes to pass the output from ls to grep and then on to awk:

ls -l | grep '^-' | awk '{print $9}'

If I'd wanted a list of directories, I could have changed the '-' to 'd':

ls -l | grep '^d' | awk '{print $9}'

Leave a comment



What version of Solaris

April 5th, 2005

To find out what version of Solaris a server is running, use the command:

uname -a

This returns something like:

SunOS sandbox 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Fire-280R

SunOS 5.6 is Solaris 2.6
SunOS 5.7 is Solaris 7
SunOS 5.8 is Solaris 8

Leave a comment



^ back to top ^

Page 4 of 9« FirstNewer23456OlderLast »