Unix Commands - Directory | CS

Download Report

Transcript Unix Commands - Directory | CS

Unix Commands
Monica Stoica
Jump to first page
Introduction to Unix


Unix was born in 1969 at Bell Laboratories, a research
subdivision of American Telephone and Telegraph
Company.
Unix system has two kinds of software:
 the
operating system software
 the application software like pico, pine, emacs, etc.

Some of the functions of the Unix operating system are:
 it
provides a filing system (write, copy, rename, move files)
 it provides for the loading and executing of the user
programs
 it provides a communication link between the computer
and its accessories (input-output devices as terminals,
printers, disks, etc).
Jump to first page
Additional Features of
the Unix System

Multi-user time-sharing
 several
people at different
terminals can use the computer at
the same time.

Multitasking
 one
user runs several computing
jobs simultaneously
Jump to first page
Unix Shell




The Unix shell is a command line interpreter, or a
program that forms a link between users and the
computer.
The shell accepts commands that you type into the
computer, and then it executes them.
The shell contains over 100 built-in commands for
your use. At the shell % prompt you can type your
commands.
There are 2 widely used shells:
 Bourne
shell provided with the standard Bell Labs version
of Unix
C
shell developed at the University of California, Berkeley
Jump to first page
Changing the prompt



If you got tired of the (login) %
prompt, you can type set
prompt=“Any message you
want ” and every time you
come back to the shell prompt
your message will show up
instead of the (login) %.
Unix will reset this back to
(login)% when you logout.
Make sure you leave a space
between the end of your
message and the ending “.
Jump to first page
TIPS



In case the backspace key does
not work when you try to erase
something at the Unix prompt,
try pressing simultaneously
Ctrl-h . It will erase one typed
character every time you press
it.
Do NOT put spaces, capital
letters or unusual characters (as
!) in file names.
For more information on a
command type man command.
Jump to first page
Password



If you want to change your password, type
passwd at the (login) % prompt. You will
be prompted to enter your old password,
the new password, and to retype the new
password.
You should have at least one digit in your
password.
When you choose your new password
remember that Unix is case-sensitive and
even a space is considered a character.
Jump to first page
Finding the time, date and
calendar of any year



If you type date at the (login) % prompt, you will
get the date of the current day, the day of the
week, and the current time.
If you type cal 03 1776 at the shell prompt, you
will get the calendar of the March, 1776. If you do
not enter a month (that is, you type only cal year)
you will get all twelve months of that year.
Tips:
you can type cal month year of your birth and find
out what day of the week you were born!
 the year should be in the range 0-9999 AD.

Jump to first page
The who command




Since Unix is a time-sharing system, several people can
use the system at the same time.
By typing who you will get a list with all the people logged
in at that moment. The leftmost column shows the
terminal at which the person is working, the next column
shows the date and the rightmost column shows the
computer number (IP number).
If you type who am I you will get information about
yourself. You can also use this command in case
somebody forgot to logout of unix and you want to know
who that person was.
Typing who > turkey will create a file called turkey and
write on it all the information listed as a result of the who
command. You can type cat turkey to view the file.
Jump to first page
The finger command




General form: finger option argument
finger command without an argument gives the same
result as who command, but also gives the full name
of each person. It also gives the idle time in minutes
since the person last gave a Unix command.
Adding the option -m obligates finger to look only for
those people who’s login names match the argument
name. For example finger -m smonica will search for
only the people who’s login name is smonica.
Option -l forces finger to give the results in long
format, and the option -s to give it in short format.
Jump to first page
More on finger command

If you want to find out all the
people with the name or login john
who have an account in Unix, type
finger -s john or finger -l john
depending on whether you want a
short form or along form. It will
search for all the people who’s first
name, last name or login is john.
Jump to first page
Sending e-mail fast without
opening pine



At the (login) % prompt type mail login
(the login of the person you want to send
an email). Press Enter.
Then type Subject: here type your
subject. Press Enter and type the
message you want to send.
When you are done type Enter and then
Ctrl-d, and you should get a (login)%
prompt.
Jump to first page
Files and Directories



While working with files and directories it will
help if you think about Unix as a big tree. All
directories in Unix stem from / , also called root.
One of root branches is called course for
students’ directories. All users’ home directories
stem from course.
On the next pages you’ll learn how to create
directories and files, move or copy files from one
directory to another, and much more.
Jump to first page
The ls command

General form: ls option argument. Some of the
options are:
 -c
lists by last change
 -l lists in long format, giving links, owner, size in
bytes, and time of last file change


typing ls -l directoryname will list all files and
subdirectories of that directory in long format.
Typing only ls will give the current working
directory.
Jump to first page
The ls command



The information on the leftmost part shows the
permissions of read, write and execute on each
listing.
If the first character is a d, it means that is a
directory. A hyphen - indicates a file.
The next three characters show the
permissions of the owner on that file or
directory, the next three the permissions of the
group the owner belongs to, and the last three
characters show the permissions of the rest of
the world on that file or directory.
Jump to first page
Example of an ls command result






This is an example of an ls command result:
-rwxr-xr-The first hyphen - shows that this is a file
the next three letters rwx show that the owner has
read, write and execute permission on that file,
the next group of three r-x show that the group the
owner belongs to has only read and execute
permission
the last three r-- show that the rest of the world has
only read permission on that file.
Jump to first page
The cat command





general form: cat argument
The cat command is used to concatenate and
display files. Concatenate means to link together.
Typing cat file2 will display on the screen file2
assuming that this file2 already exists.
You can use cat > newfile to create a new file and
to enter text into it.
You can use cat file2 file3 >> file4 to append file2
and file3 to the end of the file4. If file4 does not
exist, it is created now to receive the input from
file2 and file3.
Jump to first page
The wc word count command



General form: wc option argument
example: wc file2 will list from left
to right the number of lines, words,
and characters of file2.
options:
 -w
counts only words in a file
 -c counts only characters in a file
 -l counts only lines in a file
Jump to first page
Copy Command



General form1: cp option argument
cp file1 file2 creates a copy of file1 and gives it the
name file2. If a file named file2 already exists, it will
be replaced by the new one.
Options:
 -i
protects you from overwriting an existing file by
asking you for yes or no before it copies a file with an
existing name.
 -r can be used to copy directories and all their
contents into a new directory

General form 2: cp file1 file2 directory
 this
copies the list of the files given into the directory
which must already exist. The originals are kept in
Jump to first page
place.
The Move Command




The mv command lets you change the name of a file
or directory and lets you move a file from one
directory to another.
mv file1 to file2 will change the name of file1 to file2.
The file itself is unchanged. If a file named file2
already existed, it will be replaced by the content of
file1. Same thing applies for directories (mv
directory1 directory2).
Option -i: it will ask you before it copies to a file with
an existing name.
You can move files to an existing directory by typing:
mv file1 file2 directory
Jump to first page
Differences between cp and mv


The cp command creates a new
file with a new ID number and with
its own link (name) to a directory.
The old file continues to exists.
The mv command creates new
names for the existing files and
dumps the old names. It does not
create a new file.
Jump to first page
The rm command



If you want to remove a
file, type rm file
Once that you removed
it, it’s gone for good.
This is the end of the
presentation!
Jump to first page