生命开始情不情愿都要走完一生

2008年2月16日星期六

LINUX KONOWLEDGE COLLECTION

Everything Is a File

On a Linux system, everything is a fileeverything. Directory's a file, too a special kind of file that contains information about other files. Disk drives are really big files. Network connections are files. Even running processes are files. It's all files. To Linux, a file is just a stream of bits and bytes. Linux doesn't care what those bits and bytes form; instead, the programs running on Linux care. To Linux, a text document and a network connection are both files; it's your text editor that knows how to work with the text document, and your Internet applications that recognize the network connection.


Kernel Version Numbers
we will use kernel version in a majorversion.majorrevision.patch format.

--------------------------------------------------------------------

example, we will use kernel version 2.4.33,

--------------------------------------------------------------------

The first number (2)is the major version number. These are drastic changes to the kernel. Typically, older version stuff will not work in the newer version when this number changes. Kernel major version numbers are reserved for completely new kernel designs.
The second number (4) actually has two meanings. First, it indicates this is the fourth major revision of major version 2 of the kernel. Second, since it is an even number, it indicates that the kernel release is a stable release. If it were an odd number, it would be a developmental kernel, not suitable for production computers.
The third number (33) is the patch version number for the kernel. These changes are typically small changes, bug fixes, security fixes, and enhancements. Generally, you can use the zcat command to increment one patch at a time. For example, if your current kernel is version 2.4.33, you can use the patch-2.4.34.gz file to upgrade your kernel to version 2.4.34.

Kernel Concepts
If Linux has trouble loading a kernel module, you can use the /sbin/modprobe or /sbin/insmod commands to load modules as needed.
The Linux kernel is stored in the partition with the /boot directory. New kernels must also be transferred to this directory. By default, Red Hat Linux sets up a partition of about 100MB for the /boot directory. This provides enough room for your current kernel plus some additional upgraded kernels.
The /proc directory is based on a virtual filesystem; in other words, it does not include any files that are stored on the hard drive. But it is a window into what the kernel sees of your computer.
------------------------------------------------------------------------------------------------------------------------------
1 1403 1715 1807 1872 1982 5 8 buddyinfo diskstats fs kallsyms misc partitions swaps version
100 1646 1718 1813 1894 2 6 809 bus dma ide kcore modules pci sys vmstat
101 1697 1727 1817 1895 2042 63 825 cmdline driver interrupts kmsg mounts scsi sysrq-trigger
102 1704 1792 1823 1906 3 689 958 cpuinfo execdomains iomem loadavg mpt self sysvipc
1197 1706 1796 1825 1907 3352 745 99 crypto fb ioports locks mtrr slabinfo tty
1309 1707 1799 1834 1943 4 797 acpi devices filesystems irq meminfo net stat uptime
--------------------------------------------------------------------------------------------------------------------------------
The numbered items are based on process IDs. For example, the process ID of init is 1. The files in this directory include the memory segments that make up the active process. The contents of each of these files include the active memory for that process. The other items in the listing are files and directories that correspond to configuration information for components such as DMA channels or whole subsystems such as memory information.
More importantly, there are kernel variables you can alter to change the way the kernel behaves while it’s running.
------------------------------------------------------
echo 1 >> /proc/sys/net/ipv4/tcp_syncookies
------------------------------------------------------
Once you’ve configured a kernel once, the configuration information is stored in a hidden file, /usr/src/linux-2.4/.config.
------------------------------------------------------
CONFIG_NETDEVICES=y
CONFIG_DUMMY=m
# CONFIG_HAPPYMEAL is not set
-------------------------------------------------------
Here are the three main types of variables you’ll see in this file. The first will compile in direct support (because of the “y”), the second entry will compile in support as a module (the “m”), and the third is commented out, so this feature will be left out of the kernel we are building. You should never have to edit this file directly, as there are easier ways to configure your kernel.


Linux/Unix Filesystem Hierarchy and Structure

Everything in Linux can be reduced to a file. Partitions are associated with files such as /dev/hda1. Hardware components are associated with files such as /dev/modem. Detected devices are documented as files in the /proc directory.

./etc, /lib, /bin, /sbin, and /dev must be in the / filesystem.
LINUX COMMANDES

dmesg print or control the kernel ring buffer
RunLevel
Making each runlevel work is the province of a substantial number of scripts. Each script can start or stop fundamental Linux processes such as printing (cups), scheduling (crond), Apache (httpd), Samba (smbd), and more. The starting and stopping of the right scripts becomes part of the boot process.


这个几个runlevel 反应到/etc/inittab文件中
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
------------------------------------
init 1 go into single-user mode
runlevel 用来显示当前和上次运行runlevel
-------------------------------------

syslog

syslog 级别如下:

emerg 或 panic   该系统不可用
alert 需要立即被修改的条件
crit 阻止某些工具或子系统功能实现的错误条件
err 阻止工具或某些子系统部分功能实现的错误条件
warning 预警信息
notice 具有重要性的普通条件
info 提供信息的消息
debug 不包含函数条件或问题的其他信息
none 没有重要级,通常用于排错
* 所有级别,除了none

ChkConfig
The chkconfig command gives you a simple way to maintain different runlevels within the /etc/rc.d directory structure. With chkconfig, you can add, remove, and change services; list startup information; and check the state of a particular service.
--------------------------------------------------------------
# /sbin/chkconfig --list sendmail
sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off
--------------------------------------------------------------
If youwant to turn the Sendmail service off for runlevel 4, execute the following command:
--------------------------------------------------------------
# /sbin/chkconfig --level 4 sendmail off
--------------------------------------------------------------
With chkconfig, you can also add or delete services with the --add and --del switches. Adding a service sets up the appropriate links within the /etc/rc.d/ hierarchy. Deleting a service removes the associated links in the /etc/rc.d hierarchy.





tune2fs [options] device    
Modify tunable parameters on the ext2 or ext3 filesystem on device.
    -l device 
List the tunable parameters on device.
-c n
Set the maximum mount count to n. When the filesystem has been mounted this many times, the kernel will warn that the
filesystem has exceeded the maximum mount count when the filesystem is mounted, and e2fsck will automatically check the filesystem when
run with the -p option (as it usually run at every system boot). Setting this value to 0 tells the kernel and e2fsck to ignore the mount
count.

-i n
Set the maximum time between two filesystem checks to n. If n is a number or is followed by d, the value is in days. A value followed
by w specifies weeks. A value followed by m specifies months.The time since the last filesystem check is compared to this value by the
kernel and e2fsck -p, much like the maximum mount count. A value of 0 disables this check.

-L label
Sets the volume label of the filesystem to label. The volume label can also be set with the e2label command.

-j
Adds an ext3 journal file to the filesystem and sets the has_journal feature flag.

-m n
Sets the reserved block percentage to n. By default, ext2 filesystems reserve 5% of the total number of available blocks for root. This
means that if a filesystem is more than 95% full, only root can write to it. (It also means that df will report the filesystem as 100% full
when it is really only 95% full.)
On very large filesystems, or filesystems where only user data will be written, the reserved block percentage can be safely reduced to
make more of the filesystem available for writing by regular users.

-r n
Sets the number of reserved blocks to n. This is similar to the -m option, except it specifies a number instead of a percentage.




tree
list contents of directories in a tree - like format



uptime

uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are
currently logged on, and the system load averages for the past 1, 5, and 15 minutes.


w

w displays information about the users currently on the machine, and their processes. The header shows, in this order, the current time,
how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15

minutes.

The following entries are displayed for each user: login name, the tty name, the remote host, login time, idle time, JCPU, PCPU, and the

command line of their current process.

The JCPU time is the time used by all processes attached to the tty. It does not include past background jobs, but does include currently
running background jobs.

nl

Write each FILE to standard output, with line numbers added.



cut

