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

2008年2月16日星期六

ECLIPSE COLLECTION

Eclipse Plugins

http://download.macromedia.com/pub/labs/jseclipse/autoinstall/
SVN Client
Maven
CheckStyle
PMD
Properties Editor
TestNG
Jetty
http://jettylauncher.sf.net/updates
FreeMarker
http://www.freemarker.org/eclipse/update
i18n
http://www.guh-software.de/eclipse/
SpringIDE
http://springide.org/updatesite/
JUnitFactory
http://www.junitfactory.com/update/
JDoc
  • For Eclipse 3.2.x: http://jdocs.com/eclipse/plugin32
  • For Eclipse 3.3: http://jdocs.com/eclipse/plugin33
Goovy
http://dist.codehaus.org/groovy/distributions/update/


JSUnit

以下两个plugin太大 可以将plugin下载下来在本地安装
eclipsexul http://sourceforge.net/projects/eclipsexul
Aptana http://www.aptana.com/studio/download


Eclispe快捷方式
  1. Ctrl + Shift + O : Organize imports
  2. Ctrl + Shift + T : Open Type
  3. Ctrl + Shift + F4 : Close all Opened Editors
  4. Ctrl + O : Open declarations
  5. Ctrl + E : Open Editor
  6. Ctrl + / : Line Comment
  7. Alt + Shift + R : Rename
  8. Alt + Shift + L : extract to Local Variable
  9. Alt + Shift + M : extract to Method
  10. Alt + Shift + V : Move
  11. F3 : Open Declaration
  12. CTRL-3: Quick Access (to basically everything; I remap this to CTRL-` because it’s eassier to type one-handed)
  13. CTRL-H: Search & Replace
  14. ALT-SHIFT-X: Run As…
    ALT-SHIFT-D: Debug As…
  15. ALT-SHIFT-Q: Open View…
  16. CTRL-TAB / SHIFT-CTRL-TAB: cycle open editors (actually, these are usually on *-F6 but I remap them)
  17. Alt + Shift + W : show the class in the package view.
  18. Alt+Left or Alt+Right for navigation
  19. Ctrl+Q for last edit
  20. Ctrl+1
  21. Ctrl+F6 — Switch between last used files
  22. Ctrl+Alt+H — Open Call Hierarchy
  23. Alt+Shift+T — Show Refactor Quick Menu



Convert an Eclipse “General” Project to a Java Project

I don’t know how many times I’ve accidentally created a General project instead of a Java project, and it always bugged me that you couldn’t convert from General to Java without starting over.

The quick and easy hack is explained well here. Open the relevant .project file and add the following (note that you don’t need the <natures> element if one is already there):
    <natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
It’s too bad you can’t “Add Java Project Nature” from within the Eclipse UI.Make sure you do this with the project closed!



LINUX COMMANDS

ssh - Log into remote servers

* Usage: ssh -p<port> <username>@<hostname>
* Example: ssh -p1234 theo@production
o Logs into the server named production on port 1234

scp - Copies files to/from remote servers

* Usage: scp -P<port> <source> <target>
* Example: scp -P1234 /home/theo/myfile.txt production@/home/jsmith
o Copies myfile.txt from /home/theo to the server named production under /home/jsmith


df

Display overall disk utilization information for mounted filesystems on file. Usually, file is a device file for a partition, such as /dev/hda1. The file may also be the mount point or any file beneath the mount point. If file is omitted, information for mounted filesystems on all devices in /etc/fstab are displayed.

df [options] [file [file...]]
-h Displays results in a human-readable format, including suffixes such as M (megabytes) and G (gigabytes).
-i Displays information on remaining inodes rather than the default disk space information.

du

Display disk utilization information for directories. If directories are omitted, the current working directory is searched.

-a Shows all files, not just directories.
-c Produces a grand total for all listed items.
-h Displays results in a human-readable format, including suffixes such as M (megabytes) and G (gigabytes).
-s Prints a summary for each of the directories specified, instead of totals for each subdirectory found recursively.
-S Excludes subdirectories from counts and totals, limiting totals to directories.

Mount
mount [command_line_options] device
mount [command_line_options] directory
mount [command_line_options] device directory
Used to mount filesystems onto the filesystem hierarchy. The first and second forms consult /etc/fstab and mount the filesystem located on device or intended to be attached to directory, respectively. In both cases, information necessary to complete the mount operation is taken from /etc/fstab. The third form is independent of /etc/fstab and mounts the filesystem on device at mount point directory.
The mount command accepts two kinds of options: command-line and mount. The command-line options provide general direction for the mount command. The mount options are used to specify additional information about the device being mounted.

-a
Mounts all of the partitions specified in /etc/fstab, except those with the noauto option.

-h
Displays help on the mount command.

-o mount_options
Specifies mount options on the command line.

-r
Mounts the filesystem as read-only.

-t fstype
Specifies that the filesystem to be mounted is of type fstype. This option is typically used interactively when no entry for the mount exists in /etc/fstab.

-v
Sets verbose mode.

-w
Mounts the filesystem read/write mode.


mount -t vfat /dev/fd0 /mnt/floppy --软盘载入 VFAT支持长文件名
mount -t iso9660 /dev/cdrom /mnt/cdrom
mount /dev/sdc


ls

ls -a to reveal hidden files

ls -l for long listings,

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

-rw-r--r-- 1 dearhwj 11311 6 Aug 4 06:22 1.txt
-rw-r--r-- 1 dearhwj 11311 1 Aug 4 06:22 2.txt
-rw-r--r-- 1 dearhwj 11311 0 Aug 7 21:52 a.out
----------------------------------------------------------------

第1栏是文件的权限标志;第2栏给出的是这个文件的链接个数;第3栏是文件所有者的用户名;第4栏是这个用户所在的用户组组名;第5栏给出文件的长度;两栏是这个文件或者子目录创建或者最后一次被修改时的日期和时间;而最后一栏很明显就是这个文件的文件名。


ls -k:即--block-size=1K。

ls -i 显示inode numbers

ls -m 也可以使用- m参数把文件用逗号分隔显示在

ls -x 也可以用- x参数按水平对齐的方式而不是缺省的垂直对齐方式列出文

ls -X 用扩展名排序

ls -R,--recursive:同时列出所有子目录层。

ls -F - F参数使得ls命令可以在显示子目录的时候通过特殊标记对内容加以区分

Character

Meaning

*

Executable

/

Directory

@

Symbolic link

|

FIFO

=

Socket


ls --color

Color

Meaning

Default shell text color

Regular file

Green

Executable

Blue

Directory

Magenta

Symbolic link

Yellow

FIFO

Magenta

Socket

Red

Archive (.tar, .zip, .deb, .rpm)

Magenta

Images (.jpg, .gif, .png, .tiff)

Magenta

Audio (.mp3, .ogg, .wav)


ls -R 它将逐层进入所有的子目录并把其中的内容全部显示出来.一个比较好的办法是把- d参数和- R参数一起使用,这样可以只列出有限的子目录层次下的文件。
ls -r 缺省的是按字幕排序,-r反转
ls -rX 按扩展名排序并反转
ls -t 按时间进行排序,
ls -tr 按时间反转排序
ls -S 根据文件大小排序
ls -Sr 根据文件大小反序排列
ls -h 方便阅读文件大小


cd
cd ~ 进入用户目录
cd 进入用户目录
cd - 进入前次目录

mkdir

mkdir -p a/b/c 循环创建目录


mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a} 使用一个命令来定义复杂的目录树

mkdir temp2 temp3 temp3 # 同时创建多个目录

mkdir -m 设置访问权限 mkdir -m 444 personal

mkdir -v 显示创建目录的详细过程


rmdir

删除文件夹(必须是空的文件夹)

rmdir -p temp5/parent/child - p参数。可以使用这个参数来删除某个子目录的全部继承结构


rm

删除文件


rm file1 file2 file3 #同时删除多个文件


export

export PATH=$PATH:/usr/sbin:/sbin

For these variables to be available, they must be exported, at which time they become environment variables. Environment variables are passed on to programs and other shells, and together they are said to form the environment in which the programs execute. PATH is always made into an environment variable. Exporting a shell variable to turn it into an environment variable is done using the export command.

When a variable is exported to the environment, it is passed into the environment of all child processes. That is, it will be available to all programs run by your shell.


set
显示所有的变量(局部的和export的)
env
只显示export的变量
export
只显示export的变量
unset
unset& 删除变量

touch

一般会在两种情况下用到它。第一种情况是建立文件,第二种情况是更新文件的修改日期

创建文件

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

touch text1.txt

用 > text2.txt 也可以创建一个0 size的文件 ,但touch还可以用来修改时间。

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

使用touch命令的- t参数加上一个代表年月日时的数字把某个文件的建立日期或者时间设置为一个具体的时间,如下所示:
# touch -t 1225130000 newfile2



touch -a "filename" 修改访问时间

touch -m "filename" 修改“修改时间”


ps

sunbox# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 20:15:23 ? 0:14 sched
root 1 0 0 20:15:24 ? 0:00 /sbin/init
root 2 0 0 20:15:24 ? 0:00 pageout
root 3 0 0 20:15:24 ? 0:00 fsflush
daemon 240 1 0 20:16:37 ? 0:00 /usr/lib/nfs/statd

第一列列出用于运行该进程的用户身份,第二列列出进程的 ID,第三列列出该进程的父进程 ID。最后一列是进程的描述,通常是所运行的二进制文件的名称。每个进程都被分配一个标识符,称为进程标识符(Process Identifier,PID)。进程还有父进程,在大多数情况下就是启动它的进程的 PID。

父 PID (PPID) 的存在意味着这是一个由别的进程创建的进程。最初创建进程的原始进程名为 init,它始终被赋予 PID 1。init 是将在内核启动时启动的第一个实际进程。启动系统的其余部分是 init 的工作。init 和其他具有 PPID 0 的进程属于内核。

-f "Forest" mode, which is used to display process family trees.

-l Long format, which includes priority, parent PID, and other information.
-u User format, which includes usernames and the start time of processes.
-w Wide output format, used to eliminate the default output line truncation. Useful for the -f option.
-x Include processes without controlling terminals. Often needed to see daemon processes and others not started from a terminal session.
-C cmd Display instances of command name cmd.
-U userDisplay processes owned by username user.


pstree
pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process
trees rooted at processes owned by that user are shown.
----------------------------------------------------
pstree | more
----------------------------------------------------

top
-b
Run in batch mode. This is useful for sending output from top to other programs or to a file. It executes the number of iterations specified with the -n option and terminate. This option is also useful if top cannot display on the terminal type you are using.
-d delay
Specify the delay in seconds between screen updates. The default is five seconds.
-i
Ignore idle processes, listing only the "interesting" ones taking system resources.
-n num
Display num iterations and then exit, instead of running indefinitely.
-q
Run with no delay. If the user is the superuser, run with highest possible priority. This option causes top to update continuously and will probably consume any idle time your CPU had. Running top -q as superuser will seriously affect system performance and is not recommended.
-s
Run in secure mode. Some of top's interactive commands can be dangerous if running as the superuser. This option disables them.
快捷方式
默认按CPU的使用率来排序,可以按C、M、T实现按CPU、内存和时间的排序。
Ctrl-L
Refresh the screen.
h
Generate a help screen.
k
Kill a process. You will be prompted for the PID of the process and the signal to send it.
n
Change the number of processes to show. You will be prompted to enter an integer number. The default is 0, which indicates that the screen should be filled.
q
Quit the program.
r
Change the priority of a process (renice). You will be prompted for the PID of the process and the value to nice it to. Entering a positive value causes a process to lose priority. If the superuser is running top, a negative value may be entered, causing a process to get a higher than normal priority. This command is not available in secure mode.

find

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

如果想查找子目录/ u s r / b i n中最近一百天没有使用过的程序,可以采用下面的命令:
# find /usr/bin -type f -atime +100 -print
- atime参数后面跟着代表日期的一个数字,用来查找在过去几天访问过的文件

如果想在子目录/ u s r / b i n中查找建立不到一天的
新文件或者二十四小时内修改过的文件,可以使用下面的参数:
# find /usr/bin -type f -mtime -1 -print
- mtime参数后面跟一个表示天数的数字(本例中是一天或者更短的时间),用来查找在过去几天修改过的文件

-lname 查找 某个文件的软链接


find /home -inum 90469 根据 inode 来查找某个inode的 hard link

find / –links 2 查找特定link数的文件

find / -group grpoupname:搜索所有组为grpoupname的文件。

find / -user用户名:搜索所有文件属主为用户名(ID或名称)的文件。

find / -size n:搜索文件大小是n个block的文件。

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

locate

Searches with the locate command are almost instantaneous. And locate searches don’t require the full filename. The drawback is that the locate
command database is normally updated only once each day, as documented in the /etc/cron.daily/slocate.cron script.


locate命令的数据库文件会在每天凌晨的五点五十分自动更新。如果想为locate命令的数据库文件立刻生成一个最新的版本,可以使用updated b命令。以根操作员的身份登录进入系统,或者使用s u命令取得根操作员的权限之后,在提示符下敲入:
# updatedb

updatedb

Refresh (or create) the slocate database in /var/lib/slocate/slocate.db.

-e directories

Exclude a comma-separated list of directories from the database. updatedb is typically executed periodically via cron

whereis
whereis命令可以迅速地找到文件,而且它还可以提供这个文件的二进制可执行文件、源代码文件和使用手册页存放的位置
------------------------------------------------------
# whereis find
find: /usr/bin/find /usr/man/man1/find.1.gz
------------------------------------------------------
可以采用下面的方法让w h e r e i s命令只查找这个程序的二进制可执行文件:
-----------------------------------------------------------
# whereis -b find
find: /usr/bin/find
---------------------------------------------------------------
whereis命令检索的子目录是固定编写在它的程序中的。虽然这看起来有点象是个缺陷,但把搜索限制在固定的子目录如/usr/man、/usr/bin或/usr/sbin中可以加快文件查找的进度。

whereis -m 只查找man page
whereis -s 只查找source

whatis
whatis命令能够从某个程序的使用手册页中抽出一行简单的介绍性文字,帮助你迅速了解这个程序的具体功能。例如,如果希望了解w h o命令有什么作用,可以输入下面的内容:
# whatis who
-------------------------------------
who ( 1 ) - show who is logged on
-------------------------------------

#whatis sync
-------------------------------------
sync (1) - flush file system buffers #结果中的(1) (2) (3p) (8) 对应到了man的section
sync (2) - commit buffer cache to disk
sync (3p) - schedule file system updates
sync (8) - synchronize data on disk with memory
--------------------------------------



apropos
apropos命令在这个数据库文件中按照给出的关键字进行搜索。如果能保证whatis数据库文件及时更新,就可以使用apropos命令来帮助找到需要的程序.


which
The which command tells you which version of a command will run if you just type its name.The which command is also a speedy way to tell if a command is on your system.If the command is on your system and in your PATH, you'll be told where to find it; if the command doesn't exist, you're back on the command line with nothing.

which -a 找到所有的路径

cat
可以使用cat命令和重定向操作符(“>”)来合并文件。例如,如果想把文件test.txt和文件test2.txt合并到另外一个叫做test3.txt的文件中去,可以使用下面的方法:
----------------------------------------
cat test1.txt test2.txt > test3.txt
----------------------------------------

使用cat命令和重定向符“ > >”可以用来追加
------------------------------------------
cat test1.txt >> test2.txt
------------------------------------------

cat命令可以读取标准输入,所以可以使用c a t命令建立一个文件并通过键盘直接向这个文件中输入内容按下C t r l + D组合键关闭这个文件.
----------------------------------
# cat > myfile.txt
----------------------------------

cat -n myfile.txt 输出行号




less and more

With the more filename command, you can scroll through the text of a file, from start to finish, one screen at a time. With the less filename command, you can scroll in both directions through the same text with the PAGE UP and PAGE DOWN keys. Both commands support vi-style searches.

如果想向下翻一页,按空格键。如果想向上翻一页,按B键。
如果使用了惊叹号( ! ),还可以从more/less 命令中去执行其他的命令
-------------------------------------------------------
more test1.txt
........................
! wc programs.txt
............................
---------------------------------------------------------
还 可以使用less搜索命令在一个文本文件中进行快速查找。先按下斜杠键( / ),再输入一个单词或者词组的一部分。l e s s命令会在文本文件中进行快速查找,并把找到的第一个搜索目标高亮度显示。如果希望继续查找,请按下斜杠键( / ),再按下回车键。如果想退出阅读,请按下Q键,就返回到shell命令行。


To view information about the file while you're in less, press =



less -N text1.txt 显示行号



键入v 可以在 less和 vim 之间切换

cp

cp -r tempdir1 tempdir2 - r参数。可以使用这个参数把一个子目录拷贝到另外一个子目录中去 用-R也可以

cp -a //same as -dpR 可以使用这个参数把一个子目录拷贝到另外一个子目录中去 用-R也可以

cp -p tempdir2/tempdir1/tempfile1 tempdir3 -p 把文件连同它的子目录结构一起拷贝过去

cp "sourcefilepath" . 拷贝到当前路径
cp -d same as --no-dereference --preserve=link
--no-dereference never follow symbolic links 只拷贝链接,不拷贝链接指向的内容
When a symbolic link is encountered with cp, the contents of the file to which the link points are copied unless the -d option is specified. This "no dereference" operator causes cp to copy the links themselves instead. For example, consider a directory dir1 containing a symbolic link, which is recursively copied to other directories with and without the -d option:
-----------------------------------------------------
# ls -l dir1
total 13
lrwxrwxrwx 1 root root 19 Jan 4 02:43 file1 -> /file1
-rw-r--r-- 1 root root 10240 Dec 12 17:12 file2
# cp -r dir1 dir2
# ls -l dir2
total 3117
-rw-r--r-- 1 root root 3164160 Jan 4 02:43 file1
-rw-r--r-- 1 root root 10240 Jan 4 02:43 file2
# cp -rd dir1 dir3
# ls -l dir3
total 13
lrwxrwxrwx 1 root root 19 Jan 4 02:43 file1 -> /file1
-rw-r--r-- 1 root root 10240 Jan 4 02:43 file2
-----------------------------------------------------







mv

While you can’t rename a file in Linux, you can move it. The mv command essentially puts a different label on a file. Unless you’re moving the file to a different partition, everything about the file, including the inode number, remains the same.

If a target file or directory does not exist, source is renamed to target. If a target file already exists, it is overwritten with source. If target is an existing directory, source is moved into that directory. If source is one or more files and target is a directory, the files are moved into the directory.


ln

Hard links include a copy of the file. As long as the hard link is made within the same partition, the inode numbers are identical. You could delete a hard-linked file in one directory, and it would still exist in the other directory. On the other hand, a soft link serves as a redirect; when you open up a file created with a soft link, you’re directed to the original file. If you delete the original file, the file is lost. While the soft link is still there, it has nowhere to go.

Symbolic links

A symbolic link is simply a pointer to another filename. When Linux opens a symbolic link, it reads the pointer and then finds the intended file that contains the actual data. Symbolic links can point to other filesystems, both local and remote, and they can point to directories. They are clearly listed as being a link with the ls -l command by displaying a special "l" (a lowercase L) in column one, and they have no file protections of their own (the actual file's permissions are used instead). A symbolic link can point to a filename that does not actually exist. Such a symbolic link is said to be broken or stale.

Hard links

A hard link is not really a link at all. It is simply another directory entry for an existing file. The two directory entries have different names but point to the same inode and thus to the same actual data, ownership, permissions, and so on. In fact, when you delete a file, you are only removing a directory entry (in other words, one hard link to the file). As long as any directory entries remain, the file's inode is not actually deleted. In fact, a file is not deleted until its link count drops to zero (and the file is no longer open for reading or writing).

Hard links have two important limitations. First, because all of the links to a file point to the same inode, any hard links must by definition reside on the same filesystem. Second, hard links cannot point to directories. However, hard links take no disk space beyond an additional directory entry.

ln [options] file link
ln [options] files directory

-f

Overwrite (force) existing links, or existing files in the destination directory.

-i

Prompt interactively before overwriting destination files.

-s

Create a symbolic link rather than a hard link.

Sort

By default, the sort command sorts the contents in alphabetical order depending on the first letter in each line.



tac


wc
The wc command, short for word count, can return the number of lines, words, and characters in a file. The wc options are straightforward; for example, wc -w filename returns the number of words in that file.



BASH快捷方式

  • CTRL+A 移动到当前行的起始处。
  • CTRL+E 移动到当前行的末尾。
  • CTRL+K 删除当前行中光标所在位置后的所有字符。
  • CTRL+P(表示上一条),或向上箭头键,移动到历史缓冲区中的上一条命令。 同!!
  • CTRL+N(表示下一条),或向下箭头键,移动到历史缓冲区中的下一条命令。
  • CTRL+R(表示反向搜索)对以前的命令进行搜索。

您还可以使用 history 命令来显示以前的命令,每条命令都带有它在历史记录缓冲区中的编号。然后,您可以使用该编号,以感叹号 (!) 作为开始,执行缓冲区中一条特定的命令,比如 !382。通过使用感叹号加上一个负数,您还可以对历史记录缓冲区进行相对索引。例如,!-2 执行历史记录缓冲区中的倒数第二条命令。因为历史记录缓冲区可以跨越登录会话,所以它为前面的命令的重放提供了一种功能强大的技术。通过输入 set -o option-name ,您可以很容易地设置这些选项;而通过输入 set +o option-name ,您可以很容易地撤销这些选项。例如,set -o emacs 打开了 Emacs 键绑定选项。


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