A collection of tips for using Linux commands

Source: Internet
Author: User
Tags aliases gz file dmesg

1. Using the Virtual Console

When you press ALT+F2 after logging in, you can see the "Login:" prompt, which is a second Virtual Console. Generally the newly installed Linux has four virtual consoles that can be accessed using ALT+F1~ALT+F4. The most useful time for a virtual console is when a program fails to lock the input and can switch to another virtual Console? [COLOR=RED:8EA1DE57F3] Now generally default is 7, you can use ALT+F1~ALT+F7 to switch, the seventh is generally xwindow; if Xwindow is enabled, use ctrl+alt+f* to toggle [/color : 8ea1de57f3]

2. Copy and paste

Character interface: either Slackware or Redhat automatically runs a program called GPM each time it is installed, and the program can be copied and pasted with the mouse after running. The specific method is to hold down the left mouse button to drag the place to copy the anti-white, then the anti-white area has been copied, and then press the right mouse button to copy the content will be pasted in the cursor location. X-window: Copy of the operation of the same as the character interface, the three-button mouse press the middle button to paste, two-button mouse at the same time press the left and right key paste (must be configured XF86 in the settings of the mouse to select emulate 3 Button).

3. Quick access to certain directories

Type cd ~ To enter the user's home directory. Type CD-to enter the previous entry directory. [COLOR=RED:8EA1DE57F3] in the rh8,9 with a CD to enter the login directory, such as the root user CD into the/root. [/COLOR:8EA1DE57F3]
4. Use of the floppy drive

If it is a Linux ext2 file system with the following command: #mount-t ext2/dev/fd0/mnt dos floppy disk is used command: #mount-T msdos/dev/fd0/mnt then you can access the contents of the floppy disk in/mnt, notice in Remove the floppy disk before removing the file system, #umount/mnt otherwise it will result in loss of information. To create a file system on a floppy disk, you can use the following command: #mke2fs/dev/fd0 1440

5. Redhat displays a list of color catalogs

Open/ETC/BASHRC, add the following line: Alias ls= "ls--color" the next time you start bash, you can display a colorful list of directories like in Slackware, where the meaning of the color is as follows: Blue--and catalog Green--- Executable file Red--zipped file Light blue--Link file Grey--Other files

6. Display the type of file

Use the command file to let you know whether a file is an elf-formatted executable or a shellScriptfile or any other format for example: #file startx

7. Path to the command file

When you type some commands such as Find, shutdown, Mount, StartX, do you want to know exactly which directory these files are placed in? can be implemented with command Whereis, such as #whereis startx [COLOR=RED:8EA1DE57F3] can also be used which, for example which LS[/COLOR:8EA1DE57F3]

8. Find Files

Find command to add some parameters to find the file, such as: #find/usr-name xf86setup-print Find the file Xf86setup in/usr.

9. Delete the useless core file

When the program runs out, it sometimes produces a file called core, which is generally large and useless, and can be deleted to free up space.

10. Once untied. tar.gz file

Untie. tar.gz files are generally first extracted with gunzip and then unpacked with tar, under Linux can be completed at once, such as: #tar ZXPVF sample.tar.gz

11. Display long file names in the Win95 partition

If you find that the long file in the Win95 partition cannot be displayed, you can re-mount it in VFAT way. For the boot-mount partition can modify the file/etc/fstab, the inside of the Msdos Word to VFAT. If you cannot use VFAT mount, recompile the core and add support for VFAT.

Norton Commander in Linux

After you type command MC at the prompt you will see a very similar interface to Norton Commander, which is actually similar or even more powerful, such as the ability to directly manipulate files in the. tar.gz archive (a bit like zipmagic).

13. Enter x directly after booting

Edit the/etc/inittab file and change the id:3:initdefautl to Id:4:initdefautl. However, the search path may be a problem, you have to go directly into the/sbin to perform shutdown.
[COLOR=RED:8EA1DE57F3] This place is wrong, it should be id:5:initdefault. Now there is no need to go into the/sbin to execute shutdown because the path has been added to the/etc/profile. [/COLOR:8EA1DE57F3]

14. Run X program in the background

When executing an X program, do not forget to add a & in the back, such as #netscape & otherwise you will not be able to enter commands in that terminal window until you launch the executed program?

15. Forced Exit X

Sometimes in X because of the program error, the mouse keyboard does not work, this time do not worry, because in Linux almost will not like in the Win95 of the vicious crash, you only need to type Ctrl+alt+backspace key to return to the character interface. [COLOR=RED:8EA1DE57F3] If x is started by default, pressing these three keys restarts X. [/COLOR:8EA1DE57F3]

