Unix Workshops:commands

(Redirected from Unix-workshop:commands)
Jump to navigationJump to search

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 will show you how much free space you've got on the system
vmstat free memory
iostat input-output status and rates
pstr - process tree

File system

mount will show you where these disks are mounted. "/" means root.
pwd prints out the current working directory.
ls will print all the files and directories from our current working directory.

One option for ls will be "-l" (long) for the long version (ls -l) 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 or ls -lh

chmod will modify the file permissions. chmod 700 $file where 7 (8 bits), for example, stands for "rwx" (all permissions) for 'user'.
and the others stand for different permission combination

ls -a will also show hidden files

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

Type just cd 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 cd ..

"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.
mv will move or rename a file
mkdir make a directory
mkdir -p for nested directory: mkdir -p one/two/three
rm remove file

rmdir will remove a folder as long as it's empty
rm -r will remove a directory, regardless
cp for copy

"tree" is a program which will print a tree representation of the directories
tree -L 2 will only go 2 levels deep

">" will redirect output to a file. If the file is not there, it will create one for you.
ls -l > ls.txt will create a new file with the contents of the "ls" command.

Process Status

We'll use ps aux | grep ntp and see the process statuses. We can see "ntpd" is running and using it's configuration file
cat etc/ntpd.conf will show the configurations
ps auxww will show all the processes currently running on the system
pkill $processName will kill the process

Using a text editor

We'll use "nano" first.

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

sudo is the program that allows us to edit files with root permission.


  • vimtutor 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, :q quits the program, and :q! will force quit.
"emacs" will also be installed to this system

For just reading through files we can use "less"
/$word is for search. [n] will jump next
"head" will give us the first lines only.
head -n 30 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.
ps auxww > ps.txt will create and print to this file all of the running processes.
less ps.txt 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" ps auxww | grep
Where the pipeline ("|") will pipe the output from one program to another program.
grep $word $filename outputs the lines from the file or the output it was given (-n will give you the line number)
ps auxww | grep sshd will find the lines containing "sshd" in that output.

  • wc is word count (lines, words, characters)


Go to your home directory and create an empty file. Use touch for that.
touch garbage_file.avi 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: cat /dev/random > garbage_file.avi
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: file garbage_file.avi. The file type is "data" because this file doesn't have any valid headers, it's just garbage.


echo $SHELL will show you the shell you're using. "zsh" and "bash" are two examples of shells.
It is very handy to use man for manual. add an argument of the program you wish to explore. Try man ls. man hier shows the hierarchy. Have a look around.
CTRL+D will drop us out of shell process (try it later when you use "screen")


& 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". screen 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
screen -ls will list the detached Screens screen -Ar - reattach

Workshop notes: