Top Banner
Introduction to Linux Commands
36

Introduction to Linux Commands

Feb 25, 2016

Download

Documents

konala

Introduction to Linux Commands. 3 Definitions of Linux. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Linux Commands

Introduction to Linux Commands

Page 2: Introduction to Linux Commands

3 Definitions of Linux

• Linux Kernel: The very low-level software that manages your computer hardware and provides a library (POSIX) interface for user-level software. The Linux kernel runs on many platforms (Intel x86 and IA-64, Alpha, MIPS, HP PA-RISC, PowerPC, IBM S/390, SPARC, Motorola 680x0, etc.).

• GNU/Linux OS: The Linux kernel plus utility software to provide a useful working environment.

• Linux Distributions: The packaging of the Linux Kernel, the GNU/Linux OS and lots of other software to make Linux easy to install, configure, and use (at least for the target audience).

Page 3: Introduction to Linux Commands

Architecture• Kernel: Schedules programs, Manages data/file access and storage, Enforces security, Performs all hardware access.

• Init: First program run by kernel on booting.

• Shell: Presents each user a prompt, Interprets commands typed by user, Executes users commands, Provides user/programming environment.

Page 4: Introduction to Linux Commands

Architecture

Page 5: Introduction to Linux Commands

File Systemroot (/)

bin

dev etc

tmpvar

home

spool

mail

(users’ mail)

log

usr

X11R6

bin

(users’ accounts)

Page 6: Introduction to Linux Commands

Utilities• Basic Utilities

– Directory/File management: cd, ls, pwd, mkdir, rmdir, cp, mv, rm, find, du, file

– File viewing/editing: touch, more, less, ed, vi, emacs– User management: passwd, chmod, chown, su, who– Process management: kill, killall, ps– Documentation: man, info, /usr/share/doc

• Applications: X11, KDE, Gnome, OpenOffice, Apache, Sendmail, Gimp, Mozilla Firefox

• Security Software: gpg, ssh, iptables, ACID, snort, prelude, tcpdump, ethereal, nmap, nessus, tcpspy, tiger, ClamAV, spamassassin

Page 7: Introduction to Linux Commands

Network Commands

• telnet• ssh• ftp

Page 8: Introduction to Linux Commands

telnet• Connect to a host machine over the network.

• Syntax: telnet [options] {IP or Computer Name} [port number]

• Example: telnet 127.0.0.1 telnet 127.0.0.1 25 SMTP may not be running.

• Alternative: nc (from the netcat package)

• Telnet does not encrypt connections and so is NOT secure.• Use ssh for encrypted secure connections.

Page 9: Introduction to Linux Commands

ssh

• Secure Shell• ssh {IP or Computer Name} [username]

• Example• ssh mrb.bio.fsu.edu merchant

Page 10: Introduction to Linux Commands

ftp

• File Transfer Protocol

Syntax: ftp [options] {IP or Hostname}

Example: ftp 127.0.0.1

Page 11: Introduction to Linux Commands

Basic Linux Commands

• Handling Files and Directories • Text Editors• Compiling and Linking• Handling Processes• Archiving and Compressing Files• Other Useful Commands

Page 12: Introduction to Linux Commands

Handling Files and Directories

• ls : list files• cp : copy files• mv : move files• rm : remove files• mkdir : make directories• cd : change directories• rmdir : remove directories• pwd : print working directory• chmod : change permission mode

Page 13: Introduction to Linux Commands

ls• Syntax– ls [-Options] [name ...]

• Description– Lists contents of directory.

• Frequently Used Options– -a List all entries, including . and ..– -d Do not list contents of directories– -l Long listing– -F Mark directories with a '/', etc.

• Examples– ls -alF

Page 14: Introduction to Linux Commands

cp• Syntax

– cp [-Options] file1 [file2 ...] target• Description

– File1 is copied to target.• Frequently Used Options

– -f Force remove existing file– -i Ask before removing existing file – -r Copy directory trees

• Examples– cp p1.c p2.c– cp p1.c p2.c mydir

Page 15: Introduction to Linux Commands

mv

• Syntax– mv [-Options] file1 [file2 ...] target

• Description– File1 is moved to target.

• Frequently Used Options– -f Removes existing files without prompting the user– -i Asks before removing existing file

• Examples– mv p*.c mydir

Page 16: Introduction to Linux Commands

rm• Syntax– rm [-f] [-i] file . . .– rm -r [-f] [-i] dirname . . . [file . . .]

• Description– Removes files or directories.

• Frequently Used Options– -f Removal of files without prompting the user– -i Interactive removal– -r Recursive removal

• Examples– rm -f p*.o– rm -r mydir

Page 17: Introduction to Linux Commands

mkdir• Syntax

– mkdir [-m mode] [-p] dirname . . .• Description

– Creates the specified directories.• Options

– -m Specifies the mode to be used – -p Create missing intermediate directories

• Examples– mkdir -m 700 letter– mkdir abc– mkdir -p ./abc/def/ghi

Page 18: Introduction to Linux Commands

rmdir

• Syntax– rmdir [-p] [-s] dirname . . .

• Description– Removes directories.

• Options– -p Remove the directory dirname and its parent

directories which become empty.– -s Suppress the message when –p is in effect

• Examples– rmdir letter