16. Lilo fails after reloading Win9x unable to start Linux

Just start Linux with a floppy disk and run the Lilo once. For Redhat you can use the command Mkbootdisk to make the startup disk, for example: Mkbootdisk--devices/dev/fd0 2.0.34-1 where 2.0.34-1 is a directory under/lib/modules.
[COLOR=RED:8EA1DE57F3] That 2.0.34-1 is actually the kernel version number, if you do not know can be like this. Mkbootdisk--devices/dev/fd0 ' uname-r '. Note This ' is the key above the TAB key, is not a single quotation mark. [/COLOR:8EA1DE57F3]

17. Change the dos/windows to the default boot OS

Redhat Linux as Lilo default boot OS, that appears boot: prompt after the direct carriage to start Linux. If you want to change to Dos/windows, modify the file/etc/lilo.conf, put the Boot DOS section in front, and then run the Lilo again. For example, take lilo.conf from: Boot=/dev/hda
Map=/boot/map
install=/boot/boot.b
Prompt
Timeout=50
Image=/boot/vmlinuz-2.0.34-1
Label=linux
ROOT=/DEV/HDC5 read-only
Other=/dev/hda1
Label=dos
Table=/dev/hda
Switch
Boot=/dev/hda
Map=/boot/map
install=/boot/boot.b
Prompt
Timeout=50
Other=/dev/hda1
Label=dos
Table=/dev/hda
Image=/boot/vmlinuz-2.0.34-1
Label=linux ROOT=/DEV/HDC5 read-only
[COLOR=RED:8EA1DE57F3] This is also outdated, if you use Lilo, then directly under the prompt add a line default=dos, and then run lilo-v can, if it is grub, then change default= 0 See if you Windows is 0 or 1.grub do not reinstall [/COLOR:8EA1DE57F3]

18. Remove the Lilo information in the boot area

After installing Lilo, if the number of hard disk or partition situation changes will cause the hard drive can not start, then only need to use a floppy disk boot dos and then run FDISK/MBR. (This method can also remove any boot area virus)

19. Let X support AGP graphics

Download an AX 4.1 that is Acceleratedx 4.1, a commercial edition of X Server. In addition to AGP graphics, AX also supports many brand graphics cards. In addition, you can use the Setup program of AX Xsetup to set the resolution, refresh rate and other parameters conveniently. But I do not know how to use the AGP card effect, because I am still using the old S3 765. [COLOR=RED:8EA1DE57F3] now supports AGP by default [/COLOR:8EA1DE57F3]

20. Save the information of man or info as a text file

Take tcsh as an example: Man tcsh | Col-b > Tcsh.txt Info tcsh-o tcsh.txt-s

21. Use the current path as a prompt

For bash, in. BASHRC Add a line: ps1= "$PWD $" for tcsh, in. TCSHRC Riga Line: Set prompt= "%/>"

22. Compressing the executable file

Linux has a DOS-like pklite and Lzexe command-Gzexe. And the compression rate can be more than 50%, which is useful when space is tense. Like what:

/dosc/temp# Ls-al Total 148-rwxr-xr-x 1 root root 149564 Dec 8& nbsp;15:33 gawk/dosc/temp# gzexe gawk&n bsp;ga wk:54.5%/dosc/temp# Ls-al Total 216-rwxr-xr-x 1 root root&nb sp;68710 Dec 8 15:36 gawk-rwxr-xr-x 1 root root 1 49564 Dec 8&nbs p;15:33 gawk/dosc/temp#
[COLOR=RED:8EA1DE57F3] can now be used GZIP[/COLOR:8EA1DE57F3]

23. View information on Linux startup

The information displayed on the screen at Linux startup is too late to see, and if you are interested in this information, you can use the command DMESG to view it. [COLOR=RED:8EA1DE57F3] with DMESG |more may look more carefully [/color:8ea1de57f3]

24. Handle files with special characters in the file name

If there is a file called-file if you want to delete it, type Rm-file will display invalid option, originally because the first character of the file name is-, Linux has the file name as an option, you can add-to solve this problem, such as RM---file. If it is a special character, you can add one before the special character, or enclose the entire file name in double quotation marks.

25. Processing a whole catalogue at a time

Linux/unix a lot of common commands such as RM, CP and so on have a parameter-----R, is the meaning of recursion, the command in the Add parameter-R to the target directory and all its sub-directories, such as: Rm-rf/test (f is force means forced), the The command completely deletes the subdirectory under the root test, which acts like a Dos deltree, and is of course especially careful when using this command. Again such as: Cp-r/test/test1 has similar DOS under XCOPY/S function.