-blist Print bytes in list positions.
-clist Print characters in list columns.
-ddelim Set field delimiter for -f.
-flist Print list fields.
----------------------------------------
cut -d: -f1 /etc/passwd
---------------------------------------





paste


fmt



Signaling Active Processes
用kill -l 可以看到系统全部的信号

-----------------------------------
kill -l 15
TERM
-----------------------------------

Linux 任务控制的几个技巧

Linux/Unix 区别于微软平台最大的优点就是真正的多用户,多任务。因此在任务管理上也有别具特色的管理思想。 我们知道,在 Windows 上面,我们要么让一个程序作为服务在后台一直运行,要么停止这个服务。而不能让程序在前台后台之间切换。而 Linux 提供了 fg 和 bg 命令,让你轻松调度正在运行的任务。

假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctrl-Z ,终止这个程序,然后可以看到系统提示:
[1]+ Stopped /root/bin/rsync.sh
然后我们可以把程序调度到后台执行:(bg 后面的数字为作业号)
#bg 1
[1]+ /root/bin/rsync.sh &
用 jobs 命令查看正在运行的任务:
#jobs
[1]+ Running /root/bin/rsync.sh &
如果想把它调回到前台运行,可以用
#fg 1
/root/bin/rsync.sh
这样,你在控制台上就只能等待这个任务完成了。



nice & renice


The nice command is used to alter another command's nice number at start time. For normal users, adjustment is an integer from 1 to 19. If you're the superuser, the adjustment range is from -20 to 19. If an adjustment number is not specified, the process's nice number defaults to 10. The command consists of any command that you might enter on the command line, including all options, arguments, redirections, and the background character &.

------------------------

# nice --10 vi /etc/hosts.deny

# nice -n -10 vi /etc/hosts.deny
# renice 20 501
# renice -10 -u jdean -p 501
--------------------------------------




nohup

nohup的意思是no hang up,该命令的一般形式为:

-------------------------

nohup command &

--------------------------

如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件:

--------------------------------------------------------------

nohup command > myout.file 2>&1 &

------------------------------------------------------------------

http://www.williamlong.info/archives/482.html




jobs

lilo /lilo.conf



grub.conf






head and tail

By default, the head filename command looks at the first 10 lines of a file; the tail filename command looks at the last 10 lines of a file. You can
specify the number of lines shown with the -nxy switch.


head/tail -n text1.txt text2.txt



tail -f View the Constantly Updated Last Lines of a File or Files






System-Wide Shell Configuration Files for Bourne and Bash Shells

All system-wide shell configuration files are kept in the /etc directory. These files are bashrc, profile, and the scripts in the /etc/profile.d directory. These files and scripts are supplemented by hidden files in each user’s home directory.


/etc/bashrc

The /etc/bashrc file is used for system-wide aliases and functions. Open and analyze the file on your own.The current /etc/bashrc file does set the following parameters for each user who calls the bash shell:
It sets umask, which creates the default permissions for newly created files.
It assigns a prompt, which is what you see just before the cursor at the command prompt.
The settings here are called by the .bashrc file in each user’s home directory. The settings are supplemented by the .bash_history and .bash_logout files in each user’s home directory.


/etc/profile

The /etc/profile file is used for system-wide environments and startup files. The first part of the file sets the PATH for searching for commands. Then it sets the PATH, USER, LOGNAME, MAIL, HOSTNAME, HISTSIZE, and INPUTRC variables, and finally it runs the scripts in /etc/profile.d/. You can check the current value of any of these variables with the echo $variable command.


/etc/profile.d/

Actually, /etc/profile.d is not a script, but a directory of little scripts. You may have noticed that the /etc/profile script is actually the script in charge of handling this directory.


Variables and Parameters

Variables can change. Parameters are set. The bash shell includes a number of standard environment variables. Their default values are shown in the output to the env command.

HOME as your home directory

SHELL as the default shell

LOGNAME as the username

File Permissions

In Linux, permissions are assigned the following numeric values: r=4, w=2, and x=1.


chmod
chmod [ugo][+-=][rwx]

