PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 操作系统(Windows、Linux) » linux命令及快捷键(2)
本页主题: linux命令及快捷键(2) 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

自由的龙

该用户目前不在线
级别: 中级程序员
精华: 1
发帖: 1264
威望: 1267 点
金钱: 12660 PYMB
贡献值: 0 点
在线时间:0(小时)
注册时间:2006-04-16
最后登录:2006-06-27

linux命令及快捷键(2)


cat filename | mimencode -o filename.mime
cat filename.mime |mimencode -u -o filname
(2 commands.) Encode and then decode back a file to/from the mail-oriented Internet standard for 7-bit data transfer called "mime". On older distributions, the command that does the work (mimencode) is called mmencode. Usually, you don't have to bother with these commands, your mailer should do the mime encoding/decoding in a transparent way.

ar -x my_archive.a file1 file2
(=archiver). Extract files file1 and file2 from an archive called my_archive.a. The archiver utility ar is mostly used for holding libraries.

ark &
(in X terminal). A GUI (Qt-based) archiver application. Perhaps that's everything what you need to manage your compressed files. An alternative is gnozip.
5.11 Process control
ps
(="print status" or "process status") Display the list of currently running processes with their process ID (PID) numbers. Use ps axu to see all processes currently running on your system (also those of other users or without a controlling terminal), each with the name of the owner. Use "top" to keep listing the processes currently running.

any_command &
Run any command in the background (the symbol "&" means "run the preceding command in the background"). The job_number is printed on the screen so you can bring the command in the foreground (see below) if you want. I use "&" often when starting a GUI program from an X-terminal.

jobs
List my background or stopped processes and show their job numbers.

fg job_number
Bring a background or stopped process to the foreground.

bg job_number
Place a process in the background, so it is exactly as if it had been started with &. This will restart a stopped background process. The current foreground process can often be stopped with <Ctrl>z. If you have stopped or background jobs, you have to type exit twice in row to log out.

batch
at>updatedb<Ctrl>d
Run any command (usually one that is going to take more time to complete) when the system load is low. I can logout, and the process will keep running. When the command completes, an email will be sent to me with the output. In the example above, the "at>" represents a prompt, the command to run is updatedb, and the <Ctrl><d> terminates my input to batch (I could start many commands to run, separated by <Enter>).

at 17:00
Execute a command at a specified time. You will be prompted for the command(s) to run, until you press <Ctrl>d. The associated commands are atq (display the queue of processes started with at) and atrm (remove a process from the "at queue").

kill PID
Force a process shutdown. First determine the PID of the process to kill using ps.

killall program_name
Kill program(s) by name. For example, killall pppd will disconnect your dialup network.

nohup program_name
(=no hungup). Run program_name so that it does not terminate when you log out. Output is redirected to the file nohup.out in your home directory. You surely do not want to run an interactive program under nohup.

xkill
(in X terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)

kpm
(in X terminal) KDE process manager.

lpc
(as root) Check and control the printer(s). Type "?" to see the list of available commands.

lpq
Show the content of the printer queue. Under KDE (X-Windows), you may use GUI-based "Printer Queue" available from "K"menu-Utilities.

lprm job_number
Remove a printing job "job_number" from the queue.

