linux

33
1. What is Linux? 1.1 History of LINUX Linux was written by Linus Torvalds in 1991 and has been improved by countless number of people around the word. It was initially developed for small PC. LINUX is a open source. LINUX is a variant of UNIX. 1.2 Why LINUX? LINUX is free. Can view and edit the source code of OS. It is fully customizable. Most Important Feature is Stability. 30Years to get the bugs. Important in shared environments and critical applications. LINUX has better security structure. High Portability Easy to port new H/W Platform Written in C which is highly portable Use user name and password for login. Login is user unique name. Linux is case sensitive. Password can be changed by the user at any time. multitasking: several programs running at once multi users: several users at the same machine at once multi platforms: it runs on many different CPU

description

1. What is Linux? Bourne Again Shell(bash) 1.3.3 File System Bourne Shell (sh) (First shell by Stephen Bourne) Korn Shell (ksh) C Shell(sh) • • • • •

Transcript of linux

Page 1: linux

1. What is Linux?1.1 History of LINUX

Linux was written by Linus Torvalds in 1991 and has been improved by countless number of people around the word. It was initially developed for small PC.

LINUX is a open source.

LINUX is a variant of UNIX.

1.2 Why LINUX?

LINUX is free.

Can view and edit the source code of OS.

It is fully customizable.

Most Important Feature is Stability.

30Years to get the bugs.

Important in shared environments and critical applications.

LINUX has better security structure.

High Portability

Easy to port new H/W Platform

Written in C which is highly portable

Use user name and password for login.

Login is user unique name.

Linux is case sensitive.

Password can be changed by the user at any time.

multitasking: several programs running at once

multi users: several users at the same machine at once

multi platforms: it runs on many different CPU

Page 2: linux

1.3. Layers of LINUX

LINUX has three most important parts.

They are Kernel, Shell and File System

1.3.1 Kernel

Kernel is the heart of the operating system.

It is the low level core of the System that is the interface between applications and H/W.

Functions :

Manage Memory, I/O devices, allocates the time between user and process, inter process communication, sets process priority

1.3.2 Shell

The shell is a program that sits on the as an interface between users and kernel

It is a command interpreter and also has programming capability of its own.

Shell Types

Bourne Shell (sh) (First shell by Stephen Bourne)

C Shell(sh)

Korn Shell (ksh)

Bourne Again Shell(bash)

1.3.3 File System

Linux treats everything as a file including hardware devices. Arranged as a directory hierarchy.

The top level directory is known as “root (/)”.

2. LINUX Commands

Page 3: linux

Commands tell the operating system to perform set of operations.

The syntax form of the commands are : Command options arguments

2.1. Basic File Commands

Command: ls

Description : The command ls is used to List the contents of a directory.

This command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the directory.

Syntax: ls [options] [file-names]Options:

Options What it does

-a Displays all files (list hidden files)

-b Displays non printing characters in octal.

-c Displays files by file time stamp.

-C Displays files in a columnar format (default)

-CF list in column format and append '*' to executable files, '@' to symbolic linked files, '/' to directories

-d Displays only directories.

-f Interprets each name as a directory, not a file.

-F Lists files of Directory

-g Displays the long format listing, but exclude the owner name.

-h lists file sizes in human readable format

-i Displays the inode for each file.

-l Displays the long format listing.

-L Displays the file or directory referenced by a symbolic link.

-m Displays the names as a comma-separated list.

-n Displays the long format listing, with GID and UID numbers.

-o Displays the long format listing, but excludes group name.

-p Displays directories with /

-q Displays all non printing characters as ?

-r Displays files in reverse order.

-R list current directory and all other directories within current directory-S Lists by size

Page 4: linux

-t List more recent accessed files first -u Displays files by the file access time.

-x Displays files as rows across the screen.

-1 Displays each entry on a line.

Command: cd

Description:To switch to another directory, the command cd is used.

Syntax: cd [directory-name]Options:

Options What it does

cd dir_name Moves to directory called dir_name

cd / Moves to the root directory

cd - Moves to your previous directory

cd ~ Moves to your home directory

Cd .. Moves one level hierarchy down from the current directory