You can use two notations with chmod: alphabetic or numeric. Both have their advantages, but it's sometimes easier for users to learn the alphabetic system first. Basically, the alphabetic method uses a simple formula: the user group you want to affect (u, g, o); followed by a plus sign (+) to grant permission, a minus sign () to remove permission, or an equal sign (=) to set exact permission; followed by the letters (r, w, x, s, t) representing the permission you want to alter.





groupadd


usermod





chown

chown owner:group 同时修改file owner和group owening

You can even use chown to change only a group by leaving off the user in front of the colon.

chown [options] user-owner files
chown [options] user-owner. files
chown [options] user-owner.group-owner files
chown [options] .group-owner files
chown [options] --reference=rfile files

-c
Like verbose mode, but report only changes.

-R
Use recursive mode, descending through directory hierarchies under files and making modifications throughout.

-v
Use verbose behavior, reporting actions for all files.

-------------------------------------------------------

chown :family libby.jpg

chown -v jdoe afile #owner of afile changed to jdoe
chown -v jdoe.sales afile #owner of afile changed to jdoe.sales

-------------------------------------------------------

chgrp

When a file is created, the user's UID (her User ID number) becomes the owner of the file, while the user's GID (her Group ID number) becomes the group for the file. You can only change permissions for a group if you are a member of that group.

chgrp -R 递归的改变所有文件/目录. If you used chgrp -R family *, you wouldn't change any of the dot files in the /home/scott/pictures/libby directory. However, chgrp -R family .* should not be used. It changes all the dot files in the current directory, but .* also matches .., so all the files in the parent directory are also changed, which is probably not what you want!

----------------------------

chgrp -Rv sales sales

----------------------------


umask

When you type the umask command, you get a four-number output such as 0245. As of this writing, the first number in the umask output is always 0 and is not used. Also, no matter what the value of umask, new files can no longer be automatically created with executable permissions.

In other words, a umask of 0454 leads to identical permissions on new files as a umask of 0545. You need to use commands such as chmod to specifically set executable permissions on a file. 我们只要记住umask是从权限中“拿走”相应的位即可。

Shadow Password Suite

Historically, all that was needed to manage Linux users and groups is the information included in the /etc/passwd and /etc/group files.The Shadow Password Suite was created to provide an additional layer of protection. It is used to encrypt user and group passwords in shadow files (/etc/shadow and /etc/gshadow) that are readable only by users with root privileges.

pwconv Converts passwords from /etc/passwd. This command works even if some of the passwords are already encrypted in /etc/shadow.
pwunconv Opposite of pwconv.
grpconv Converts passwords from /etc/group. This command works even if some of the passwords are already encrypted in /etc/gshadow.
grpunconv Opposite of grpconv.
/etc/skel
Basic configuration files for individual users are available in the /etc/skel directory. This directory includes a number of hidden files. For a full list, run the ls -a /etc/skel command. If you want all future users to get specific files in their home directories, include them here.
Daemon
Daemons are often configured to start automatically when you start Linux. This process is documented at various runlevels in the /etc/rc.d directory.
Cron
The cron system is essentially a smart alarm clock. The cron daemon, crond, checks a series of directories for jobs to run, every
minute of every hour of every day. The crond checks the /var/spool/cron directory for jobs by user. It also checks for general scheduled jobs under /etc/crontab and in the /etc/cron.d/ directory.
Linux already includes a series of scripts that are executed by cron on committed schedules in the /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly directories.
Because cron always checks for changes, you do not have to restart cron every time you make a change.
You can set different variables within the crontab file, or you can set environmental variables with the following syntax:
Variable=Value
crontab
The easiest way to set up your own cron jobs is through the crontab file, which can be managed through the crontab command. Users can edit their own crontab files with the crontab -e command; the superuser can configure the crontab for a specific user with the crontab -u username -e command. The general format for a crontab file can be found in the /etc/crontab script, which is used to run the scripts in the aforementioned schedule-related directories.
A typical crontab entry from that file is: 42 4 1 * * root run-parts /etc/cron.monthly Five schedule fields appear on the left-hand side of each crontab entry: minute, hour, day of month, month, and day of week. The preceding line is executed at 4:42 A.M., on the first of every month, no matter what day of the week it is.



