Linux system-rhel5.1-server

Source: Internet
Author: User
Tags case statement gz file system log uppercase letter vars disk usage

1. installation files Rhel5.1-server-20071017.0-i386-dvd.iso

2. Directory structure

/bin: Store Common commands
/boot: Store startup program
/dev: Store device files
/etc: Store startup, shutdown, configuration programs and files
/home: User work root directory
/lib: Storing Shared link libraries
/root: Working directory for super users
/sbin: Common hypervisor for system administrators
/tmp: Storing temporary files
/lost+found: When the system is abnormal, it is used to save some data

/misc: Some useful tools
/mnt: mount points for optical drives, hard drives, etc.
/media: Automatic mount point for optical drive
/proc: Real-time information for the operating system
/sys: Hardware device information in the system
/SRV: Information that needs to be extracted after service startup
/var: main Storage System Log
/usr: Store user program
Service directory for the/TFTPBOOT:TFTP server
SELinux security procedures provided by/selinux:redhat

3. The super user's prompt is "#" and the other user's prompt is "$"

4. Add Users

? Useradd
Format: useradd [options] User name
Example:
Useradd SMB
Add a user with the name SMB

Change Password
? passwd
Format: passwd [options] [user name]
Example:
passwd SMB
To modify the password for an SMB user

Switch users
? Su
Format: su [option] [user name]
Example:
Su–root
Switch to the root user and bring the root environment variable into

Shutdown
? Shutdown
Format: Shutdown [-t seconds] [-RKHNCFF] Time
[Message]
Example:
Shutdown now
Shut down now.

Copy
? Cp
Format: CP [option] source file or directory destination file or directory
Example:
1. cp/home/test/tmp/
Copy the test file from the/home directory to the/tmp directory
2. cp–r/home/dir1/tmp/
Copy the Dir1 directory under the/home directory to the/tmp directory

Move or rename
? Mv
Format: MV [option] source file or directory destination file or directory
Example:
1. Mv/home/test/home/test1
Rename the test file under the/home directory to Test1
2.mv/home/dir1/tmp/
Move (cut) The Dir1 directory under the/home directory to the/tmp directory

Delete
? Rm
Format: RM [options] File or directory
Example:
1. Rm/home/test
Delete the test file from the/home directory
2.rm–r/home/dir
Delete the Dir directory under the/home directory

Create a Directory
? Mkdir
Format: mkdir [options] Directory name
Example:
1. Mkdir/home/workdir
Create the Workdir directory under the/home directory
2. Mkdir–p/home/dir1/dir2
Create the/home/dir1/dir2 directory, and if Dir1 does not exist, first create the Dir1

View Catalog
? Ls
Format: LS [options] [directory or file]
Example:
1. Ls/home
Displays files and directories (without hidden files) in the/home directory
2. Ls–a/home
Displays all files and directories (including hidden files) in the/home directory

3. Ls–l/home
Display details of files and directories in the/home directory
4. Ls–c/home
Displays files and directories under the/home directory, sorted by modified time

Packaging and compression
? Tar
Format: tar [options] directory or file
Example:
1.tar CVF tmp.tar/home/tmp
Package all files and directories in the/home/tmp directory into a single
Tmp.tar file
2.tar XVF Tmp.tar
Unpack the packaged files Tmp.tar in the current directory

3.tar Cvzf tmp.tar.gz/home/tmp
Package and press all files and directories under the/home/tmp directory
Shrink into a tmp.tar.gz file
4.tar Xvzf tmp.tar.gz
Unpacking compressed files tmp.tar.gz in current directory

Unzip
? Unzip
Format: Unzip [options] compressed file name. zip
Example:
1.unzip Tmp.zip
Unzip the Tmp.zip file

5.

Access rights
Every file and directory in the system has access permissions
Use it to determine who can pass the file
and directories to access files. or directory access rights are divided
Read-only, write-only, and execute three kinds. There are three different types of
User can access the file or directory: the file
Users, other users who are in the same group as the owner. The
A person is usually the creator of a file.

Each file or directory has three groups of access rights, each set with three-bit
Read, write, and execute permissions for the file owner, and the same group as the owner
Read, write, and execute permissions for the user, read, write, and execute by other users in the system
Permissions. When you use the LS-L command to display the details of a file or directory, the leftmost
A list of access rights for a file. For example:
$ ls-l sobsrc. Tgz
-rw-r--r--1 root root 483997 Ju1 L5 17:3l sobsrc. Tgz
Note there are 10 locations. The first character specifies the file type, if the
A character is a horizontal line, indicating that it is a non-directory normal file. If it is
D, which indicates that it is a directory. R stands for Read Only, W for write, X for executable,
The horizontal line represents no permission for the item.

6.

Changing access rights
? chmod
Format: chmod [who] [+ |-| =] [mode] File name
Parameters:
Who
U represents the owner of the file.
G represents the same group of users as the file owner.
O means "other users".
A means "all users". It is the system default value.
Mode
+ Add a permission
-Cancel a permission
= Give given permission
Example: chmod g+w hello.c

The permissions represented by mode can use the following letters
Any combination of (numbers):
R-Readable (4)
W Writable (2)
x executable (1)
Example: chmod 761 hello.c

