22
Jump to first page Unix Commands Monica Stoica Monica Stoica

Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Embed Size (px)

Citation preview

Page 1: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Unix Commands

Monica StoicaMonica Stoica

Page 2: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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).

Page 3: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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

Page 4: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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

Page 5: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Changing the prompt If you got tired of the (login) %

prompt, you can type set set prompt=“Any message you prompt=“Any message you want ”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 Make sure you leave a space between the end of your between the end of your message and the ending “.message and the ending “.

Page 6: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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 . Ctrl-h . It will erase one typed It will erase one typed character every time you press character every time you press it. it.

Do NOTNOT put spaces, capital letters or unusual characters (as !!) in file names..

For more information on a command type man commandman command.

Page 7: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Password If you want to change your password, type

passwdpasswd 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.

Page 8: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Finding the time, date and calendar of any year

If you type date 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 yearcal 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.

Page 9: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The whowho command Since Unix is a time-sharing system, several people can

use the system at the same time. By typing whowho 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 Iwho 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 > turkeywho > 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 turkeycat turkey to view the file.

Page 10: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The finger command General form: finger option argumentfinger option argument finger command without an argumentfinger 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-m obligates finger to look only for those people who’s login names match the argument name. For example finger -m smonicafinger -m smonica will search for only the people who’s login name is smonica.

Option -l-l forces finger to give the results in long format, and the option -s-s to give it in short format.

Page 11: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

More on finger 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 johnfinger -s john or finger -l johnfinger -l john depending on whether you want a short form or along form. It will It will search for all the people who’s first search for all the people who’s first name, last name or login is john.name, last name or login is john.

Page 12: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Sending e-mail fast without opening pine

At the (login) % prompt type mail loginmail login (the login of the person you want to send an email). Press Enter.

Then type Subject: here type your Subject: here type your subjectsubject. Press Enter and type the message you want to send.

When you are done type Enter and then Ctrl-dCtrl-d, and you should get a (login)% prompt.

Page 13: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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 rootroot.

One of root branches is called coursecourse 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.

Page 14: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The ls command General form: ls option argumentls 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 directorynamels -l directoryname will list all files and

subdirectories of that directory in long format. Typing only lsls will give the current working

directory.

Page 15: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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 dd, 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.

Page 16: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Example of an ls command result This is an example of an ls command result: -rwxr-xr---rwxr-xr-- The first hyphen - shows that this is a file the next three letters rwxrwx show that the owner has

read, write and execute permission on that file, the next group of three r-xr-x show that the group the

owner belongs to has only read and execute permission

the last three r--r-- show that the rest of the world has only read permission on that file.

Page 17: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The cat command general form: cat argumentcat argument The cat command is used to concatenate and

display files. Concatenate means to link together. Typing cat file2cat 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.

Page 18: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The wc word count command

General form: wc option argumentwc option argument example: wc file2wc 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

Page 19: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

Copy Command General form1: cp option argumentcp option argument cp file1 file2cp 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 directorycp file1 file2 directory this copies the list of the files given into the directory

which must already exist. The originals are kept in place.

Page 20: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

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 file2mv 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 mv directory1 directory2directory2).

Option -i-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 directorymv file1 file2 directory

Page 21: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

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.

Page 22: Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision

Jump to first page

The rm command

If you want to remove a file, type rm filerm file

Once that you removed it, it’s gone for good.

This is the end of the This is the end of the presentation! presentation!