[Linux] Some tips for Linux (reproduced)

xiaoxiao2021-03-06  106

http://www.21php.com/tutorial/tutorial.php?tid=89 Author: LinuxForum 1. After the virtual console login press Alt F2 key Then they can see the "login:" prompt, this is the first Two virtual console. Press Alt F1 to return to the first console, and it is very convenient to switch back. View a few lines: #Run gettys in Standard Runlevels 1: 12345: Respawn: / sbin / mingetty tty1 2: 2345: Respawn: / sbin / mingetty tty2 3: 2345: Respaw: / sbin / mingetty Tty3 4: 2345: Respawn: / sbin / mingetty TTY4 5: 2345: Respawn: / sbin / mingetty tty5 6: 2345: Respawn: / sbin / mingetty TTY6TTYTTTYTTTTY TTYT TTY6 TTY6 TTY5 TTY5 6: 2345: TTY6Ty Edit this file to increase or reduce the virtual console. Use the virtual console under xwin to switch with Ctrl Alt F?. XWindow occupies the first console after the virtual console, the default is TTY7, so to switch back to XWIN, press Alt F7 (when you change the number of virtual console). If the second XServer started, it should be Alt F8, and so on.

2. Refrex Displaying the color directory and file list with ls --color -f, parameter - COLOR indicates color display, parameter -f will add a character after the file / directory name to indicate its category. It is recommended that beginners use MAN Ls to see more information. For example, use the -l parameter to list most of the information (long format display); all files are listed in -A parameter; including the first character "." Hidden file; use -n parameter does not process file name Directly displayed, so that the Chinese file name can be displayed in the Chinese environment. Also note that the use of LS and other commands can have many techniques (the easiest, "LS -L | more"). For convenience, you can edit / etc / bashrc or your own .bashrc, join a line: Alias ​​Ls = "ls --color -f -n" Run Bash will take effect immediately, if added / etc / bashrc is valid for all users who use the Bash Shell. If you are using other shells, go to the corresponding configuration file. Be careful not to / etc / aliases file, that is the alias configuration file for Sendmail. The color of the LS display can be modified, please refer to "Colour With Linux Terminals", there is a shell script to display all ANSI colors. You can take a look at / etc / dir_colors or $ home / .dir_colors, pay attention to the scope of the two files. You can also use the Dircolors -p command to list settings, see "Man Dircolors" in more details.

3. Methods: LS -F | GREP / $ or Alias ​​Sub = "LS -F | GREP / $" (Linux) LS -L | GREP "^ D" or LS -LL | GREP "^ D" (Solaris) Find. -Type D Find. -Type D | Sort Reference Dtree

4. List all files in addition to certain types of files All files use KSH, with LS! (*. Z), all files can be displayed, except * .z files. This command is useful to use many types of files in a directory .5. 5. Count the number of calculated files and directory counts, can you help you calculate how many files and how many directorys .. ls -l * | grep "^ - "| WC -L <---- to count files ls -l * | grep" ^ D "| WC -L <----- to count DIR can also turn the above statement into script or a Alias

6. All files in the replication subdirectory and subdirectory are plus -r parameters when using CP, such as "CP -R / MNT / FLOPPY / * / USR / local /" to refer to the important parameters of -f -s

7. File / Directory Renname Simply move with the move command to the new name. For example, "MV / USR / OLDNAME / USR / NEWNAME"

8. Delete all files and subdirectories and subdirectories in a directory RM -RF / TMP / EXAMPLE these are prepared for lazy people, and novices are best to learn more by man command. If English is not good, wait for the Chinese release :-(

9. Quickly enter some directory Type CD ~ (or CD $ HOME) to enter the user's Home directory. Type CD - to enter the previous directory.

10. Display Environment Variable Echo $ Home Display Home Directory Echo $ PATH Display Executable Search Path ENV Displays all environment variables (there may be many, "Env | more", "Env | Grep Path", etc.) Modify environment variables, With Export under Bash, settenv under CSH. For example: export path = $ PATH: / usr / local / bin wants to know the specific usage of Export, you can use the shell's Help command: Help Export

11. Display the type of file with file command, such as "file / bin / mount", "file xxx.gz", "file netscape", "file init.img", and more. Related configuration files in / etc / magic or / usr / share / magic

12. Find the path to the command file, such as the specific path you want to find the mount command, you can use the Type mount whereis mount to find out the file related to this command file such as Manuals Page.

13. Find files Using the FIND command, such as: Find / usr -name XF86 * In / usr directory (including subdirectory) Find the first four letters XF86 file Find. -Name Netscape -print in the current directory (included Subdirectory) Find files Find / Home -nouser named Netscape Find files with users with users (user account deleted but legacy files) Find / var -newer test Look for better than Test in / var directory File date Update file Find command has many parameters, pay attention to view with the man command. The faster lookup file is using Locate, using LOCATE to update the file / directory name database before using Locate. It writes the file / directory information into the database, and it is especially fast. Updatedb is placed in crontab and the default configuration is automated in the middle of the night. Locate has a slight security problem because normal users can use it to get part of the directory / files that they cannot access. There is now a Secure Locate, saving the UID / GID to the database, and the user compares the permissions in Locate. 14. How do you see how the message has been scrolled over under the recovery screen? Try these two button combinations: Shift PageUp and Shift PageDown are valid for xterm / nxterm / cxterm / xxgdb. Kvt with KDE has been made very well.

15. Special way to view file content, I believe that you are already very familiar with the most basic CAT and LESS. If you have special requirements: If you just want to watch the top 5 lines of the file, you can use the head command, such as: Head -5 / ETC / Passwd If you want to view the file 10 line, you can use the tail command, such as tail -10 / etc / passwd tail -f / var / log / messages parameter -F makes tail to read the latest content, This has the effect of real-time monitoring, when you use it in the process of ppp, it is not very convenient! To view the middle of the file, you can use the sed command such as: SED -N '5, 10p' / etc / passwd, you can only view the fifth line to 10th line of the file.

16. Cancellation ^ M character When you ftp some DOS files to UNIX, you often see a hateful ^ M character behind each row, there are two simple ways to cancel it. Use "VI" to open this file, knock in Command Mode::% s / ^ v ^ m //g or, tapping in Unix Shell: SED 'S / ^ V ^ m //g' foo> foo .new

17. Use the find command to change the ownership of ownership to change all the files in the current directory, which can be: find. -Exec chown owner. [Group] {}; (Solaris) Find. -Exec chown -r owner. [Group] { }; (Linux)

18. Change XTERM / CXTERM to press the CTRL button at the same time, press the CTRL button and the right click will pop up a menu to make you choose, or you can specify the font when starting xterm, such as "xterm -fn 8x16 &" prompt: Don't you try Ctrl What will the left mouse button ?!

19. When starting a program, let it enter the background running method to see the previous Bash introduction should understand the usage of Ctrl Z / BG / FG. Some programs work more tired, add a & symbol after it, such as "UpdatedB &", "Netscape &", and more. This way this shell will release it. Note that the prime process of this coming is still this shell, if you exit this shell, these programs will be drilled by KILL (unless this program specially processes yourself from the shell). It is recommended to check the background job with the jobs command before exiting the shell. 20. Use the NOHUP command (not hang) If you want the process to execute after you exit the system, you can use the nohup command such as% nohup tar -cf / dev / tape / home & you logout, then log in, Use the 'ps' command to see the process is still noticing, you must run the command to run in the background, NOHUP must be used with & operation. Some software can handle SIGHUP signals, such as Wget, there is no need to use NOHUP. If you are willing to start the brain, you can also use nohup to implement PPP callback: first dial, then perform a homemade script with NOHUP, such as "Sleep 60; PPP-START-SCRIPT", etc. Finally, logout exits and hang up the phone is waiting.

21. Quickly call the history command to read the introduction of the previous Bash, you must be familiar with History,! !! These usage is very familiar. In fact, you can also use the upper and lower sponsor keys to call up the history command, then use the left and right cursor keys and edit the command line.

22. Generate a file file file = `Date ' % m% d'! Touch Todayis. $ File or a shell script: #! / Usr / bin / sh file =` Date' % M% D'`Touch Todayis. $ FILE EXIT 0 Note" `" in the File variable is not "'", but the left upper number key 1 is the one (left single quotation mark).

23. Save the content of Man / Info as a text file as an example: 1) Man TCSH | col -b> tcsh.txt 2) nroff -man tcsh.man | col -b> tcsh.txt is in info emacs Example Info Emacs -o Emacs.txt -s Tip, if you have KDE, use KDEHELP to see Man Page and Info Page is very convenient. It is also a TKMAN to choose, and it is a graphic / hypertext method, a search engine, and more functions. Newcomers should go to MAN and INFO!