View disk usage
? Df
Format: DF [option]
Example:
Df–k
Display disk usage in kilobytes

View Directory Size
? Du
Format: du [options] Directory
Example:
Du–b IPC
Displays the size of the IPC directory in bytes

Network configuration
? Ifconfig
Format: ifconfig [options] [network interface]
Example:
1. Ifconfig eth0 192.168.0.1
Configure eth0 The IP address of this NIC is 192.168.0.1
2. Ifconfig eth0 Down
Pause Eth0 The work of this NIC
3. Ifconfig eth0 up
Restore the work of eth0 this NIC

Software Installation
? Rpm
Format: RPM [Options] [installation file]
Example:
1. RPM-IVH tftp.rpm
Installing a file with the name TFTP
2. Rpm–qa
List all installed RPM packages
3. Rpm–e Name
Uninstall the RPM package named name

Mount
? Mount
Format: Mount [options] device source destination directory
Example:
1. mount/dev/cdrom/mnt
Mount the optical drive to the/MNT directory
? Umount
Format: Mount target directory
Example:
1. UMOUNT/MNT (corresponding to the Mount example)
To cancel the mount of the optical drive under/MNT

Find string
? Grep
Format: grep [Options] String
Example:
1. grep "file"./-rn
In the current directory and its subdirectories, look for files that contain a file string
2. Netstat–a | grep tftp
View ports for TFTP in all port

View process
? Ps
Format: PS [options]
Example:
1.ps aux
View all processes in the system.

Kill process
? Kill
Format: Kill [option] process number
Example:
1.kill–s SIGKILL 4096
Kill process number No. 4096.

Vi

? : Set NU Displays line number
? : Set Nonu Cancel line number

TFTP server-Installation
Installing Tftp-server using RPM packages
1. If you can see that the service is started using the following command, do not install
[[Email protected]]# netstat-a | grep tftp
Installed results: UDP 0 0 *:tftp *:*
2, if not installed, perform the following command installation.
[Email protected]]# rpm-ivh tftp-server-0.42-
3.1.I386.RPM (rhel5 installation CD \servers directory)
3. Set up the main working directory of TFTP
[Email protected] btools]# Mkdir/tftpboot

TFTP server-Configuration
4. Modify the configuration file
[Email protected] btools]# vi/etc/xinetd.d/tftp
Service TFTP
{
..............................
Socket_type = Dgram
...... ...... ......
Server =/USR/SBIN/IN.TFTPD
Server_args =-s/tftpboot
Disable = no
...... ...... ......
}

TFTP server-Boot
#/etc/init.d/xinetd start
#netstat-A | grep tftp
UDP 0 0 *:tftp *:*

NFS Installation
Installing Server for NFS
[Email protected]]# rpm-q nfs-utils
If not installed, from the Linux operating system version of the security
Locate the Nfs-utils installation package on the CD-ROM.
Cases:
[Email protected]]# rpm-ivh nfs-utils-1.0.9-
24.el5.i386.rpm

NFS Configuration
[Email protected]]# Vi/etc/exports
Join directories and access permissions that are allowed to be accessed by other computers
Cases:
/home 192.168.1.* (Rw,sync,no_root_squash)
1./home: Directories allowed to be accessed by other computers
2.192.168.1.*: The client IP address that is allowed to access the directory
3. Rw: Readable and writable
4, Sync: Synchronous Write Disk (async: Data will be staged in memory, not directly write
into the hard drive)
5. No_root_squash: Indicates that the client root user has write access to the directory

NFS Boot
1. Use the following command when starting the NFS server:
/etc/init.d/nfs start
2. Restart the NFS server with the following command:
/etc/init.d/nfs restart

NFS Use
Use the Mount command to mount a share on an NFS server
Directory.
# mount-t NFS Servername:/shared_dir/localdir
Cases:
# mount-t NFS 10.168.1.100:/home/mnt/nfs

Samba
To modify/etc/samba/smb.conf, add:
[Root]
Comment = Root directories
browseable = yes
writeable = yes
Path =/
Valid users = SMB (user name)

Samba (Add Users)
Useradd SMB//Add SMB System User
SMBPASSWD-A SMB//Change Password

Wireshark
RPM–IVH lm_sensors-2.10.0-3.1.i386.rpm
RPM–IVH net-snmp-5.3.1-9.el5.i386.rpm
RPM–IVH wireshark-0.99.6-1.el5.i386.rpm
RPM–IVH wireshark-gnome-0.99.6-1.el5.i386.rpm
(The above 4 RPM packages are in the servers directory of the RHEL5 installation disk)

Defined
What is a shell?
Simply put, it is the command parser that will
The user-entered instruction is converted to the corresponding machine
program that the device can run. Kinds

Bourne Shell (SH)
Korn Shell (Ksh)
Bourne Again Shell (bash)
C Shell (including csh and TCSH)
Tenex/tops C Shell (tcsh)

Shell Script
A shell script is a text containing a sequence of commands
This document. When you run this script file, the file
The sequence of commands contained will be executed. (Display, Shipping
Line hello.sh)