Cd ../../ Moves two level hierarchy down from the current directory

Command: mkdir

Description:The mkdir command creates a single directories or multiple directories.

Syntax: mkdir [options] directories

Options:

Options What it does

-m mode Sets the access mode for the new directory.

-p If the parent directories don't exist, this command creates them.

Command: cat

Page 5: linux

Description: The cat command reads one or more files and prints them to standard output. The operator > can be used to combine multiple files into one. The operator >> can be used to append to an existing file.

Syntax: cat [options] [files]Options:

Options What it does

-e $ is printed at the end of each line. This option must be used with -v.

-s Suppress messages pertaining to files that do not exist.

-t Each tab will display as ^I and each form feed will display as ^L. This option must be used with -v.

-u Output is printed as unbuffered.

-v Display control characters and non printing characters

Command: cp

Description: To copy a file, the command cp is used. Copies files from one location to another.

Syntax: cp [ -ip ] source_file destination_file

cp [ -ipr ] source_file_list destination_directory

cp -r [ -ip ] source_directory destination_directoryOptions:

Options What it does

-i (interactive) prompts before overwriting

-p (preserve) Copy the contents, modification times, and permission modes of the source_file to the destination files.

-r or -R ( Recursive) copy directories (recursively copying all the contents)

-f (force) if an existing destination file cannot be opened, remove it and try again

-u (update) copy only when the SOURCE file is newer than the destination file or when the destination file is missing

Command: mv

Page 6: linux

Description: The mv command allows you to move and rename files.

Syntax: mv [options] sources targetOptions:

Options What it does

-f (force) Forces the move.

-d The source file is stored in decrypted (clear-text) format on target.

-e The source file is stored in encrypted form, if the target file system is an Encrypted File System (EFS).

-E

The -E option requires one of the following arguments. If you omit the -E option, warn is the default behavior.

force

Fails the mv operation on a file if the fixed extent size or space reservation of the file cannot be preserved.

ignore

Ignores any errors in preserving extent attributes.

warn

Issues a warning if the space reservation or the fixed extent size of the file cannot be preserved.

-i (interactive) Prompt for a confirmation before overwriting any files

Command: rm

Description:To remove a file use “rm”.

Syntax: mv [options] filenameOptions:

Options What it does

-i (interactive) prompts before deleting a file

-rf recursively removes all files and subdirectories in the current directory,without prompting to delete files.

Command: rmdir

Page 7: linux

Description:The command rmdir or rm -r is used to delete a directory or directories.

Syntax: rmdir [options] directory-nameOptions:

Options What it does-i (interactive) prompts before deleting a file

-rf recursively removes all files and subdirectories in the current directory,without prompting to delete files.

-p Remove directory structure

Command: pwd Description:The pwd command displays the full pathname of the current directory.

Syntax: pwd

Command: wc

Description:The command wc is used to count lines, words or characters in a file or piped results from another command.

Syntax: wc [options] filenameOptions:

Options What it does

-c print the byte counts

-m print the character counts

-l print the newline counts

-L print the length of the longest line

-w print the word counts

2.2.Display Commands

Page 8: linux

Command: less

Description:less is a program ,used to view (but not change) the contents of a text file one screen at a time.

Syntax: less [options] [files]Options:

Options What it does

-g Highlights just the current match of any searched string.

-I Case-insensitive searches.

-M Shows more detailed prompt, including file position.

-N Shows line numbers (useful for source code viewing).

-S Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.

-c clears the screen before displaying.

+n starts printing from nth line

Command: more

Description:The more command displays the file called name in the screen. The RETURN key displays the next line of the file. The spacebar displays the next screen of the file.

Syntax: more [options] [files]Options:

Options What it does

-c Page through the file by clearing the window. (not scrolling).

-d Displays "Press space to continue, 'q' to quit"

-f Count logical lines rather than screen lines (wrapping text)

-l Ignores form feed (^L) characters

-r Display all control characters.

-s Displays multiple blank lines as one blank line

-u Does not display underline characters and backspace (^H).

-w Waits for a user to press a key before exiting.

-n Displays n lines per window.

Page 9: linux