You can set up users in /etc/cron.allow and /etc/cron.deny files. If these files don’t exist, cron usage is not restricted. If users are named in /etc/cron.allow file, all other users won’t be able to use cron. Any users named in /etc/cron.deny can’t use cron either.
Name Resolution
/etc/resolv.conf 记录DNS域名
/etc/host.conf
Many networks configure an /etc/hosts file for the local network and a DNS server for other networks and/or the Internet. When your computer looks for an IP address, this file determines whether it searches though /etc/hosts or DNS first. This is usually a one-line file:
order hosts, bind
The /etc/hosts.allow and /etc/hosts.deny files can help you manage what computers are allowed into your network. You can specify computers by name, IP address, network, or domain name in each file.

netstat

netstat -r, is used to display local routing tables

---------------------------------------------------
Destination Gateway Genmask Flags MSS Window irtt Iface
127.0.0.0 * 255.0.0.0 UH 40 0 0 lo
191.72.1.0 * 255.255.255.0 U 40 0 0 eth0
0.0.0.0 191.72.1.1 255.255.255.0 UG 40 0 0 eth0

------------------------------------------------------

The Destination column lists networks by their IP addresses. The Gateway column indicates gateway addresses. If the destination is on the LAN, no gateway is required, so an asterisk is shown in this column. The Genmask column lists the network mask. Networks look for a route appropriate to the destination IP address. The IP address is compared against the destination networks, in order. When the IP address is found to be part of one of these networks, it’s sent in that direction. If there is a gateway address, it’s sent to the computer with that gateway.Flag参数的值如下图



netstat -lp 显示那些只有正处在listen状态中的程序,并显示该程序的PID。

ARP

The Address Resolution Protocol associates the hardware address of a network adapter with an IP address.The arp command displays a table of hardware and IP addresses on the local computer.

/sbin/arp
Address HWtype HWaddress Flags Mask Iface
192.168.0.121 ether 52:A5:CB:54:52:A2 C eth0
192.168.0.113 ether 00:A0:C5:E2:49:02 C eth0
The address column lists known IP addresses, usually on the LAN. The HW Type column shows the hardware type of the adapter, while the HW Address column shows the hardware address of the adapter.
You can use the -H option to limit arp’s output to a specific hardware type, such as ax25, ether, or pronet. The default is ether, which is short for Ethernet.

To remove the offending machine’s arp entry from your arp table,use the -d option:

# arp -d bugsy





rm

rm -i 删除以前提示

rm -f 直接删除不提示

rm -r 递归删除

rm -d Remove directories even if they are not empty. This option is reserved for privileged users

Adding, Deleting, and Modifying User Accounts

/etc/passwd的文件格式,用冒号(:)分隔

The first number you see is the numeric ID for that user (the second number is the numeric ID for the main group associated with the user).

Now that you’ve created a new user, you need to create a home directory for that user. For example, if you’ve just created user mj, you need to create directory /home/mj. You’ll also need to make sure that mj has ownership permissions on that directory and all of the files that you’re going to put in that directory. Normally, every Linux user needs configuration files. The files in the /etc/skel directory contain default configuration files.

Alternatively, you can automate this process with the useradd command. If you wanted to add a new user named pm, you could just type useradd pm to add this user to the /etc/passwd file. By default, it creates a home directory, /home/pm, adds standard files from the /etc/skel directory, and assigns the default shell, /bin/bash. But useradd is versatile.

Adding a User Account

useradd -d 指定用户的home目录

useradd -m

useradd -f 设定一个用户expire以后,会有多少天成为永久的disabled, 0表示一旦expire 就disabled -1 就表示不起作用

Deleting a User Account
Removing user accounts is as straightforward as adding them, with a few exceptions. The simplest method is with the userdel command. By default, this command retains files in the user’s home directory.

