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

自由的龙

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

linux命令及快捷键(3)


groupadd group_name
(as root) Create a new group on your system. Non-essential on a home machine, but can be very handy even on a home machine with a small number of users.
For example, I could create a group "friends", using
groupadd friends
then edit the file /etc/group, and add my login name and the names of my friends to the line that lists the group, so that the final line might look like this:
friends:x:502:stan,pete,marie
Then, I can change the permissions on a selected file so that the file belongs to me AND the group "friends".
chgrp friends my_file
Thus, the listed members of this group have special access to these files that the rest of the world might not have, for example read and write permission:
chmod g=rw,o= my_file
The alternative would be go give write permission to everybody, which is definitely unsafe even on a home computer. groups
List the groups to which the current user belongs. Or I could use groups john to find to which groups the user john belongs.

usermod
groupmod
(as root) Two command-line utilities to modify user accounts and groups without manual editing of the files /etc/passwd /etc/shadow /etc/group and /etc/gshadow. Normally non-essential.

userconf
(as root) Menu-driven user configuration tools (password policy, group modification, adding users, etc). Part of linuxconf package, but can be run separately.

passwd
Change the password on your current account. If you are root, you can change the password for any user using: passwd user_name

chfn
(="change full name"). Change the information about you (full name, office number, phone number, etc). This information is displayed when the finger command is run on your login_name.

chage -M 100 login_name
(= "change age"). Set the password expiry to 100 days for the user named login_name .

quota username
setquota username
quotaon /dev/hda
quotaoff /dev/hda
A set of commands to manage user disk quotas. Normally not used on a home computer. "Disk quota" means per-user limits on the usage of disk space. The commands (respectively) display the user quota, set the user quota, turn the quota system on the for a given filesystem (/dev/hda in the above example), turn the quota system off. "Typical" Linux distros I have seen set on default: no limits for all users, and the quota system is off on all filesystems.

kuser
(as root, in X terminal) Manage users and groups using a GUI. Nice and probably covering most of what you may normally need to manage user accounts.

chmod perm filename
(=change mode) Change the file access permission for the files you own (unless you are root in which case you can change any file). You can make a file accessible in three modes: read (r), write (w), execute (x) to three classes of users: owner (u), members of the group which owns the file (g), others on the system (o). Check the current access permissions using:
ls -l filename
If the file is accessible to all users in all modes it will show:
rwxrwxrwx
The first triplet shows the file permission for the owner of the file, the second for the group that owns the file, and the third for others ("the rest of the world"). A "no" permission is shown as "-".
When setting permissions, these symbols are used: "u"(=user or owner of the file), "g"(=group that owns the file), "o"(=others), "a" (=all, i.e., owner, group and others), "="(=set the permission to), "+"(=add the permission), "-"(=take away the permission), "r"(=permission to read the file), "w"=(write permission, meanning the permission to modify the file), "x"(=permission to execute the file).
For example, this command will add the permission to read the file junk to all (=user+group+others):
chmod a+r junk
This command will remove the permission to execute the file junk from others:
chmod o-x junk Also try here for more info.
You can set the default file permissions for the new files that you create using the command umask (see man umask).

chown new_ownername filename
chgrp new_groupname filename
Change the file owner and group. You should use these two commands after you copy a file for use by somebody else. Only the owner of a file can delete it.

lsattr files
List attributes for the file(s). Not very often used because the most interesting attributes are still not implemented. The attributes can be changed using the chattr command. The attributes are: A (=don't update atime when the file is modified), S (=synchronous updates), a (=append only possible to this file), c (=file compressed on the kernel level, not implemented yet), i (=immutable file), d (=no dump), s (=secure deletion), and u (undeletable, not implemented yet). An interesting usage may be to make a file undeletable even by root (until s/he clears the attribute).

sudo /sbin/shutdown -h now
(as a regular user, I will be prompted for my user password) Run the command "shutdown" (or another command which you have been given permission to run by your system administrator). With sudo, the administrator can give selected users the rights to run selected commands, without handing out the root password. The file /etc/sudoers must be configured to contain something like:
my_login_name   my_host_computer_name = /sbin/shutdown

pwck
grpck
(as root, two commands). Verify the integrity of the password and group files.

pwconv
grpconv
(as root) Unlikely you need these commands. They convert old-style password and group files to create the more-secure "shadow" files.

5.15 Program installation
rpm -ivh package_name-version.platform.rpm
(as root) Install a package (option "i", must be the first letter after the dash), while talking to me a lot (option "v'=verbose) and printing "hashes" to show installation progress (option "h"). rpm stands for "Redhat Package Manager".

rpm -Uvh package_name-version.platform.rpm
(as root) Upgrade (option "U", must be the first letter after the dash) a package, while being verbose (option "v") and displaying hashes ("h").

rpm -ivh --force --nodep package_name-version.platform.rpm
(as root) Install the package ignoring any possible conflicts and package dependency problems.

rpm -e package_name
(as root) Uninstall (option "e"=erase) the package package_name. Please note the absence of "-version.platform.rpm" at the end of the package name (the package name is the same as the name of the *.rpm file from which the package was installed but without the dash, version, platform and "rpm").

rpm -qpi package_name-version.platform.rpm
Query (option "q", must be the first letter after the dash) the yet uninstalled package (option "p") so that it displays the info (option "i") which the package contains.

rpm -qpl package_name-version.platform.rpm
Query (option "q", must be the first letter after the dash) the yet uninstalled package (option "p") so that it displays the listing (option "l") of all the files the package contains.

rpm -qf a_file
Find the name of the installed package to which the file "a_file" belongs or belonged. Useful if I accidentally erased a file and now I need to find the right package and re-install it.

rpm -qi package_name
Query the already installed package so that it displays the info about itself. Please note the absence of "-version.platform.rpm" at the end of the package name.

rpm -qai | more
Query all the packages installed on my system so that they display their info. On my simple system, I have ~600 packages installed so obviously, I must have a lot of time to read all their info. To count your packages, try:
rpm -qa | grep -c ''
To find a particular package, try:
rpm -qa | grep -i the_string_to_find
(The option -i makes grep ignore the case of the characters, so upper or lower case letters will match.)

rpm -Va
Verify (the option "V") all the packages (option "a") installed on my system. This lists files that were modified since the installation. Here is the legend for the output:
.     Test passed
c     This is a configuration file
5     MD5 checksum failed
S     File size is different
L     Symbolic link has changed
T     File modification time changed
D     Device file is modified
U     User that owns the file has changed
G     Group that owns the file has changed
M     File mode (permissions and/or file type) has been modified

kpackage
gnorpm
glint
(in X terminal, as root if you want to be able to install packages, 3 commands) GUI fronts to the Red Hat Package Manager (rpm). "glint" comes with RH5.2 and seems obsolete 白痴白痴白痴白痴白痴 gnorpm is the "official" RedHat GUI package installer, older versions are very slow and confusing but the newer version (the one that comes with RH7.0) is vastly improved. kpackage is the "official" KDE program and has been pretty good all along. Use any of them to view which software packages are installed on your system and the what not-yet-installed packages are available on your RedHat CD, display the info about the packages, and install them if you want (installation must be done as root).

5.16 Accessing drives/partitions
mount
See here for details on mounting drives. Examples are shown in the next commands.

mount -t auto /dev/fd0 /mnt/floppy
(as root) Mount the floppy. The directory /mnt/floppy must exist, be empty and NOT be your current directory.

mount -t auto /dev/cdrom /mnt/cdrom
(as root) Mount the CD. You may need to create/modify the /dev/cdrom file depending where your CDROM is. The directory /mnt/cdrom must exist, be empty and NOT be your current directory.

mount /mnt/floppy
(as user or root) Mount a floppy as user. The file /etc/fstab must be set up to do this. The directory /mnt/floppy must not be your current directory.

mount /mnt/cdrom
(as user or root) Mount a CD as user. The file /etc/fstab must be set up to do this. The directory /mnt/cdrom must not be your current directory.

umount /mnt/floppy
Unmount the floppy. The directory /mnt/floppy must not be your (or anybody else's) current working directory. Depending on your setup, you might not be able to unmount a drive that was mount by somebody else.

5.17 Network administration tools
netconf
(as root) A very good menu-driven setup for your network.

ping machine_name
Check if you can contact another machine (give the machine's name or IP), press <Ctrl>C when done (without <Ctrl>c, the command keeps going). As all Linux commands, ping has options, including the "ping of death" attack, when it seems you can ping some servers so they die--try the the opitons -f and -s.

route -n
Show the kernel routing table.

host host_to_find
nslookup host_to_find
dig ip_to_find
(Three commands, use any.) Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find. This way you can check if your DNS works. You can also find out the name of the host of which you only know the IP number.

traceroute host_to_trace
Have a look how your messages trace to host_to_trace (which is either a host name or IP number).

mtr host_to_trace
(as root) A powerful and nice tool that combines the functionality of the older ping and traceroute (RH7.0)

nmblookup -A ip_address
Status of a networked MS Windows machine (with an NetBIOS name). This command is an equivalent of Windows nbtstat command.

ipfwadm -F -p m
(for RH5.2, see the next command for RH6.0) Set up the firewall IP forwarding policy to masquerading. (Not very secure but simple.) Purpose: all computers from your home network will appear to the outside world as one very busy machine and, for example, you will be allowed to browse the Internet from all computers at once.

echo 1 > /proc/sys/net/ipv4/ip_forward
ipfwadm-wrapper -F -p deny
ipfwadm-wrapper -F -a m -S xxx.xxx.xxx.0/24 -D 0.0.0.0/0
(three commands, RH6.0). Does the same as the previous command. Substitute the "x"s with digits of your class "C" IP address that you assigned to your home network. See here for more details.

ipchains -P forward DENY
ipchains -A forward -s xxx.xxx.xxx.0/24 -d 0.0.0.0/0 -j MASQ
(two commands, RH7.0). Same as previous commands, but works under RH7.0.

ipchains -L
List all firewall rules. Use to check if your firewalling setup works.

iptables -L
Linux kernel 2.4.x uses new firewalling "iptables". The above example lists the firewall rules.

firewall-config
(as root, in Xterm). A GUI for building your custom firewall.

ifconfig
(as root) Display info on the network interfaces currently active (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1, etc, first ppp over modem as ppp0, second as ppp1, etc. The "lo" is the "loopback only" interface which should be always active. Use the options (see ifconfig --help) to configure the interfaces.

ifup interface_name
(/sbin/ifup to run as a user) Startup a network interface. E.g.:
ifup eth0
ifup ppp0
ifup ppp1
Users can start up or shutdown the ppp interface only when the permission is given in the ppp setup (using netconf ). To start a ppp interface (dial-up connection), I normally use kppp available under the KDE "K" menu (or by typing kppp in an X-terminal).

/etc/rc.d/init.d/network restart
Restart the network using its normal initialization script (the same which is used during bootup). Useful if you just have manually made changes to your network configuration. Any other service listed in init.d can be stopped, started, or restarted in a similar way (call the script with an options stop, start or restart).

ifdown interface_name
(/sbin/ifdown to run it as a user). Shut down the network interface. E.g.: ifdown ppp0 Also, see the previous command.

netstat | more
Displays a lot (too much?) information on the status of your network.

/usr/sbin/mtr --gtk
(as root, in X windows if you wish the nice gtk-based interface). Network diagnostic tool combining the capabilities of traceroute and ping.   Comes with RH7.0.

nmap ip_number
Map the ports on the machine with ip_number. REALLY useful to establish the security of your network configuration as you can see the opened ports. nmap is included on the RH7.0 "Linux PowerTools" CD, as is a convenient GUI front end, "nmapfe". nmap can also do operating system "fingerprinting". Normally, people (and their ISPs) don't like their computer ports being scanned (they view it as possbily probing before an attack) so they may complain if they find out--learn how to use nmap on your own computers else you will soon hear from your ISP (the complaints will go to them). How do I know this?

ethereal
(as root, in Xterminal) Network analyzer--view the network trafic going through your computer. Included on the RH7.0 "Linux PowerTools" CD. Using ethereal may be unethical in some situations, and unauthorized use in the workplace could be a fireable offence.

tcpdump -i ppp0 -a -x
(as root) Print all the network traffic going through the first over-the-phone interface (ppp0) as ascii and hexadecimal. Probably too much printout. tcpdump is a rather raw tool and it can be useful for building more "customized" tools for listening to/log what you need.
5.18 Music-related commands
cdplay play 1
Play the first track from a audio CD. Use cdplay to play the whole CD. Use cdplay stop when had enough.

eject
Get a free coffee cup holder )).   (Eject the CD ROM tray). This command defaults to the cdrom, but could be used to eject other removable media by specifying the mount point or device. E.g., I can eject the zipdisk from a parallel-port (external) zipdrive (as root) using: eject /dev/sda4

play my_file.wav
Play a wave file.

rec my_file.wav
Record a wave file from my microphone.

mpg123 my_file.mp3
Play an mp3 file.

mpg123 -w my_file.wav my_file.mp3
Create a wave audio file from an mp3 audio file. Useful if you wanted to write a regular audio CD from mp3s--you have to convert the mp3s to the *.wav format first. Don't be surprised the conversion is slow--decompressing mp3s is very processor intensive.

xmms
(in X terminal) Nice GUI mp3 player.

freeamp
(in X terminal) Another GUI mp3 player.

lame input_file output_file
MP3 encoder.

knapster
(in X terminal) Start the program to downoload mp3 files that other users of napster have displayed for downloading. You may share your mp3s too. Really cool, while it lasts. Gnutella and FreeNet will soon replace them->it gets even cooler.

cdparanoia -B "1-"
(CD ripper) Read the contents of an audio CD and save it into wavefiles in the current directories, one track per wavefile. The "1-" means "from track 1 to the last". -B forces putting each track into a separate file.

playmidi my_file.mid
Play a midi file. playmidi -r my_file.mid will display text mode effects on the screen.

sox audio_file another_format_audio_file
(="SOund eXchange") Convert from almost any audio file format to another (but not mp3s). See man sox for the list of supported audio file formats (many). sox also lets you add special effects to your sound file.

kscd
(in X terminal) CD player.

kmidi
(in X terminal) MIDI player.

kmid
(in X terminal) MIDI/caraoke player.

kmix
(in X terminal) Sound mixer.

studio
(in Xterminal) Sound Studio--edit sound files, add effects, etc. Available on the on the PowerTools CD, RH7.x.

extace
(in Xterminal) Sound visualization utility.

festival --tts my_file.txt
Say the content of the my_file.txt file (ascii text). "festival" is a speach synthesizer that comes on the RedHat 7.0 "Linux PowerTools" CD. To say something from the command line, you need to start up "festival" and then, at the "festival>" prompt, type the appropriate command ("scheme" language interpreter), as in this example (bold represents the prompt):
festival
festival>(SayText "good dog, really good dog")
festival> (quit)
5.19 Graphics-related commands
kghostview my_file.ps
(in X terminal) Display a postscript file on screen. I can also use the older-looking ghostview or gv for the same end effect. I can print the postscript file from the viewer too.

xpdf my_file.pdf
(in X terminal) View a pdf file.

enscript my_file.txt -U 2
Convert a text file to postscript and print it to the default printer. I could also send the output to a postscript file:
enscript my_file.txt -U 2 -o my_file.ps
The option -U 2 makes enscript print 2 logical pages on one physical page which saves me paper, and creates more convenient, compact printouts. You may also select four pages per page, more makes the printout kind of difficult to read. enscript is really flexible, see man enscript to select from among the many formatting options.

ps2pdf my_file.ps my_file.pdf
Make a pdf (Adobe portable document format) file from a postscript file.

mpage -2 my_file.ps > new_file.ps
Print the postscript file my_file.ps, outputting two logical pages on one physical page. Save the output to the file new_file.ps.

ps2ps file.ps new_file.ps
psnup -nup 2 -pletter new_file.ps new_file2.ps
Another way of making a postscript file containing 2 logical pages on one physical page. First, I used the "postscript distiller" ps2ps to make the postscript file simpler (at the cost of it becoming much larger). Then, I used the psnup utility to make new_file2.ps which contains 2 logical pages per one physical page. I could have also put 4 or 8 logical pages per one physical page.

gimp
(in X terminal) A humble looking but very powerful image processor. Takes some learning to use, but it is great for artists, there is almost nothing you can't do with gimp. Use your mouse right button to get local menus, and learn how to use layers. Save your file in the native gimp file format *.xcf (to preserve layers for future editing) and only then flatten it and save as png (or whatever) for use. "Learning how to make proper selection is the key."

gphoto
(in X terminal) Powerful photo editor and camera image acquisition program.

kpaint
(in X terminal) Simple bitmap paint program ("paintbrush"-type).

xfig
(in X terminal) A simple drawing program. Useful for making elementary sketches or diagrams.

dia
(in X terminal) A tool for drawing diagrams from pre-built components.

display my_picture
(in X terminal) Display a picture for viewing only. You can also type display & and select file from the menu to view the image, rotate it , change its colour, apply certain effects, etc. display is part of ImageMagick package, together with several other utilities described below.

identify -verbose my_picture
Give me a description of an image file my_picture: format, type, class, size in pixels, number of colours, size in bytes, etc.

convert -geometry 60x80 my_picture.gif out_small_picture.gif
Scale a picture to a size 60x80 pixels. See a few line down for an example how to use convert to convert between different graphical file formats.

animate -delay 6x5 pic1 pic2 pic3
Keep showing two or more pictures in sequence. In the example above, the picture files are named pic1, pic2 and pic3, the delay between pictures is 0.06 second, and the whole presentation sequence is repeated in 5 seconds.

combine pic1 pic2 combined_pic.miff
Combine two or more images to another image. You can for example put a logo on every image.

montage -geometry 800x600+0+0 my_picture montage.miff
Create a tiled image from my_picture so that the total size is 800x600 pixels, with 0x0 border. The output goes to the file montage.miff.

zgv my_picture
Display a picture for viewing on a vga screen (no X necessary).

giftopnm my_file.giff > my_file.pnm
pnmtopng my_file.pnm > my_file.png
Convert the proprietary giff graphics into a raw, portable pnm file. Then convert the pnm into a png file, which is a newer and better standard for Internet pictures (better technically plus there is no danger of being sued by the owner of giff patents).

xwd -out my_cupture_screen_file.xwd
(in X terminal) Capture the contents of X-windows screen into a graphics X-windows "dump" file (*.xwd). You can later convert the xwd file into your favourite format using the convert utility. Unde KDE, you can also use the keyboard shortcuts <Alt><PrintScreen> or <Ctrl><Alt><PrintScreen> to copy the current window or the entire desktop into the clipboard.

convert my_capture_screen_file.xwd my_capture_screen.jpg
Convert the X-windows screen dump file (*.xwd) into the *.jpg file format. The convert utility can convert graphics from/to many different file formats.

import -display 192.5.100.10:0 -window root my_file.jpeg
Capture the contents of the root screen from X-windows runnning on server 192.5.100.10 display 0. The output file is my_file.jpeg (change the file format by giving it an appropriate filename extension). You need to have the permission to write to the screen in order to be able to capture its content (the permission to everybody can be given by running xhost + in the X-terminal). See man import for options.

ksnapshot
(in X terminal) GUI-based utility to capture screen contents.

xine frankenstein.avi &
(in X terminal). Watch the movie from the file "frankenstein.avi". Looks better than on a TV )
5.20 Small games
Many small games are probably installed on your system. Here is just a sample that installed from my standard Linux distribution CD.

kpat
(in X terminal) Patience card game. sol (fast) and pysol (slow but loaded) are two other choices. My favourite is: sol --variation=freecell&

xboing
(in X terminal). Very nice, pin-ball game.

xboard
(in X terminal) Chess. Plays too well for me

konquest &
(in X terminal) Compete with your son in a conquest of a galaxy. Nice board game.

kmines
(in X terminal) Minesweeper.

civserver
civclient
(in X terminal) Startup server for the FreeCivilization game (first command). Afterwards, when the server is already running, start up the client (second comamand). Somebody else starts another client--and you play. FreeCiv came on my RH7.0 CDs.

fgfs
"Flight Gear" flight simulator.

Go to Part 6: Essential Linux applications (proprietary or not)
Back to Top Page
顶端 Posted: 2006-04-20 15:24 | [楼 主]
PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 操作系统(Windows、Linux)

时:01-10 07:16 Copyright © 2006 phpwhy.com 权
ICP05060669

曳息 -