nice program_name
Run program_name adjusting its priority. Since the priority is not specified in this example, it will be increased by 10 (the process will run slower), from the default value (usually 0). The lower the number (of "niceness" to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use top to display the priorities of the running processes.

renice -18 PID
(as root) Change the priority of a running process to minus 18. Normal users can only adjust processes they own, and only up from the current value (make them run slower). One could also renice +10 -u peter to make user peter use fewer cpu clicks so that other user don't suffer when he runs his computing-intensive tasks.

<Ctrl>c, <Ctrl>z, <Ctrl>s, and <Ctrl>q also belong to this chapter but they were described previously. In short they mean: stop the current command, send the current command to the background, stop the data transfer, resume the data transfer.

lsof
List the opened files. If I am a root, all files will be listed. I can limit myself to files opened by processes owned by the first console if I use lsof /dev/tty1 . To list only network files (useful for a security audit), I would do lsof -i (as root).

watch -n 60 my_command
Execute my_command repeatedly at 60-second intervals (the default interval is 2 seconds).
5.12 Some administration commands
su
(=substitute user id) Assume the superuser (=root) identity (you will be prompted for the password). Type "exit" to return you to your previous login. Don't habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it. You can also use "su" to assume any other user identity, e.g. su barbara will make me "barbara" (password required unless I am the superuser).

alias ls="ls --color=tty"
Create an alias for the command "ls" to enhance its format with color. In this example, the alias is also called "ls" and the "color" option is only evoked when the output is done to a terminal (not to files). Put the alias into the file /etc/bashrc if you would like the alias to be always accessible to all users on the system. Aliases are a handy way to customize your system. Type "alias" alone to see the list of aliases for your account. Use unalias alias_name to remove an alias.

cat /var/log/httpd/access_log
Show who connected to your http (apache) server since the last time the log file was "rotated" (normally rotated once a day, when cron runs). The previous log file is access_log.1, the yet previous access_log.2, etc.

cat /var/log/secure
(as root) Inspect the important system log. It is really a good idea to do it from time to time if you use Internet access.

ftpwho
(as root) Determine who is currently connected to your ftp server.

printtool
(as root in X-terminal) Configuration tool for your printer(s). Settings go to the file /etc/printcap and (strangely) /var/spool/lpd.

setup
(as root) Configure mouse, soundcard, keyboard, X-windows, and system services. There are many distibution-specific configuration utilities, setup is the default on RedHat. Mandrake 7.0 offers very nice DrakConf .

linuxconf
(as root, either in text mode or in the X terminal). You can access and change hundreds of network setting from here. Very powerful--don't change too many things at the same time, and be careful with changing entries you don't understand. ReadHats network configuration utility netconf is a subset of linuxconf, therefore it is simpler and sometimes easier to use.

mouseconf
(as root). Simple tool to configure your mouse (after the initial installation). Mandrake includes also an alternative mousedrake.

kudzu
(as root). Automatically determines and configures your hardware. If having mysterious problems with your mouse (or other serial hardware), you may want to disable kudzu, so it does not run on the system startup (kudzu messed up my system so I could not have my mouse working). You can run it manually when you need it.

timeconfig
(as root) Set the timezone for your system. My computer hardware clock (BIOS setup) keeps time in UTC (Coordinated Universal Time, which was once called GMT or the Greenwich Mean Time). This way, I avoid any possible problems associated with switching timezones due to the daylight savings time, transfering files across the globe through the network, or a physical travel. It is customary to keep time on a server computers in UTC to avoid time ever going "backwards" (which could cause problems). Timestamps on files are always kept in UTC and displayed in the local time using the time zone information. For example, many applications (e.g., compilers, databases) depend on being able to distinguish a newer file from an older one by comparing their timestamps. It is important to keep the timezone correct. The only reason why I could select to keep BIOS time in the local time is to avoid problems when when dual booting from the same computer, and when the other operating system (MS Windows?) does not know how to handle UTC. Then, I let my Linux server know about this by checking the box "Hardware clock set to GMT", so that Linux can backcalculate the UTC which it needs.

setclock
(as root). Set your computer hardware clock from the current linux system time. Use the command "date" first to set up the linux system time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
and then write the time to the hardware clock using:
setclock

dateconfig&
(in X-terminal, as root else you will be asked for the root password). An excellent GUI utility to set my operating system and hardware clock and timezone, and tell my BIOS to keep time in UTC. I don't need the previous two commands.

xvidtune
(in X-terminal). Adjust the settings for your monitor display for all resolutions so as to eliminate black bands, shift the display right/left/up/down, etc. (First use the knobs on your monitor to fit your text mode correctly on the screen). Then use xvidtune to adjust the monitor frequencies for each resolution so it fits well in your secree. To make the changes permanent, display the frequencies on the screen and then transfer them to the setup file /etc/X11/XF86Config.   On newer monitors, you may really prefer to adjust your monitor using the built-in monitor settings--xvidtune is for older monitors which do not have the capability to remember their settings.

kvideogen
(in X-terminal). Generate "modelines" for customized resolutions of your screen. After you generated the setup text (the "modelines"), you can copy-paste it to the X-windows setup file /etc/X11/XF86Config (or /etc/X11/XF86Config-4 if you use X-server version 4.xx). See also the keyboard shortcut <Ctrl><Alt><+>

SVGATextMode 80x25x9
SVGATextMode 80x29x9
(as root) Change the text resolution in the text terminal. In the above example (second line) I changed the text screen to 80 columns x 29 lines with characters 9 pixels high. The first line defines a resolution that always works, so that if the second command did not work on my system, I can press <ArrowUP> twice and <Enter> to regain control over my screen. The possible modes depend on your video card and your monitor synchronization frequencies--I needed to edit (as root) the file /etc/TextConfig and (un)comment the proper lines to let SVGATextMode know what my system supports.

SuperProbe
(as root). A utility to determine the type of the video card and the amount of its memory.

cat /var/log/XFree86.0.log
A log file for X that can be useful to determine what is wrong with your X setup. The "0" in the filename stands for "display 0"--modify the filename accordingly if you need log for displays "1", "2", etc.

lspci
Show info on your motherboard and what cards are inserted into the pci extension slots. My older computer has ISA slots (or EISA) slots, no pci.

lsdev
Display info about your hardware (DMA, IRQ, IO ports).

lsof|more
List files opened on your system.

kernelcfg
(as root in X terminal). GUI to to add/remove kernel modules. Module is like a device driver--a piece of Linux kernel that provides support for a particular piece of hardware or functionality. You can do the same from the command line using the command insmod.

lsmod
(= list modules). List currently loaded kernel modules. A module is like a device driver--it provides operating system kernel support for a particular piece of hardware or feature.

modprobe -l |more
List all the modules available for your kernel. The available modules are determined by how your Linux kernel was compliled. Almost every possible module/feature can be compiled on linux as either "hard wired" (perhaps a bit faster, but non-removable), "module" (maybe a bit slower, but loaded/removable on demand), or "no" (no support for this feature at all). The modules which your kernel supports (with which it was compiled) are all as files under the directory /lib/modules (and the subdirectories) so browsing it may give you a clue if you are lost. If your kernel does not support a module you require, you may need to re-compile your kernel with this module enabled (this is rare because the "stock" RedHat or Mandrake Linux kernels come with almost all common and non-experimental modules pre-compiled. Still, if you have a bleeding edge hardware ... ).

modprobe sb
Load the soundblaster (sb) module. Use the previous command to find other kernel modules there are to load.

insmod parport
insmod ppa
(as root) Insert modules into the kernel (a module is roughly an equivalent of a DOS device driver). Normally, I use "modprobe" (see the previous command) to insert modules. This example shows how to insert the modules for support the external parallel-port 100-MB zip drive (it appears to be a problem to get the external zip drive to work in any other way under RH6.0 and 6.1). For the 250-MB external zip, I use the imm module instead of ppa.

rmmod module_name
(as root, not essential). Remove the module module_name from the kernel.

depmod -a
(as root) Build the module dependency table for the kernel. Not essential unless you modified /etc/modules and don't wish to reboot.

setserial /dev/cua0 port 0x03f8 irq 4
(as root) Set a serial port to a non-standard setting. The example here shows the standard setting for the first serial port (cua0 or ttyS0). The standard PC settings for the second serial port (cua1or ttyS1) are: address of i/o port 0x02f8, irq 3. The third serial port (cua2 or ttyS2): 0x03e8, irq 4. The forth serial port (cua3 or ttyS3): 0x02e8, irq 3. Add your setting to /etc/rc.d/rc.local if you want it to be set at the boot time. See man setserial for good a overview.

tunelp
(as root, rarely needed) Tune up your parallel ports.

/sbin/chkconfig --level 123456 kudzu off
(as root)A tool to check/enable/disable system services which will automatically start under different runlevels. Typically, I just use RedHat ntsysv utility if I need to enable/disable a service in the current runlevel, but chkconfig does give me an extra flexibility. An alternative tool is tksysv (X-based). The example above shows how to disable kudzu service so it does not start up at any runlevel (it messes up mouse on one of my computers). To list all the services started/stopped under all runlevels, I use:
chkconfig --list | more
To check the current status of services, I may use:
service --status-all
To start a service right now, I may use something like (starts an ftp server):
service wu-ftpd start
To re-start samba networking (e.g., after I changed its configuration), I may use:
service smb restart

symlinks -r -cds /
(as root) Check and fix the symbolic links on my system. Start from / and progress through all the subdirectories (option -r="recurse") and change absolute/messy links to relative, delete dangling links, and shorten lengthy links (options -cds). If my filesystem spreads over different hard drive partitions, I need to re-run this command for each of them (e.g., symlinks -r -cds /usr).

cd /usr/src/linux-2.4.7-10
make xconfig
(as root in X terminal). A nice GUI front-end for configuration of the kernel options in preparation for compilation of your customized kernel. (The directory name in the example contains the version of my Linux kernel so you may need to modify the directory name if your Linux kernel version is different than 2.4.7-10 used in this example. You need the "Tk" interpreter to run "make xconfig", and the kernel source code installed.) The alternatives to "make xconfig" are: "make config" (runs a scripts that asks you questions in the text mode) and "make menuconfig" (runs a text-based menu-driven configuration utility). Try: less /usr/doc/HOWTO/Kernel-HOWTO for more information.
After configurating the options for the new kernel with "make xconfig", I may proceed with compilation of the new kernel by issuing the following commands:
make clean   (this is optional; it cleans the old object files, may lengthen compilation, may prevent problems in some situations)
make dep
make bzImage
The last command will take some time to complete (maybe 10 min or 2 h, depending on your hardware). It produces the file arch/386/boot/bzImage, which is your new Linux kernel. Next:
make modules
make modules_install
Now you have the new modules installed in /lib/modules/KernelName.
Don't rename the module directory if you want to run multiple kernels--the kernel must be able to find its "matching" modules. If I want to change the kernel name, I have to edit the main kernel makefile (e.g., /usr/src/linux-2.2.14/Makefile) and change the lines right at the top. Mine (default RH7.2) are:
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 7
EXTRAVERSION = -10custom
The kernel name for the currently running kernel can be displayed using uname -r . Mine (default RH7.2) is "2.4.7-10custom". Now I can install the new kernel. The installation involves copying the new kernel (while renaming it) into the /boot directory:
cp arch/386/boot/bzImage /boot/vmlinuz-2.4.7-10custom
cp System.map /boot/System.map-2.4.7-10custom
and making changes to /etc/lilo.conf or /boot/grub/grub.conf so I can select at the boot time which kernel (the old or the new) to boot. It is strongly advised that you preserve the old kernel as a boot option (in case the new kernel refuses to boot).
If you use initrd (initial ram disk) for two-stage booting, you may also need to create an image with modules used by the kernel during startup:
mkinitrd /boot/initrd-2.4.7-10custom.img 2.4.7-custom
See this for details on kernel patching. Quick reference:
cd /usr/src/linux-2.4.7-10
patch -E -p1 < /home/download/the_patch_to_apply
It may also be helpful to read: /usr/doc/HOWTO/Kernel-HOWTO and perhaps man depmod. Configuration, compilation and installation of a new kernel is quite simple but it CAN lead to problems. Compilation of a kernel is also a good way to test your hardware, because it involves considerable amount of computing. If your hardware is "flaky", you may receive the "signal 11" error (then read the /usr/doc/FAQ/txt/GCC-SIG11-FAQ).

ldconfig
(as root) Re-create the bindings and the cache for the loader of dynamic libraries ("ld"). You may want to run ldconfig after an installation of new dynamically linked libraries on your system. (It is also re-run every time you boot the computer, so if you reboot you don't have to run it manually.)

mknod /dev/fd0 b 2 0
(=make node, as root) Manually create a device file. This example shows how to create a device file associated with your first floppy drive and could be useful if you happened to accidentally erase it. The options are: b=block mode device, c=character mode device, p=FIFO device, u=unbuffered character mode device. The two integers specify the major and the minor device number. I normally wouldn't know the parameters which mknod requires. So to make devices, I first read man MAKEDEV to figure the name of the device and then run the script /dev/MAKEDEV which knows about Linux devices by their names--see the next command. If the mentioned manual page does not help, I may refer to the ultimate documentation included with the kernel source code:
less /usr/src/linux/Documentation/devices.txt

cd /dev
./MAKEDEV audio
(as root). Restore the "audio" device that I just somehow screwed up. Also see the previous command.

5.13 Hard Drive/Floppy Disk Utilities
fdisk /dev/hda
(= "fixed disk". As root.) Linux hard drive partitioning utility (DOS has a utility with the same name). In the example above, I specified that I would like to partition the first harddrive on the first IDE interface, hence "hda". If I were you, i would backup any important data before using fdisk on any partition. I do not not know anybody who likes fdisk (either Linux or DOS edition)--I prefer easier to use cfdisk, see next command.

cfdisk /dev/hda
(as root) Hard drive partitioning utility, menu-based. Easier to use then the plain-vanilla fdisk (see the previous command). Physical drives can contain primary partitions (max 4 per disk), and logical partitions (no restriction on number). A primary partition can be bootable. Logical partitions must be contained within "extended partitions"; extended partitions are not usable by themselves, they are just a container for logical partitions. When partitioning a disk, I typically: (1) create a primary partition (2) make the primary partition bootable (3) create an extended partition, (4) create logical partition(s) within the extended partition.

sfdisk -l -x |more
(as root) List the partition tables (including extended partitions) for all drives on my system.

parted /dev/hda
A partition manipulation utility for Linux (ext2), and DOS (FAT and FAT32) hard drive partition. It is for creation, destroying, moving, copying, shrinking, and extending partitions. You should really like to backup your data and carefully read info parted before using it.

fdformat /dev/fd0H1440
mkfs -c -t ext2 /dev/fd0
(=floppy disk format, two commands, as root) Perform a low-level formatting of a floppy in the first floppy drive (/dev/fd0), high density (1440 kB). Then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c ). Making the filesystem is an equivalent to the high-level formatting. I can also format floppies to different (also non-standard) densities; try ls /dev/fd0<Tab> .I am also able to format to the default density (normally 1440k) using fdformat /dev/fd0.

badblocks /dev/fd01440 1440
(as root) Check a high-density floppy for bad blocks and display the results on the screen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy. badblocks can be also used to check the surface of a hard drive but I have to unmount the filesystem first to do a full read-write check:
mount       [to find out which device contains the disk partition I wish to check for bad blocks]
umount /dev/hda8     [unoumnt the selected partition]
badblocks -n /dev/hda8 [check the selected partition in a non-destructive read-write mode, so that my data is not erased!]
mount /dev/hda8     [mount the partition back since no info on bad blocks was printed]
If bad blocks are found, they can be marked on the hard drive so that will not be used using:
e2fsck -c /dev/hda8

fsck -t ext2 /dev/hda2
(=file system check, as root) Check and repair a filesystem, e.g., after an "unclean" shutdown due to a power failure. The above example performs the check on the partition hda2, filesystem type ext2. You definitely want to unmount the partitions or boot Linux in the "single mode" to perform this (type "linux single" at the LILO prompt or use init 1 as root to enter the single user mode). If errors are found during the filesystem checkup, I accept the defaults for repair.

tune2fs -j /dev/hda2
(as root, only for kernel that support ext3--RH7.2) Adjust the tuneable parameter of an ext2 filesystem. The example above shows how to add a journal to a disk partition (hda2 in this example), effectively converting the file system to ext3 (journaling) filesystem. To complete the transition, you must also edit the file /etc/fstab and change the filesystem type from ext2 to ext3, else you may run into problems--ext2 will not mount an uncleanly shut down journaled filesystem! To check what is the type of the filesystem use mount (with no arguments) or cat /etc/mtab. If you need more information on ext3 setup, try: http://www.symonds.net/~rajesh/howto/ext3/ext3-5.html.
Other options of tune2fs let you me add a volume label, adjust the number of mounts after which the filesystem check is performed (maximal mount count), or turn on time-based filesystem checks instead (less often used).

dd if=/dev/fd0H1440 of=floppy_image
dd if=floppy_image of=/dev/fd0H1440
(two commands, dd="data duplicator") Create an image of a floppy to the file called "floppy_image" in the current directory. Then copy floppy_image (file) to another floppy disk. Works like DOS "DISKCOPY".

mkbootdisk --device /dev/fd0 2.4.2-3
Make an emergency boot floppy. You are typically asked if you would like to make a boot disk during the system installation. The above command shows how to make it after install, on the first floppy drive (/dev/fd0). Your kernel name (needed in the command, here 2.4.2-3) can be determined either by running uname -a or ls /lib/modules .
5.14 Management of user accounts and files permissions
useradd user_name
passwd user_name
(as root) Create a new account (you must be root). E.g., useradd barbara Don't forget to set up the password for the new user in the next step. The user home directory (which is created) is /home/user_name. You may also use an equivalent command adduser user_name

ls -l /home/peter
useradd peter -u 503 -g 503
(as root). Create an account to match an existing directory (perhaps from previous installation). If the user ID and the group ID (shown for each file) were both 503, I create an account with a matching user name, the user ID (UID) and the group ID (GID). This avoids the mess with changing the ownership of user files after a system upgrade.

userdel user_name
Remove an account (you must be a root). The user's home directory and the undelivered mail must be dealt with separately (manually because you have to decide what to do with the files). There is also groupdel to delete groups.

还是贴不下,下篇再继续。
顶端 Posted: 2006-04-20 15:24 | [楼 主]
PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 操作系统(Windows、Linux)

时:11-23 21:45 Copyright © 2006 phpwhy.com 权
ICP05060669

曳息 -