Grammar
The first line of the shell script must be in the following format:
V#!/bin/sh
The symbol #! is used to specify the parser for the script file. On top
example, use/bin/sh to parse the script. When editing a good script
, if you want to execute the script, you must also make it executable
Property.
chmod +x filename

Comments
In shell programming, a sentence that begins with #
Comment Until the end of the line. If you use the note
Even for quite a long period of time without using the foot
This script can be understood in a very short period of time.
Use and working principle.

Variable
In shell programming, all variables are made up of strings,
And there is no need to declare variables beforehand, for example: S1 (demo).
#!/bin/sh
#set variable A
A= "Hello World"
# Print A
echo "A is:"
Echo $a

Variable
Sometimes variable names are easily confused with other text. Cases:
S2 (Demo):
num=2
echo "The $numnd"
Thinking: Output? Why?

Variable
num=2
echo "The $numnd"
This does not print out "This is the 2nd" and simply prints "This is the" because the shell will go to search for the value of the variable numnd, but this variable has no value. You can use curly braces to tell the shell that we're printing num variables: num=2
echo "This is the ${num}nd"
This will print: This is the 2nd

Default variables
$#: The number of command-line arguments passed in the script
$*: All command line parameter values, between each parameter value
Leave a space
$: Command itself (shell file name)
$: First command-line argument
$: Second command-line argument

S3 (Demo):
#!/bin/sh
echo "Number of VARs:" $#
echo "Values of VARs:" $*
echo "Value of VAR1:" $
echo "Value of VAR2:" $
echo "Value of VAR3:" $
echo "Value of VAR4:" $4
Run./S2 1 2 3 4
Output result:?

Local variables
When a variable is first assigned a value, the local keyword is added to
To declare a local variable, for example: S4 (Demo):
#!/bin/bash
hello= "Var1"
Echo $hello
function Func1 {
Local Hello = "var2"
Echo $hello
}
Func1
Echo $hello
Output:?

Variable (note)
1. When assigning a variable, "=" cannot have spaces on either side
2. A semicolon is not required at the end of a statement in BASH

If statement
if [expression]
Then
#code Block
Fi

If statement
if [expression]
Then
#code Block
Else
#code Block
Fi

If statement

if [expression]
Then
#code Block
else if [expression]
Then
#code Block
Else
#code Block
Fi
Fi

If statement

if [expression]; Then
#code Block
elif [Expression]
Then
#code Block
Else
#code Block
Fi
Fi

Comparison
Comparison Action integer Action string operation
Same-eq =
Different-ne! =
Greater than-GT >
Less than-lt <
Greater than or equal to-ge
Less than or equal to-le
is empty-Z
Not empty-n

Cases:
Compare integers A and b for equality: if [$a = $b] (eq also available)
Determine if integer A is greater than integer b:if [$a-gt $b]
Compare strings A and b for equality: if [$a = $b]
Determine if string A is empty: if [-Z $a]
Determine if integer variable A is greater than b:if [$a-gt $b]
Attention:
1. Leave a space around the "[" and "]" symbols
2. "=" There are spaces around

Judge
-e file already exists
-F file is a normal file
-S file size is not zero
-d file is a directory
-R file can be read by the current user
-W file can be written to the current user
The-x file can be performed on the current user
Example: S5 (Demo):
#!/bin/sh
Folder=/home
[-R "$folder"] && echo "Can read $folder"
[-F "$folder"] | | echo "This was not file"

For loop
The For loop structure differs from the C language in bash for
The basic structure of the ring is:
for var in [list]
Do
#code Block
Done
Where $var is a cyclic control variable, [list] is the one that Var needs to traverse
Collection, the Do/done contains the loop body, which is equivalent to the C language
A pair of curly braces. In addition, if do and for are written on the same line, you must
Do before adding ";". such as: for $var in [list]; Do

Example: S6 (Demo):
#!/bin/bash
For day in Sun Mon Tue Wed Thu Fri Sat
Do
Echo $day
Done
If the list is contained in a pair of double quotes, it is considered an element, such as S8:
#!/bin/bash
For day in "Sun Mon Tue Wed Thu Fri Sat"
Do
Echo $day
Done

For loop (note)
In the example above, in the line where for,
The variable day is not added with the "$" symbol, and
In the loop body, the Echo row variable
The $day must be prefixed with the "$" symbol.

While loop
The basic structure of the while loop is:
while [condition]
Do
#code Block
Done

Until cycle
The basic structure of the Until loop is:
until [condition]
Do
#code Block
Done
The difference between while and until is that while is a true
Line, until is executed for false time

Case statement
The case structure in BASH and the switch statement in the C language
function is similar and can be used for multiple branch control.
Case ' $var ' in
Condition1)
;;
Condition2)
;;
* )
Default statments;;
Esac

Example, S7 (demo):
#!/bin/bash
echo "hit a key and then hit return."
Read Keypress
Case ' $Keypress ' in
[A-z]) echo "uppercase letter";;
[A-z]) echo "lowercase letter";;
[0-9]) echo "Digit";;
*) echo "punctuation, whitespace, or other";;
Esac

Linux system-rhel5.1-server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.