userdel -r "username" command would remove all of these files.

修改用户信息

The usermod command modifies various settings in /etc/passwd. In addition, you can use it to set an expiration date for an account or an additional group.

# /usr/sbin/usermod -e 2003-06-08 test1 设置过期时间
# /usr/sbin/usermod -G special test1 可以设置几个组

# /usr/sbin/usermod -g groupid 可以设置组的ID

You can use the chage command to manage the expiration date of a password. This is all related to the /etc/shadow file

/etc/passwd的文件格式

Default User Configuration File

Filesystem Types
Information about your local and remotely mounted filesystems is stored in /etc/fstab. Each filesystem is described on a separate line. Each line is composed of multiple fields, each separated by spaces or tabs. When your system boots, it processes each filesystem in the order listed.
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
/dev/hda2 swap swap defaults 0 0
--------------------------------------------------
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
--------------------------------------------------
This /etc/fstab line sets the default configuration for the first floppy drive (/dev/fd0). Normally, it’s mounted on the /mnt/floppy directory. The format is auto, which means that the mount command searches through the /etc/filesystems configuration file. As long as vfat is part of this file, you do not need to specify the filesystem type. The mount command reads the filesystem on the floppy and mounts it with the correct filesystem automatically.

------------Content of /etc/filesystems--------------------
ext3
ext2
iso9660
reiserfs
vfat
xfs
ntfs
minix
hfs
efs
-----------------------------------------------------------
mount 有很多参数,可以参考 man mount命令

ifconfig

The ifconfig command is used to configure and display network devices.If you don’t specify a device, ifconfig shows all network adapters, including the loopback adapter.

以下命令用来设置


-------------------------------------------------------------
ifconfig eth0 inet 192.168.1.9 netmask 255.255.255.0
The optional parameter inet designates the address family and defaults to IPv4.
The parameter inet6 refers to IPV6.
--------------------------------------------------------------




grep
v 选项 选择不符合条件的项
grep -v ^# /etc/inetd.conf 即寻找/etc/inetd.conf中不以#开头的项
grep 5[0-9][0-9] /etc/passwd

kill
kill -l 命令看到系统中全部可用的信号名
shell脚本在执行时,会产生三个所谓的“伪信号”,(之所以称之为“伪信号”是因为这三个信号是由shell产生的,而其它的信号是由操作系统产生的),通过使用trap命令捕获这三个“伪信号”并输出相关信息对调试非常有帮助。

kill [-s sigspec | -sigspec] [pids]
kill -l [signum]
-----------------------------
kill -l 15 TERM
kill -9 1000 1001
kill -KILL 1000 1001
-----------------------------

trap
trap命令用于捕获指定的信号并执行预定义的命令。
命令格式如下
----------------------------------
trap 'command' signal
-----------------------------------
其中signal是要捕获的信号,command是捕获到指定的信号之后,所要执行的命令。可以用kill –l命令看到系统中全部可用的信号名,捕获信号后所执行的命令可以是任何一条或多条合法的shell语句,也可以是一个函数名。

tee
tee命令会从标准输入读取数据,将其内容输出到标准输出设备,同时又可将内容保存成文件。
------------------------------------------------
cmd1 | tee file_cmd1 | cmd2 | cmd3 > file1
将cmd1 输出到屏幕并且输出到 file_cmd1.
------------------------------------------------


uniq
进行排序之后,您会发现有些行是重复的。有时候该重复信息是不需要的,可以将它除去以节省磁盘空间。不必对文本行进行排序,但是您应当记住 uniq 在读取行时会对它们进行比较并将只除去两个或更多的连续行

cat happybirthday.txt

Happy Birthday to You!
Happy Birthday to You!
Happy Birthday Dear Tux!

sort happybirthday.txt | uniq
Happy Birthday Dear Tux!
Happy Birthday to You!
Happy Birthday to You!
-u 用来显示(唯一)的行
-d 用来显示多余的行