Page 19: Introduction to Linux Commands

cd

• Syntax– cd [directory]

• Description– Change working directory. – If directory is not specified, the value of shell parameter

$HOME is used as the new working directory.• Examples– cd– cd ./abc/def/ghi– cd ..

Page 20: Introduction to Linux Commands

pwd

• Syntax– pwd

• Description– Prints the path name of the working (current)

directory.• Examples– pwd

Page 21: Introduction to Linux Commands

chmod• Syntax

– chmod [-R] mode file ...– chmod [-R] [ugoa]{+|-|=}[rwxXstl] file ...

• Description– Changes the permissions mode of a file or directory.

• Examples

chmod 400 file - Read by ownerchmod 040 file - Read by groupchmod 004 file - Read by world

chmod 200 file - Write by ownerchmod 020 file - Write by groupchmod 002 file - Write by world

chmod 100 file - execute by ownerchmod 010 file - execute by groupchmod 001 file - execute by world

• To combine these, just add the numbers together:chmod 444 file - Allow read permission to owner and group and worldchmod 777 file - Allow everyone to read, write, and execute file

Page 22: Introduction to Linux Commands

Text Editors

• pico - Simple, easy-to-use text editor• vi - Text editor based on an underlying line

editor ex• emacs - Powerful and extensible - Hard to learn

Page 23: Introduction to Linux Commands

vi

• vi Modes:– Command mode : Normal and initial mode. Other

modes return to command mode upon completion.ESC (escape) is used to cancel a partial command.

– Input mode : Entered by setting any of the following options: a A i I o O c C s S R . Arbitrary text may then be entered. Input mode is normally terminated with ESC character.

– Last line mode : Reading input for : / ? or !.Terminates by typing a carriage return

Page 24: Introduction to Linux Commands

Compiling and Linking

• cc - C compiler - Default behavior is ANSI/ISO C

• make - Allows programmer to maintain, update, and regenerate groups of computer programs.

Page 25: Introduction to Linux Commands

cc / gcc

• Syntax– cc [-Options] ... file ...

• Description– *.c are assumed to be C source programs.– *.o are compiled object files.– a.out is the default output program name.

• Frequently Used Options– -c Produce an object file– -03 Invoke optimizer

Page 26: Introduction to Linux Commands

cc / gcc

– -o outName the final output file out.– -Dname Define the name to the C macro

processor– -Idir Seek dir for include files

• Examples– cc p1.c

Page 27: Introduction to Linux Commands

Handling Processes

• ps : Prints information about active processes

• kill : Sends a signal to a process

Page 28: Introduction to Linux Commands

ps• Syntax

– ps [-Options] • Description

– Prints information about active processes. • Frequently Used Options

– -A Every process now running– -e Same as -A– -f Full listing– -l Long listing

• Examples– ps -ef

Page 29: Introduction to Linux Commands

kill• Syntax– kill [-signal] pid . . .– kill –l (the letter ‘L’ in lowercase)

• Description– Sends a signal to the specified processes. – The value of signal may be numeric or symbolic.– Signal 15 is the default signal.– kill –l lists the defined signals.

• Examples – kill 389– kill –3 401 402– kill -HUP 99999

Page 30: Introduction to Linux Commands

Archiving and Compressing

• tar• gzip

Page 31: Introduction to Linux Commands

tar• A ".tar" file is not a compressed file, it is actually a collection of

files within a single file uncompressed. If the file is a .tar.gz ("tarball") or ".tgz" file it is a collection of files that is compressed.

• Syntax– tar key [arguments] [name...]

• Description– Saves and restores multiple files on a single file. – The key argument controls tar's actions.

• Frequently Used Functions – c Create– x Extract from the tape– t List files on the tape

Page 32: Introduction to Linux Commands

tar

• Frequently Used Modifiers– v Verbose– f Next argument is the name of the archive

• Examples– Creating a tarball:

tar -cvwf file.tar myfile1.txt mypic1.jpeg– Extracting from a tarball

tar -xvwf file.tar

Page 33: Introduction to Linux Commands

Other Useful Commands

• grep: search files for a pattern• man : on-line reference manuals• wc : word, line and byte or character

count

Page 34: Introduction to Linux Commands

grep• Syntax

– grep [-E| -F] [-c| -l| -q] [-insvx] pattern_list [file . . .]

• Description– Searches the input files, selecting lines matching one or more

patterns• Frequently Used Options

– -i Case-insensitive search– -l Write file names only – -n Display line number

• Examples– grep -i unix p1.c– grep -n UNIX *.c *.h

Page 35: Introduction to Linux Commands

man• Syntax

– man [-Options] [-M path] [-T macropackage] [ -s section] name ...– man [-M path] -k keyword ...

• Description– On-line reference manuals

• Frequently Used Sections– 1 User commands and application programs– 2 System calls– 3 Library functions

• Examples– man -s 1 mkdir– man mkdir– man -k pipe

Page 36: Introduction to Linux Commands

wc• Syntax

– wc [ -c|-m ] [ -lw ] [ file . . . ]• Description

– Counts lines, words, and characters• Options

– -c Count the number of bytes– -m Count the number of characters– -l Count the number of newline characters– -w Count the number of words

• Examples– wc -l *.h *.c