+num Displays the file starting at line number num.

+/pattern Displays the file starting at two lines before the pattern.

Command: head

Description:Print the first few lines (default is 10) of one or more files. If files is missing or -, read from standard input. With more than one file, print a header for each file.

Syntax: head [options] [files]Options:

Options What it does

-n Displays the first n lines of the file

Command: tail

Description:The tail command displays the last ten lines of the file.

Syntax: tail [options] [files]Options:

Options What it does

-f Follow the file as it grows.

-r Displays the lines in the reverse order.

-n[k] Displays the file at the nth item from the end of the file.

+n[k] Displays the file at the nth item from the beginning of the file.

2.3.File Permission Commands

Each file in UNIX/LINUX has an associated permission level.

Page 10: linux

This allows the user to prevent others from reading/writing/executing their files or directories.

Use “ls –l filename ” to find permission level of that file.

The permission levels are

“r” means “read only” permission.

“w” means “write” permission.

“x” means “execute” permission.

In case of directory, “x” grants permission to list directory contents.

Command: chmod

Description:The chmod command changes the access mode of one file or multiple files.

Syntax: chmod [option] mode filesOptions:

Options What it does

-R Descend directory arguments recursively while setting modes.

-f Suppress error messages if command fails.

Mode:

mode

Who u=user, g=group, o=other, a=all (default)

Opcode

+ means add permission- means remove permission= means assign permission and remove the permission of unspecified fields

Permission r=Read, w=write, x=Execute, s=set uid bit, t=sticky bitu=user, g=group, o=other, l=mandatory locking

Command: chgrp

Description:The chgrp command is used to change the group that has access to files and directories.

Page 11: linux

All files in Linux belong to an owner, and a group. The owner is set by the chown command, and the group by the chgrp command.

Syntax: chgrp new group filename(s) [-options]Options:

Options What it does

-c Print information about files that are changed.

-f Do not print error messages about files that cannot be changed.

-R Traverse subdirectories recursively, applying changes.

-v Verbosely describe ownership changes.

-version Print version information and then exit.

Command: chown

Description:To change the owner of a file or directory, the command chown is used.

It is used for changing the ownership rights of a file (hence the name 'chown' - change owner). It does not change the read, write and execution permissions however.

Syntax: chown [-options] new-owner filenames

Options:

Options What it does

-c

Displays a message for each file whose ownership or group is changed

--dereference

Changes the ownership/group of the files symbolic links point to, not the symbolic links themselves. The default is --no-dereference.

-f Prevents chown from displaying error messages when it is unable to change the ownership/group of a file

-R When you include directories in the file-list this options makes all the files in that directory to be affected by the command

2.3.System Resource Commands

Command: date

Page 12: linux

Description: The date command can be use to get the current date and time on the system

Syntax: date [options] [+format] [date] format:

format What it does

% Literal %.

- (hyphen) Do not pad fields (default: pad fields with zeros).

( underscore) Pad fields with space (default: zeros).

%a Abbreviated weekday.

%b Abbreviated month name.

%c Country-specific date and time format.

%d Day of month (01-31).

%h Same as %b.

Options:

Options What it does

-d

Display date, which should be in quotes and may be in the format d days or m months d days, to print a date in the future. Specify ago to print a date in the past. You may include formatting (see the following section).

-f Like -d, but printed once for each line of .

-I [time-spec]Display in ISO-8601 format. If specified, time-spec can have one of the following values: date (for date only), hours, minutes, or seconds to get the indicated precision.

-r Display the time file was last modified.

-R Display the date in RFC 822 format.

-s Set the date.

-u Set the date to Greenwich Mean Time, not local time.

Command: chsh

Description: Change the user’s login shell. Change your login shell, either interactively or on the command line. Warn if shell does not exist in /etc/shells. Specify the full path to the shell. chsh prompts for your password. Only a privileged user can change another user's shell.

Page 13: linux

Syntax: chsh [options] [user-name] Options:

Options What it does

-l Print valid shells, as listed in /etc/shells, and then exit.

-s Specify new login shell.

-u Print help message and then exit.

Command: passwdDescription: The passwd command changes the password for the user.