RPM
rpm -q "package name" 查询package
rpm -Uvh "package path" 安装package

Virtual Console
Virtual consoles are configured in the init configuration file, /etc/inittab. By default, Red Hat Linux is configured with six virtual consoles. Just use the appropriate ALT-function key combination. For example, pressing the ALT key and F2 at the same time brings you to the second virtual console. You can switch between adjacent virtual consoles by pressing ALT-RIGHT ARROW or ALT-LEFT ARROW. For example, to move from
virtual console 2 to virtual console 3, press ALT-RIGHT ARROW.

Disk Quota
You have two ways to set quotas for users. You can limit users by inodes or by kilobyte-sized disk blocks. Every Linux file requires an inode, so you can set limits by the number of files or by absolute space.

Kernel Configuration Options
The Code Maturity Level options allow you to incorporate experimental code in the kernel.


Network Interfaces
A network interface is a device connects as a computer to a network. The computer sends and receives packets by using the network interface.
Different network interfaces are available with linux kernel. In individual network devicesl, the interface configuration file control the network interfaces. When the system boots, it use these files and determines what interfaces to bring up and how to configuration them. These files are located in the /etc/sysconfig/network-scripts/ directory. The name of these files begin with ifcfg and are followed by device name the configuration file control.
--------------------------------------------------
-rw-r--r-- 1 root root 243 Mar 25 20:04 ifcfg-eth0
-rw-r--r-- 1 root root 166 Mar 25 20:04 ifcfg-eth1
-rw-r--r-- 1 root root 254 Jun 21 2001 ifcfg-lo
-------------------------------------------------

/etc/resolv.conf
A client submit requests for translation to one of the DNS servers configured in the /etc/resolv.conf file. At the start of configuration, A DNS domain has to be specified in the search directive where the name translations are searched. It is common to list one domain name. Yet, you can spcify up to six domains. These are stored from most specific domain to least specific domain. A subdomain will be sorted before its parent domain.


route
route add [-net | -host ] destination [ gw gateway ] [metric metric ] options

Basic Network Services Configuration
/etc/hostname 文件用来设置host 名称
In Fedora, the files and scripts that activate interfaces are found in the /etc/sysconfig/network-scripts and /etc/sysconfig/networking dirctories.
System interfaces are activated and deactivated by interface control scripts.
There are two primary interface control scripts, /sinb/ifdown and /sbin/ifup. These scripts call on control script located in the /etc/sysconfig/network-scripts/ directory.

Bash 参数和参数扩展
函数和 shell 脚本的妙处之一是,通过向单个函数或脚本传递 能够使它们表现出不同的行为.在函数或脚本中,您可以使用下表中列出的 bash 特殊变量来引用参数。您可以给这些变量附上 $ 符号的前缀,然后像引用其他 shell 变量那样引用它们。
注意:如果您拥有的参数多于 9 个,则不能使用 $10 来引用第十个参数。首先,您必须处理或保存第一个参数($1),然后使用 shift 命令删除参数 1 并将所有剩余的参数下移一位,因此 $10 就变成了 $9,依此类推。$# 的值将被更新以反映参数的剩余数量。在实践中,最常见的情况是将参数迭代到函数或 shell 脚本,或者迭代到命令替换使用 for 语句创建的列表,因此这个约束基本不成问题。



Archive



Archive Query Command






setuid & setgid & sticky

When the setuid bit is set, the code in the file will execute, using the file’s owner as the effective user ID. This means that the program can do anything that the file’s owner has permission to do. If a file is owned by root and the setuid bit is set, the code has permission to modify or delete any file in the system, no matter which user starts the program. Sounds dangerous, doesn’t it? Programs with the setuid bit have been the subject of attacks in the past.

The setgid bit does the same thing, except that the code executes with the privileges of the group to which the file belongs. Normally, a program executes with the privileges of the group of the user who started the program. When the setgid bit is set, the program runs with privileges as though the user belonged to the same group.



Package Management





