Unix Workshops:commands

About the System
--- First we used passwd to change our password.

Now, let's find out what kind of OS we're running. Type uname.

uname is the command, then we can add options and arguments.

In uname -a the -a is the option. This will reveille more information about our OS.

gpart lets us look through the disks. Type it and see your available options and arguments.

Add the argument 'show' (gpart show) to look through the partitions.

Add the option '-p' to this lot (gpart show -p) to also see the partition names.

df</tt> will show you how much free space you've got on the system

vmstat</tt> free memory

iostat</tt> input-output status and rates

pstr</tt> - process tree

File system
mount</tt> will show you where these disks are mounted. "/" means root.

pwd</tt> prints out the current working directory.

ls</tt> will print all the files and directories from our current working directory.

One option for ls</tt> will be "-l" (long) for the long version (ls -l</tt>) where you will see columned details for each file or directory;


 * Column 1: Permissions. The first letter is 'd' for directory and 'l' for file. The other letters divide into three groups of 3 letters. These are the permissions for each user type (3, 3, 3 => user, group, everyone else) respectively.
 * Column 2: Amount of hard links to the file.
 * Column 3: Owner.
 * Column 4: Group.
 * Column 5: Byte size.
 * Column 6: Last modified.
 * Column 7: Name

The 5th column is file size in Bytes. In case you have large files you might wish to see a more human readable version, use the option '-h' (human readable) which will add other size formats: B, k, m etc.

You can either type in ls -l -h</tt> or ls -lh</tt>

chmod</tt> will modify the file permissions. chmod 700 $file</tt> where 7 (8 bits), for example, stands for "rwx" (all permissions) for 'user'.

and the others stand for different permission combination

ls -a</tt> will also show hidden files

To navigate through the directories, use cd</tt> to drill into a directory: cd etc</tt> will lead you to the directory holding all the configuration files. You can use <tt>cat</tt> to see the contents of the file. Try <tt>cat rc.conf</tt> to see the basic configuration for the system.

Type just <tt>cd</tt> to get to your own home directory


 * one dot (.) represents the current directory, two dots (..) represent one directory up. So in order to go one directory up the tree type <tt>cd ..</tt>

"etc/rc.d" has all the scripts to run the demons, one of which is "sshd" which should be enabled in order for us to log into the system remotely.

"ntpd" is the network time protocol demon.

<tt>mv</tt> will move or rename a file

<tt>mkdir</tt> make a directory

<tt>mkdir -p</tt> for nested directory: <tt>mkdir -p one/two/three</tt>

<tt>rm</tt> remove file

<tt>rmdir</tt> will remove a folder as long as it's empty

<tt>rm -r</tt> will remove a directory, regardless

<tt>cp</tt> for copy

"tree" is a program which will print a tree representation of the directories

<tt>tree -L 2</tt> will only go 2 levels deep

">" will redirect output to a file. If the file is not there, it will create one for you.

<tt>ls -l > ls.txt</tt> will create a new file with the contents of the "ls" command.

Process Status
We'll use  and see the process statuses. We can see "ntpd" is running and using it's configuration file

<tt>cat etc/ntpd.conf</tt> will show the configurations

<tt>ps auxww</tt> will show all the processes currently running on the system

<tt>pkill $processName</tt> will kill the process

Using a text editor
We'll use "nano" first.

<tt>sudo nano /etc/rc.conf</tt> then you can add <tt>ntpd_enable="YES"</tt> and the next time the machine turns on, it will be enabled. Still, in order to run it now we'll print

<tt>sudo</tt> is the program that allows us to edit files with root permission.

Editors

 * <tt>vimtutor</tt> will teach you how to use "vim"

"ed" is an editor, but it will only show you one line at a time

"vi" is the visual editor, and it will allow you to see the entire file. We recommend using "vim".

It is very important to remember, <tt>:q</tt> quits the program, and <tt>:q!</tt> will force quit.

"emacs" will also be installed to this system

For just reading through files we can use "less"

<tt>/$word</tt> is for search. [n] will jump next

"head" will give us the first lines only.

<tt>head -n 30</tt> is for just the first 30 lines. where "head" is the command, "-n" is the option and "30" is the argument

"tail", on the other hand, gives the other end.

We will use a long and stupid way to check if a process is currently running on the system.

<tt>ps auxww > ps.txt</tt> will create and print to this file all of the running processes.

<tt>less ps.txt</tt> will show the contents of the file so we can search it.

A more reasonable way to tackle this task is to just look through the text, we can use "grep" <tt>ps auxww | grep</tt>

Where the pipeline ("|") will pipe the output from one program to another program.

<tt>grep $word $filename</tt> outputs the lines from the file or the output it was given (<tt>-n</tt> will give you the line number)

<tt>ps auxww | grep sshd</tt> will find the lines containing "sshd" in that output.


 * <tt>wc</tt> is word count (lines, words, characters)

Files
Go to your home directory and create an empty file. Use <tt>touch</tt> for that.

<tt>touch garbage_file.avi</tt> will create a simple file with this name.

Fill it with some data. The "random" program will supply with random data, you can direct the output of that file like so:

Now random data is written into your new file. You'll need to stop the operation at some point. Using CTRL+C will kill the process.

You can find out what kind of file this is using "file" like so:. The file type is "data" because this file doesn't have any valid headers, it's just garbage.

SHELL
<tt>echo $SHELL</tt> will show you the shell you're using. "zsh" and "bash" are two examples of shells.

It is very handy to use <tt>man</tt> for manual. add an argument of the program you wish to explore. Try <tt>man ls</tt>. <tt>man hier</tt> shows the hierarchy. Have a look around.

CTRL+D will drop us out of shell process (try it later when you use "screen")

Multiplexer
<tt>&</tt> at the and of your command will let you run the terminal while the command you've just executed is still running. It will print everything when it happens.

This can be useful at times. Other times it can be annoying. Enter "screen". <tt>screen</tt> is a terminal multiplexer.

create another window: "CTRL+A" and then "C" for create "N" for next and "P" for previous. "K" for killing Screen. "D" for detach

<tt>screen -ls</tt> will list the detached Screens <tt>screen -Ar</tt> - reattach