Syntax: passwd [options] [user]Options:

Options What it does

-s Displays password information.

-d Delete the password for the user's account.

-f Force the operation. Overrides -u.

-i days, --inactive=days Set the number of days after a password has expired before the account is disabled.

-k Keep passwords (authentication tokens) that have not expired.

-l Lock the user's account.

-n days Set the minimum number of days that the password is valid.

-S Print the status of the user's password.

-u (unlock) Unlock the user's account

-w days, --warning=days Set the number of days of warning users will get before their password expires.

-x days, --maximum=days Set the maximum number of days that the password is valid.

Command: ps

Description: The ps command displays active processes.

Syntax: ps [options]Options:

Page 14: linux

Options What it does

-a Displays all processes on a terminal, with the exception of group leaders.

-c Displays scheduler data.

-d Displays all processes with the exception of session leaders.

-e Displays all processes.

-f Displays a full listing.

-glist Displays data for the list of group leader IDs.

-j Displays the process group ID and session ID.

-l Displays a long listing

-plist Displays data for the list of process IDs.

-slist Displays data for the list of session leader IDs.

-tlist Displays data for the list of terminals.

-ulist Displays data for the list of user-names.

Command: kill

Description: The kill command allows you to kill one process ID or multiple process Ids.

Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.

Syntax: kill [options] IDsOptions:

Options What it does

-l Lists the signal names.

-signal The signal number of name. Using the signal number of 9, means that the kill is absolute.

Examples:

kill -9 78689

It gives the guarantee that the process would be killed. It is stronger signal called SIGKILL

$ kill 0

Terminates all current process except your shell

Command: who

Page 15: linux

Description: Lists all users currently on system.

Syntax: who [options] [file] Options:

Options What it does

-a Equivalent to -b -d --login -p -r -t -T -u.

am i Print the user-name of the invoking user.

-b (boot) Print time of last system boot.

-d (dead) Print a list of dead processes.

-i (idle) Include idle times. An idle time of indicates activity within the last minute; one of old indicates no activity in more than a day.

-l (login) Print list of system login processes.

-m Same as who am i.

-p Print active processes spawned by init.

-q (count) "Quick." Display only the user-names and total number of users.

-r (run level) Print the current run level.

Command: who am i

Description: Reports the details about the command user.

Syntax: who am I

Command: who am i

Description: Reports the user name of the command user.

Syntax: whoami

2.4.Disk Space Commands

Command: du

Description: du command is used too check the amount of disk space being used by a directory and its sub directories

Syntax: du [options] [files]

Page 16: linux

Options What it does

-a Shows counts for all files and directories.

-b Displays size in bytes.

-c Prints a total for all arguments after they are processed.

-h Creates human readable output, appending letters such as M for megabytes.

-k Displays size in kilobytes.

-m Displays size in megabytes.

-s Displays a summary total for each argument.

-x Skips directories containing file systems other than the one contained in the argument

Command: df

Description: The df command is used to show the amount of disk space that is free on file systems.

Syntax: df [options] [files]

Options What it does

-a Include empty file systems (those with 0 blocks).

-h (human readable) Print sizes in a format friendly to human readers (e.g., 1.9G instead of 1967156).

-k Displays size in kilobytes.

-l Show local file systems only.

-m Print sizes in megabytes.

-x type Show only file-systems that are not of type type.

Command: free

Description: display information about free and used memory on the system.

displays the total amount of free and used physical memory and swap space in the system, as well as the buffers and cache consumed by the kernel.

Syntax: free [options] [files]

Page 17: linux

Options What it does

-b Display output in bytes.

-g Display output in gigabytes (GB).

-k Displays size in kilobytes.

-l Display detailed information about low vs. high memory usage.

-m Print sizes in megabytes.

-o Use old format. Specifically, do not display -/+ buffers/cache.

-t Display total summary for physical memory + swap space.

2.4.Basic Network Commands

Command: ping

Description: Ping is the most important troubleshooting command and it checks the connectivity with the other computers.

Syntax: ping [options] host

Example:

your system's IP address is 10.10.10.10 and your network servers' IP address is 10.10.10.1 and you can check the connectivity with the server by using the Ping command in following format.