man


  1. General commands. Examples are cd, chmod, lp, mkdir, and passwd.

  2. Low-level system calls provided by the kernel. Examples are intro and chmod.

  3. C library functions. Examples are beep, HTML::Parser, and Mail::Internet.

  4. Special files, such as devices found in /dev. Examples are console, lp, and mouse.

  5. File formats and conventions. Examples are apt.conf, dpkg.cfg, hosts, and passwd.

  6. Games. Examples are atlantik, bouncingcow, kmahjongg, and rubik.

  7. Miscellanea, including macro packages. Examples are ascii, samba, and utf-8.

  8. System administration commands used by root. Examples are mount and shutdown.


man -k 根据命令说明内容查找
man -f 根据命令名称找到简要说明
man -u

shutdown
shutdown -c 取消一个正在进行的shutdown
shutdown -k 并不真的shutdown ,只是向每个用户发送警告信息
sleep
sleep 3 暂停3秒

命令结合
; Run Several Commands Sequentially
&& Run Commands Only If the Previous Ones Succeed
|| Run a Command Only If the Previous One Fails
$() 把一条命令的输出输入到另一个命令中
--------------------------------------
date "+%Y-%m-%d"
2005-11-24
mkdir $(date "+%Y-%m-%d")
--------------------------------------

The Three Input/Output Streams

| redirects stdout so it is sent to be stdin for the next command.
> Redirect a Command's Output to a File
set -o noclobber You set noclobber to on, bash won't allow redirection to overwrite existing files without your explicit permission. At that point, if you want to use redirection and overwrite a file, use >| instead of just > .To permanently turn on noclobber, you need to add set -o noclobber to your .bashrc file.

set +o noclobber If you decide you don't like or need noclobber, you can turn it off again:

>> Append a Command's Output to a File. Remember that > creates a new file if it doesn't already exist and overwrites a file that already exists. If you use >> instead of >, however, your output is appended to the bottom of the named file (and yes, if the file doesn't exist, it's created)
< Use a File As Input for a Command



tar
tar -u 追加最新的文件
tar -t list tar文件的内容
tar -C --directory DIR 创建tar解压路径
tar -r 把某个文件append到一个现存的tar文件中

gzip & gunzip
接压缩一个tar.gz文件可以有以下方法
----------------------------
gzip -d tarball.tar.gz
tar xvf tarball.tar
-----------------------------
gzip -d 不是使用gzip的解压缩模式
可以可以用gunzip来代替 gzip -d
-------------------------------
gunzip tarball.tar.gz
tar xvf tarball.tar
-------------------------------

还可以用管道来简便
----------------------------
gzip -dc tarball.tar.gz | tar xv
w
-c 选项用来表示保持原有的文件
------------------------------

tar zxvf tarball.tar.gz 更直接

如果 是bzip2 格式,可以采用以下方式
-----------------------------------
bzip2 -dc tarball.tar.bz2 | tar xv
tar jxvf tarball.tar.bz2
-----------------------------------

Command History and Editing
HISTSIZE is a shell variable to control the history list. Commands from previous bash sessions are stored by default in a file called ~/.bash_history (or the file named in shell variable HISTFILE).




echo
echo *
This will NOT echo the * onto the screen. It will provide a listing of all the files in your current directory. This is because the SHELL interprets the wildcard and passes the value (all files) as an argument to vecho.
echo $USER
This will display the value assigned to the user variable
echo "$USER"
Note it also displays the value assigned to the user variable. This is because double quotes protect most special characters EXCEPT double quotes allow variable and command substitution
echo '$USER'
Note this will display $USER on the screen. This is because single quotes disable recognition of all special characters


Filename Generation




split

split [infile] [outfile]

Split infile into a specified number of line groups; the output will go into a succession of files of outfileaa, outfileab, and so on.


tr

tr [string1 [string2]]

Translate characters by mapping from string1 to the corresponding character in string2.


od

od [files]

Dump files in octal, hexadecimal, ASCII, and other formats.

-x Hexadecimal dump
-c shows ASCII characters


init 5. telinit 5

没有评论: