Dave's quickie *nix command summary
This is just meant to be a quick overview of some linux/unix commands
and their uses, aimed at new users to the system, operating in
a command line environment (e.g. ssh, rlogin, dtterm, etc).
Disclaimer: this list was originally
created for use on a unix system, some modifications may
be necessary for debian linux.
All data in the system is recorded in files (eg. source code files, executable files,
text files, etc).
The commands below give you the ability to manipulate the
names and contents of your files.
- pico filename - use the pico editor to create or
modify a file, control-O saves the file (prompts you with the name before
it saves) and control-X quits the editor
- vi filename uses the vi editor (instead of pico).
For a quick list of vi commands, click here.
- ls - list the files in the current directory
- ls blah* - lists all files in the current directory which
start with pattern blah. Similarly ls *blah would list
all files in the current directory which end with pattern blah
- cat filename - scroll the file across your screen
- more filename - allows you to look at a file but
not alter it (less is a similar tool), `q' will get you out of
more and less
- mv oldfilename newfilename - allows you to rename,
or move, a file
- mv filename directoryname - allows you to move
a file into another directory
- rm filename - allows you to delete a file
- cp originalfile newfile - allows you to copy a file
- du . - displays the amount of disk space taken up by
the current directory and all the files and directories it contains
- df - displays statistics on the free disk space on the system
- sort filename - prints out the contents of the file
in sorted order
- diff filename1 filename2 - compares the two files,
prints out a list of all the lines in the two files which are not identical
- wc filename - counts the number of lines, words, and
characters in the file
Files can be organised into directories, i.e.
a directory is just something which contains a number of files.
Every time you log on to the system you start in your home directory.
Afterwards you can use various forms of the cd command to move from
one directory to another.
A file is described by a path (through various directories) and the file's name.
You can place one directory inside another,
for example your home directory may contain (in addition to a number of files)
a directory named practicals.
Inside this directory you may place another directory named prac02,
inside this directory you may place a file named myprogam.cpp.
From your home directory you could refer to this file by the path+name:
practicals/prac02/myprogram.cpp
The commands below give you the ability to create, manipulate, and
move around in directories.
- cd - takes you to your home directory
- cd ~blah - takes you to the home directory of the
person whose login id is blah
- cd .. - takes you to the directory `containing' the current
one (one level up the directory tree)
- cd directoryname - moves you into the specified directory
- mkdir directoryname - creates a new directory
- cp -r oldname newname - copies a directory and
everything in it
- mv oldname newname - renames a directory
- rmdir directoryname - removes an empty directory
- rm -r directoryname - removes a directory and
everything in it
- pwd - lists exactly where the current directory is in
the overall system directory
Ordinarily, when you run a command or program the output is sent to your screen.
You can instead direct the output to a file or to another command or program as follows:
- command > filename - puts
the output from the specified command into a new file
- command >> filename - appends
the output from the specified command onto the end of the specified file
- command1 | command2 - takes all
the output from command1 and uses it as input to command2
When you are logged on to the system, there are a number of ways
you can communicate with other people who are logged on to the system.
These include:
- talk userid - requests a talk session with the
user (assuming they are currently logged in), if they then type in
talk yourid a connection will be established (control-D
to quit once you're done)
- write userid blahblahblah - sends the
message to the screen of the other user
- mesg n - prevents other users from popping up talk requests
and write messages on your screen (mesg y will allow them again)
- finger userid - determines if the user is currently
logged on
There are a wide variety of commands available to let you
control the execution of your programs, and to obtain information
about the execution of your programs.
- g++ blah.cpp -o blah
- compiles the C++ source code for a program, stored in blah.cpp,
and places the resulting
executable file in blah.
- To run the program blah in the directory
you are currently in, type ./blah
- to kill the currently running job use control-C
- to suspend the currently running job use control-Z
- to start a suspended job up in the background (i.e. you can
still enter other commands while it's running) enter bg
- to move a background job into the foreground (i.e. it takes over
your terminal/window again) enter fg
- to schedule a command to run at a specific time/day (even if you
aren't going to be around and logged on then) use the at command, for example:
at 11:00pm October 7 commandname
- ps - get a list of processes you have running right now,
the very first field (PID) give you an ID number for the process
- kill -9 number - kills the job with the specified
PID number (you can only kill your own jobs)
- nice commandname - runs the command but at a lower than
normal priority (being nice to other users by not hogging the system)
- time commandname - times the running of the specified command
- which commandname - determines which directory
the executable for the specified command is stored in
- set history=n - sets history to remember the last
n commands you ran
- history - gets a list of the commands you've run recently
- ^old^new - repeats the previous command, but changes the
substring old to the substring new when you run it
this time (useful if you make a typo in a long command)
- !! - repeats the last command
- !pattern - repeats the last command that begain with pattern
There are a wide variety of other commands on the system which
may be useful from time to time.
These include:
- man commandname - online help for a command
- man -k keyword - searches for commands related to the keyword
- date - displays the current time and date
- who - displays a list of the users currently on the system
- users - gives a shorter-format list of who is currently logged on
- w - displays a list of what all the system users are currently doing
- whoami - displays your loginid
- groups - displays a list of the groups you are a member of
- env - displays the current settings of your terminal characteristics
- reset - re-initialises the terminal settings
- uptime - shows the recent system load and the length of time
the system has been up and running
- hostname - gives the full name of the machine you're on
The command to change your password is passwd.
For information on what constitutes a ``safe'' password see this
note by John Miller.
The Unix environment was originally designed to allow easy sharing of
code and files between different users. The owner (creator) of a file
or directory can determine, to an extent who can read (r) the file/directory,
who can edit (w) the file, who can execute (x) the file (if it is
an executable program), and who can cd into a directory.
When you are setting up access permissions so people can/cannot
use your files, people are divided into three different categories:
- u - user, this means you
- g - group, this usually means people taking a similar program to you
- o - other, this means everyone
Giving/Taking away permissions:
You set permissions to your files using the chmod command.
To give all types of users permission to read a file, you would enter
chmod ugo+r filename
To take away read permission for a file (so you can read it but
no one else can) you would enter
chmod go-r filename
To take away read, write, and execute permissions from a file
for everyone but yourself, you would enter
chmod go-rwx filename
To give everyone access to cd into one of your directories, use the command
chmod ugo+x directoryname
NEVER EVER *EVER* GIVE WRITE PERMISSION TO THE GROUP OR OTHER
CATEGORY FOR ANY OF YOUR FILES OR DIRECTORIES -- THIS IS A SECURITY HAZARD
Finding out who can use your files right now:
If you type in ls -l you will get a list of all your files and
directories, one per line.
The first thing on the line will have 10 characters, something like
-rwxr-xr-x
The 10 characters (from left to right) indicate:
- d means it is a directory, - means it is a file
- r means user (creator) has read access, - means user does not
- w means user has write (modify) access, - means user does not
- x means user has execute or cd access, - means user does not
- r means group has read access, - means group does not
- w means group has write (modify) access, - means group does not
- x means group has execute or cd access, - means group does not
- r means everyone has read access, - means users at large do not
- w means everyone has write (modify) access, - means users at large do not
- x means everyone has execute or cd access, - means users at large do not
Copyright © 1997, David M. Wessels. Revised September, 2000.
All rights reserved.