type Ping 10.10.10.1 and press enter

If you get the reply from the server then the connectivity is ok and if you get the error message like this "Request time out" this means the there is some problem in the connectivity with the server.

Options:

Options What it does

-a Make ping audible. Beep each time response is received.

-b Ping a broadcast address.

Page 18: linux

-c count Stop after sending (and receiving) count ECHO_RESPONSE packets.

-f

Flood ping-output packets as fast as they come back or 100 times per second, whichever is greater. This can be very hard on a network and should be used with caution. Only a privileged user may use this option.

-i waitWait wait seconds between sending each packet. Default is to wait one second between each packet. This option is incompatible with the -f option.

-l name Set source address to interface name. name may also be specified as an IP address.

-s size Set send buffer (SNDBUF) size. The default is the size of one packet.

-t n Set the IP Time to Live to n seconds.

-T option

Set IP time-stamp options. Accepted option values are:

tsonly - Timestamps only.

Tsandaddr - Timestamps and addresses.

Tsprespec hosts - Timestamps with prespecified hops of one or more hosts.

-u Use older ping behavior and print full user-to-user latency instead of network round-trip time.

-w n Exit ping after n seconds.

Command: ifconfig (interface configurator)

Description: ifconfig is used to configure the network interfaces. Normally we use this command to check the IP address assigned to the system. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.

(OR)

Page 19: linux

Linux ifconfig command is used to setup a network interface card (NIC). It means we can use ifconfig command to configure ip address, netmask and gateway for the card. The ifconfig command is also used to configure or tuning the network interface card such as changing the ip address or assigning ip alias, protocol, parameter and other options. We can also use ifconfig command to view network interface card's status and to activate or deactivate the interface driver.

The ifconfig command is used to configure kernel-resident network interfaces. It is used at boot time to set up the interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is necessary.

If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all the interfaces, even those that are down. Otherwise, it configures the specified interface.

ifconfig [interface]

ifconfig [interface] [aftype] [options] | [address]...

Syntax:

View current configuration of network interfaces, including the interface names:ifconfig

Turn an adapter on (up) or off (down):ifconfig <network name> <up|down>

Assign an IP address to an adapter:ifconfig <network name> <ip address>

Assign a second IP address to an adapter:ifconfig <network name:instance number> <ip address>

Example: ifconfig eth0:0 192.168.1.101

Options:

Options What it does

Page 20: linux

interface The name of the interface. This is usually a driver name followed by a unit number (e.g. eth0 for the first Ethernet interface).

up This flag activates the interface. It is implicitly specified if an address is assigned to the interface.

downThis flag shuts down the interface driver.

[-]arp Enable or disable the use of the ARP protocol on this interface.

[-]promisc Enable or disable the promiscuous mode of the interface. If selected, all packets on the network will be received by the interface.

[-]allmulti Enable or disable all-multi cast mode. If selected, all multi-cast packets on the network will be received by the interface.

multicast Set the multicast flag on the interface. This should not normally be needed as the drivers set the flag correctly them-selves.

addressThe IP address to be assigned to the interface.

Command: netstat

Description: Linux netstat command is another useful network utility in Linux. We can use netstat to list network connections, view routing table and information about network interface. The netstat command has been one of useful tools for network troubleshooting. This tutorial is a basic guide to the netstat command with usage examples to help the new Linux beginner.

Syntax:netstat [options]

Options:

Options What it does

-S displays statistical information about the protocols.

Page 21: linux

-I displays statistical information about the network interface

-Rdisplays the routing table.

-C Enable or disable the use of the ARP protocol on this interface.displays statistical information and updates every second

-Ldisplays information about all sockets that are ready to listen

-Adisplays information about all sockets that are ready to listen and not listen.

-P displays information about sockets and PID with Process Name.

Command: route

Description: Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program.

Syntax:route [options]

Options What it does

-a Make ping audible. Beep each time response is received.

-b Ping a broadcast address.

-c count Stop after sending (and receiving) count ECHO_RESPONSE packets.

-f

