An Introduction to Linux
&
Contents
A quick guide to Linux
Background Using Linux
Additional Resources
What is Linux
A fully-networked 32/64-Bit Unix-like Operating System
Unix Tools Like sed, awk, and grep (explained later)
Compilers Like C, C++, Fortran, Smalltalk, Ada
Network Tools Like telnet, ftp, ping, traceroute
Multi-user, Multitasking, Multiprocessor
Has the X Windows GUI
Coexists with other Operating Systems Runs on multiple platforms Includes the Source Code
Where did it come from?
Linus Torvalds created it
with assistance from programmers around the world first posted on Internet in 1991
Linux 1.0 in 1994; 2.2 in 1999 Today used on 7-10 million computers
with 1000s of programmers working to enhance it
Why is it significant?
Growing popularity Powerful
Runs on multiple hardware platforms Users like its speed and stability No requirement for latest hardware
Its free
Licensed under GPL Vendors are distributors who package Linux
Linux/390
Using it
Logging In
Connect to the Linux system using telnet:
vt100, vt220, vt320 ansi tty X-windows
Able to login more than once with same user No MW problems!
Logging In
Before you can use it you must login by specifying your account and password:
Linux 2.2.13 (penguinvm.princeton.edu) (ttyp1)
penguinvm login: neale Password: Last login: Tue Jan 4 10:13:13 from linuxtcp.princeton.edu [neale@penguinvm neale]$
Rule Number 1
Do not login as root unless you have to root is the system superuser (the maint of Linux but more dangerous)
Normal protection mechanisms can be overridden Careless use can cause damage Has access to everything by default
root is the only user defined when you install
First thing is to change roots password The second job is to define normal users for everyday use
Creating a new user
Use the useradd command Use the passwd command to set password [root@penguinvm]# useradd Try it logon as root scully
[root@penguinvm]# passwd scully Changing password for user scully New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully [root@penguinvm]#
Adding a new user
Limits on users can be controlled by
Quotas ulimit command
Authority levels for a user controlled by group membership
Users and Groups
Groups define functional areas/responsibilities They allow a collection of users to share files A user can belong to multiple groups You can see what groups you belong to using the groups command:
neale sys adm
Using the new user
Now logoff using the exit command login as the new user
Linux 2.2.13 (penguinvm.princeton.edu) (ttyp2)
penguinvm login: scully Password: [scully@penguinvm scully]$
You need help?
The Linux equivalent of HELP is man (manual)
Use man -k <keyword> to find all commands with that keyword Use man <command> to display help for that command
Output is presented a page at a time. Use b for to scroll backward, f or a space to scroll forward and q to quit
The Linux System
User commands includes executable programs and scripts
The shell interprets user commands. It is responsible for finding the commands and starting their execution. Several different shells are available. Bash is popular,
User commands Shell Kernel
File Systems Device Drivers
The kernel manages the hardware resources for the rest of the system.
Hardware
Linux File System Basics
Linux files are stored in a single rooted, hierarchical file system
Data files are stored in directories User home directories (folders) Directories may be nested as deep as needed
Data files Directories root
Naming Files
Files are named by
naming each containing directory starting at the root
This is known as the
pathname
/etc/passwd
/home/neale/b
The Current Directory
One directory is designated the
current working directory
if you omit the leading / then path name is relative to the current working directory Use pwd to find out where you are
Current working directory
doc/letter ./doc/letter /home/neale/doc/letter
Some Special File Names
Some file names are special:
/ . .. ~ The root directory (not to be confused with the root user) The current directory The parent (previous) directory My home directory
Examples:
./a same as a ../jane/x go up one level then look in directory jane for x
Special Files
/home - all users home directories are stored here /bin, /usr/bin - system commands /sbin, /usr/sbin - commands used by sysadmins /etc - all sorts of configuration files /var - logs, spool directories etc. /dev - device files /proc - special system files
Linux Command Basics
To execute a command, type its name and arguments at the command line
ls -l /etc
Command name
Options (flags) Arguments
Redirecting Output
The output of a command may be sent (piped) to a file:
ls -l >output
> is used to specify the output file
Redirecting Input
The input of a command may come (be piped) from a file:
wc <input
< is used to specify the input file
Common Commands
pwd - print (display) the working directory cd <dir> - change the current working directory to dir ls - list the files in the current working directory ls -l - list the files in the current working directory in long format
File Commands
cp <fromfile> <tofile>
Copy from the <fromfile> to the <tofile>
mv <fromfile> <tofile>
Move/rename the <fromfile> to the <tofile>
rm <file>
Remove the file named <file>
mkdir <newdir>
Make a new directory called <newdir>
rmdir <dir>
Remove an (empty) directory
More Commands
who
List who is currently logged on to the system
whoami
Report what user you are logged on as
ps
List your processes on the system
ps aux
List all the processes on the system
echo A string to be echoed
Echo a string (or list of arguments) to the terminal
File Permissions
Every file
Is owned by someone Belongs to a group Has certain access permissions for owner, group, and others Default permissions determined by umask
File Permissions
Every user:
Has a uid (login name), gid (login group) and membership of a "groups" list:
The uid is who you are (name and number) The gid is your initial login group you normally belong to The groups list is the file groups you can access via group permissions
File Permissions
Linux provides three kinds of permissions:
Read - users with read permission may read the file or list the directory Write - users with write permission may write to the file or new files to the directory Execute - users with execute permission may execute the file or lookup a specific file within a directory
File Permissions
The long version of a file listing (ls -l) will display the file permissions:
-rwxrwxr-x -rw-rw-r--rw-rw-r-drwxrwxr-x 1 1 1 7 rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij rvdheij 5224 221 1514 1024 Dec Dec Dec Dec 30 30 30 31 03:22 03:59 03:59 14:52 hello hello.c hello.s posixuft
Permissions Owner
Group
Interpreting File Permissions
-rwxrwxrwx
Other permissions Group permissions Owner permissions Directory flag (d=directory; l=link)
Additional Resources
http://www.linux.org http://www.tux.org http://www.li.org