24. About RPM Tips 1) Display progress with -VH parameters when installing the RPM package, such as rpm -ivh ipchains-1.3.6-1.i386.rpm If you use GLINT or XRPM, it is not necessary. 2) Directly install RPM packets, such as rpm -i ftp://ftp.xxx.xxx 3) Check all RPM packets, find lost files rpm -va 4) Find a file that belongs to which RPM package, for example: rpm -QF / USR / BIN / WHO 5) Description information of an RPM package, for example: rpm -qpi mon-0.37j-1.i386.rpm 6) List the file information of an RPM package, for example: rpm -qpl mon- 0.37J-1.I386.rpm25. Quick Expand XXX.TAR.GZ / XXX.TGZ Compressed Pack Tar ZVFX XXX.tgz Expand this package in the current directory TAR ZVFT XXX.TGZ only test does not expand TAR ZVFX XXX.TGZ - C / New-DIR is started after the / new-dir directory TAR ZVFC Test.tgz / test puts all the files and subdirectories in the / Test directory into Test.tgz tar parameters, you have to learn.

26. Copy and Paste Text If you start the GPM this patron program, you can use the left mouse button to select the text, then you can paste it into the place you want. If the two-button mouse is the configuration is to select the anti-real 3 key mouse, then press the left and right to simulate the middle button. You should use the mouse button under the text terminal to paste.

27. Quick Find a PID number / shutdown in a program run, for example, want to find inetd: ps aux | grep inetd, if you want to find the most memory process: PS AUX | Sort 4n finds KILL to give It signals, or forces to kill it such as: kill -9 xxx (PID of a process) offers a KILLALL in Linux, you can directly use the name of the process rather than the PID number, such as killall -hup inetd, such as Killall XDM. KILLALL will send a signal to all processes running in the program that specifies the name. List all available signals with KILLALL -L. When it comes to PS, I can't help but introduce QPS, write the graphical interface written by QT, combined with the characteristics of Free, TOP, PS and KILL, and see the Socket / Memory Map / Files information for the process. There is also KTOP written for KDE, the advantage is to list the relationship between the parent and child process. Shutdown -r now killed all processes immediately restarted shutdown -h now killed all proximity shutdown -h 5 "Warning: after 5 minutes I'll shutdown" sent to the user and stopped after 5 minutes. Relevant commands have Reboot, Halt, Poweroff, INIT, etc. To achieve the software turning off the power, your PC must be an ATX structure, then go to configure the compiled kernel, open the Charactor Device / Advanced Power Management Support / Power Off On Shutdown.

28. Find the font information under XWindow, especially the character mapping table (internal code) XLSFONTS lists all font xfontsel categories list all fonts and display the Demonstration Text XFD Displays all characters and internal code in a font file, such as XFD -fn hanzigb16fs Take a look at the Chinese code and use XFD -FN CClib16ST to see the internal code of the font library used in CXTERM and the XF86 (note the highest bit).

29. Find the date of the date for a certain day A = `Find ~ -print` | ls -l - exten-time $ a 2> / dev / null | grep" jun 27 "| Grep 1998 Linux command is very powerful ! Write you with this script, with convenient point. You store it into a file that is just a file, set the X attribute. #! / bin / sh # Copyright by Ming Gong (Miye) for news: //news.freesoft.cei.gov.cn/chinese.com.linux # GPL V2, Jun 30, 1998 # The right of usage, Distribution And model is here by the author. # The author deny any responsibilities and liabilities related to the code. # OK = 0 a = `Find $ 1 -Print` if EXPR $ 3 == 1> / dev / null; the m = Jan; OK = 1; FI if expr $ 3 == 2> / dev / null; then m = feb; OK = 1; Fi if expr $ 3 == 3> / dev / null; the m = mar; ok = 1; Fi if EXPR $ 3 == 4> / dev / null; the m = APR; OK = 1; FI if EXPR $ 3 == 5> / dev / null; Then M = May; OK = 1; Fi IF EXPR $ 3 == 6> / dev / null; the m = jun; ok = 1; FI if expr $ 3 == 7> / dev / null; the m = jul; ok = 1; Fi if expr $ 3 == 8> / dev / null Then m = aug; OK = 1; FI if EXPR $ 3 == 9> / dev / null; Then m = SEP; OK = 1; FI IF EXPR $ 3 == 10> / dev / null; THEN M = OCT; OK = 1; Fi if expr $ 3 == 11> / dev / null; the m = NOV; OK = 1; Fi if expr $ 3 == 12> / dev / null; THEN M = DEC; OK = 1; FI if EXPR $ 3 == 1> / dev / null; THEN M = Jan; OK = 1; Fi

IF expr $ ok == 1> / dev / null; the ls -l - the expr-ful-time $ A 2> / dev / null | GREP "$ m $ 4" | GREP $ 2; Else Echo usage: $ 0 pat year month day Echo EXAMPLE: $ 0 ~ 1998 6 30; Fi

30. Use a mobile phone such as a floppy disk / disc that has just turned from the death / dish, and the hand is holding the floppy disk / disc don't know how to do, because there is no A disk D disk under Linux. I just started learning. This is also the case when Linux (I have never done root :-). If you have a book with Linux, take a closer look at the relevant chapters of the equipment and documentation system. Simply put, you need to install the file system on the floppy disk / disc device to a point on the Linux directory tree, called Mount Point, usually a directory. After installing Linux, there is a default installation point / mnt, below / mnt / floppy and / mnt / cdrom. You can use mount -t ext2 / dev / fd0 / mnt / floppy <- Install the floppy disk of Linux file system format to mount -t MSDoS / DEV / FD0 / MNT / FLOPPY <- Floppy disk installation of DOS file system format Upper mount -t vfat / dev / fd0 / mnt / floppy <- vfat support 95/98 long message name mount / dev / hdb / mnt / cdrom <- put it in the first IDE port The disc installation on the optical drive is installed on the mount / dev / cdrom / mnt / cdrom

31. Add / Delete Users to add a user named username with useerAdd UserName (or addUser UserName) and specify passwords with passwd username. The user's information is recorded in the / etc / passwd file, because each user can (and must be able to read this file) then can Crack Other users password, for security considerations now using Shadow. The password of the user under / etc / passwd changes into X real password records in / etc / shadow, and this file only can read it with root privileges. RedHat 5.1 The following version does not use Shadow directly, you need to convert it with PWCONV. If you want to change it, you can use PWUnConv. Tip: In the / etc / skel directory records a basic file (LS -A / ETC / SKEL / see what is available), using the userAdd automatically copies these files to the user's home directory and appropriate Permissions (using -m parameters when adding users: useradd -m xxx). If you under this directory down key, you will automatically have a directory of the same name in its home directory, so that each user has "Person Home". Deleting users can use userDel usrname or userdel -r username (some releases may be DELUSER), - R parameters will delete this user's home directory, but there may be information on this user in other places, so deleted users It is best to find somewilled relevant information with Find / -user username. If you want to temporarily prohibit one user, you can add one * to the first character of this user's password in the / etc / passwd file. If you change the cryptographic domain to empty, you can enter the system if you don't need your password. When you forget the root password, you can use floppy to start the original root installation, go directly to the Passwd file. I don't need a password when starting in a single user mode. The problem of long user names, it has been made very well in the RedHat release, and it is also allowed to have spaces in the username. If you don't support the release in your hand, you will change UT_NAMEDSIZE to 32 to /usr/include/utmpbits.h, recompile the relevant program. Another intuitive configuration tool is LinuxConf, such as using it to configure PPPUSER, and more. Here you can only give some clues, you will see "Man Useradd", "Man Shadow", "Man Group", "Man UseerDel" ...... Returns newcomers to read more books more to see MAN Page Otherwise, it is not easy to find / etc / skel. 32. List the space DU or DU -S or DU -K du -s or du -k du -s | sort -n, which is occupied by a directory, can quickly discover that directory is the biggest. Use DF to see the space size of the installed file system and the remaining space size. Quota -v View the user's disk space information if you limit the user's space size with quota.

33. Commands (Tab keys) There are many shells with this feature. 1) Simply enter the first few characters of the file or directory name, then press the Tab key, if there is no weight, the complete file name is automatically automatically appeared in the command line; if there is a weight, press the Tab button, system The current directory will be listed in the current directory. For example, the CD / MNT / CD

34. There is no setENV in RedHat5.0, and the variable set by Set will not read in the program. Which function can be used to read the environment variable set by the set? Set env; export env is then read with GetENV . 35. Let the grep search file and the contents of all subdirectory, such as "chinput" in all C original code under zhxwin (try cancel the downlink -q parameter): Find / Download / zhxwin -name * .c -EXEC GREP -Q -S chinput {}; -print Find all files You can use: find. -type f -exec grep -s Chinese {}; -print If you like the graphical interface, Kfind's Kfind is very good.

36. Check the log information at startup First Go to the /etc/syslog.conf file, find the corresponding file. (More detailed information to see "Man syslogd" "man syslog.conf" and "man klogd") is usually under SLACKWARE / VAR / ADM / Messages under RedHat / var / log / messages. These files may be large, pay attention to backup and deletion. In the previous, it has been mentioned in Tail (Tail -f) method, and there is a logscanner tool, which is quite good.

I suggest you read The Linux Tips Howto and go to Linux Gazette. See a new open site when collected these documents: Linux Tips & tricks

转载请注明原文地址:https://www.9cbs.com/read-103221.html

New Post(0)