Flood ping-output packets as fast as they come back or 100 times per second, whichever is greater. This can be very hard on a network and should be used with caution. Only a privileged user may use this option.

Command: ssh (Secure Shell)

Description: ssh is a program for logging into a remote machine and for executing commands on a

Page 22: linux

remote machine

Syntax: ssh [options] host-name [command]

Options:

Options What it does

-a Make ping audible. Beep each time response is received.

-b Ping a broadcast address.

-c count Stop after sending (and receiving) count ECHO_RESPONSE packets.

-f

Flood ping-output packets as fast as they come back or 100 times per second, whichever is greater. This can be very hard on a network and should be used with caution. Only a privileged user may use this option.

Command: scp (Secure copy)

Description: scp copies files between hosts on a network

Syntax: scp [options] [[user]@host1:file1] [[user]@host2:file2]

Options:

Options What it does

-a Make ping audible. Beep each time response is received.

-b Ping a broadcast address.

-c count Stop after sending (and receiving) count ECHO_RESPONSE packets.

-f

Flood ping-output packets as fast as they come back or 100 times per second, whichever is greater. This can be very hard on a network and should be used with caution. Only a privileged user may use this option.

Command: arp ( address resolution protocol )

Description:ARP is used to translate protocol addresses to hardware interface addresses.Modifying

Page 23: linux

your ARP cache can change which interfaces handle specific requests.

Syntax: arp [options]

Options:

Options What it does

-a Display entries for hosts or, if none are specified, all entries.

-dRemove the specified host's entry. To delete a proxy entry, add the pub argument and specify the interface associated with the proxy using -i.

-f Read entries from file and add them.

-H

Search for type entries when examining the ARP cache. type is usually ether (Ethernet), which is the default, but may be ax25 (AX.25 packet radio), arcnet (ARCnet), pronet (PROnet), or netrom (NET/ROM).

-i

Select an interface. If you are dumping the ARP cache, this option will cause the command to display only the entries using that interface. When setting entries, this will cause the interface to be associated with that entry. If you do not use this option when setting an entry, the kernel will guess.

-n Display host IP addresses instead of their domain names.

-s

add a permanent entry for host at hardware-address. A hardware-address for type ether hardware is 6 hexadecimal bytes, colon-separated. The pub argument can be used to set the publish flag, creating a proxy entry.

Command: telnet

Description:ARP is used to translate protocol addresses to hardware interface addresses.Modifying

Page 24: linux

your ARP cache can change which interfaces handle specific requests.

Syntax: arp [options]

Options:

Options What it does

-a Display entries for hosts or, if none are specified, all entries.

-dRemove the specified host's entry. To delete a proxy entry, add the pub argument and specify the interface associated with the proxy using -i.

-f Read entries from file and add them.

-H

Search for type entries when examining the ARP cache. type is usually ether (Ethernet), which is the default, but may be ax25 (AX.25 packet radio), arcnet (ARCnet), pronet (PROnet), or netrom (NET/ROM).

-i

Select an interface. If you are dumping the ARP cache, this option will cause the command to display only the entries using that interface. When setting entries, this will cause the interface to be associated with that entry. If you do not use this option when setting an entry, the kernel will guess.

-n Display host IP addresses instead of their domain names.

-s

add a permanent entry for host at hardware-address. A hardware-address for type ether hardware is 6 hexadecimal bytes, colon-separated. The pub argument can be used to set the publish flag, creating a proxy entry.

dmesgdigtraceroutenslookup

lnwhile

Page 25: linux

whichaliasaspellkillallrebootshutdownsleepbgfglprsu

bcechocalwhatis lsawkdigtimeman (manual )hostnamehost idjobslsattrrestore

Page 26: linux

http://www.cs.brown.edu/courses/bridge/1998/res/UnixGuide.html

http://oreilly.com/linux/command-directory/

http://www.oreillynet.com/linux/cmd/

http://www.debianhelp.co.uk/commands.htm

http://www.comptechdoc.org/os/linux/usersguide/linux_ugbasics.html

http://www.mediacollege.com/linux/command/shell-command.html

http://www.techonthenet.com/unix/index.php

http://www.fsid.cvut.cz/cz/U201/linux.html