26. Modify the login screen

To this machine: first modify the file/etc/issue to display the content, and then modify the file/etc/rc.d/rc.local (RedHat) or/ETC/RC.D/RC. S (Slackware) Comment out the following sentences:

# This would overwrite/etc/issue at every boot. So, make any changes your # want to make to/etc/issue here

Or you'll lose them when you reboot. echo "" >/etc/issue echo "Red Hat Linux $R" >>/etc/issue echo "Kernel $ (uname-r) on $a $ (uname-m)" >>/ Etc/issue

Cp-f/etc/issue/etc/issue.net Echo&nbs p;>>/etc/issue

Otherwise, each restart of the/etc/issue will be changed.

Remote machine for Telnet: First rename the file/etc/usr/sbin/in.telnetd, such as change to In.telnetd.exe, and then a shell script named in.telnetd, after displaying the required content and then calling In.telne Td.exe. Such as:

#!/bin/sh cat/etc/login.banner #需要在登录提示符前显示的内容 echo-n "" Exec/usr/sbin/in.telnetd.exe

27. A few useful aliases

Several aliases that are easy to operate and reduce misoperation, it is recommended to put them in the startup file, such as/ETC/BASHRC.

Alias rm= ' rm-i ' Alias cp= ' cp-i ' Alias mv= ' Mv-i '

#前三个别名的作用是在删除, overwriting the file before the prompt confirmation, Redhat has been automatically #加上了, it is strongly recommended that Slackware users also add, because Linux/unix the next file deleted #除就再也无法恢复了.

Alias l= ' Ls-l ' Alias CD. = ' CD: ' Alias utar= ' tar xvfz ' #解 *.tar.gz file alias inforpm= ' Rpm-qpi ' #显示rpm包的信息 alias instrpm= ' RPM-UHV ' #安装rpm包 alias L Istrpm= ' RPM-QPL ' #列rpm包内的文件 alias uistrpm= ' Rpm-e ' #反安装rpm包

28. Use the command to complement

The so-called command completion (command-line completion) means that when the character that you type is sufficient to determine the next unique file in the directory, you only have to press the Tab key to automatically finish the remainder of the file name, for example, to put the directory/freesoft under the file Gcc-2.8.1.tar.gz unpacking, when typing to tar xvfz/freesoft/g if the file is the only file in the directory with the head of G, you can press the Tab key, then the command will be automatically filled with: Tar xvfz/freesoft/gcc-2.8. 1.tar.gz, very convenient.

29. Last Tip

If you have time, take a look at the FAQ files provided by the system, because most of the problems you usually encounter can be found in the answers. [COLOR=RED:8EA1DE57F3] This can be viewed with the man command, such as man LS or info to see more detailed help information, such as info/etc/fstab. Alternatively, you can view the Help manual directly in/usr/share/doc. [/COLOR:8EA1DE57F3]


[Color=green:8ea1de57f3]30. Enter single-user mode and restrict access to single-user mode.
Single-user mode allows ordinary users to have all of the root permissions, if you forget the root password, or the system has a problem and the system administrator is not anxious to repair the system, the use is still very large. But there are also security risks.
A. Entering single-user mode
Lilo, press CTRL+X when the boot interface appears and then enter the Linux single return after boot: to enter the one-user mode.
Grub: When the Boot interface appears, press E, then select the second line (kernel*), and then press E. Enter single or init 1 or 1 (both) at the end, press ENTER, and then press B to boot.
B. Restrict access to single-user mode, no password when booting the system
Lilo: Add Password=password to the next line of install=/boot/boot.b
Restricted
Then run Lilo-v
It is important to note that it is best to restrict normal users from editing lilo.conf otherwise the plaintext password is useless. chmod 600/etc/lilo.conf. Just read and write access to the root user is OK.
Grub: In grub.conf in the first paragraph anywhere in the password= plaintext password, or first use Grub-md5-crypt to generate an encrypted password, and then use the mouse to select it, press ctrl+shift+c copy, Then open the grub.conf in the upper section of the title plus PASSWORD=--MD5 (note that there is a space), and then right-click, the password to stick your encryption. Or you can write password MD5 the format of the password can be. Then save the reboot.
It is recommended that you use an encrypted password. This way, even if an ordinary user opens grub.conf, they don't know what the password is.
C. Restrict user access to the specified system. (Useful for multi-boot systems)
Lilo: Add password= password under label=*
Grub: Add password--md5 password under title=*

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.