Linux must command Linux to provide a large number of commands, which can be used to do a lot of work effectively, such as disk operations, file access, directory operations, process management, file permission settings and so on. Therefore, it is necessary to work on a Linux system using the commands provided by the system. To really understand Linux systems, you have to learn from Linux commands and learn more about Linux systems with basic command learning.
 
different Linux distributions are not the same number of commands, However, the minimum number of commands for Linux distributions is more than 200. Here the author of the more important and most frequently used commands, according to their role in the system is divided into the following six parts of the introduction.
Installation and login commands: Login, shutdown, halt, reboot, install, mount, Umount, Chsh, Exit, last;
file processing commands: Files, mkdir, grep, DD, find, MV, LS, diff, Cat, ln;
system Management related commands: DF, top, free, quota, at, LP, AddUser, Groupadd, Kill, crontab;
network operations commands: ifconfig, IP, ping, netstat, Telnet, ftp, route, Rlogin, rcp, finger, mail, nslookup;
system security-related commands: passwd, Su, Umask, Chgrp, chmod, Chown, chattr, sudo ps, who;
other commands: Tar, unzip, Gunzip, Unarj, Mtools, man, Unendcode, UUDecode.
Login
2. Use
Login's role is to log on to the system, and its use rights are for all users.
2. Format
Login [name][-p][-h host name]
3. Main parameters
-P: Notifies login to maintain the current environment parameters.
-H: Used to transfer user names between remote logins.
If you choose to log in to Linux in command-line mode, the first Linux command you see is login:.
The General interface is this:
manddrake Linux Release 9.1 (Bamboo) for i586
Renrel 2.4.21-0.13mdk on I686/tty1
localhost login:root
PassWord:
in the above code, the first line is the Linux release number, the second line is the kernel version number and login Virtual Console, we enter the login name on the third line, press "enter" key after password enter the account password, you can log in the system. For security reasons, the characters are not echoed on the screen when the account password is entered, and the cursor does not move.
You will see the following interface (in the case of Superuser) when you log in:
[email protected] root]#
Last Login:tue, Nov 10:00:55 on VC/1
The above shows the logon week, month, day, time, and the Virtual Console used.
4. Application Tips
Linux is a true multi-user operating system that allows multiple users to log in at the same time, allowing one user to log in multiple times. This is because Linux, like many versions of UNIX, provides access to the Virtual console, allowing users to log in multiple times at the same time from the console (the system's console is a monitor and keyboard that is directly connected to the system). Each virtual Console can be viewed as a stand-alone workstation that can be switched between workstations. Virtual Console switching can be achieved by pressing the ALT key and a function key, typically using F1-F6.
For example, after a user logs in, clicking the "Alt+f2" key will allow the user to see the "login:" Prompt that appears above, stating that the user sees the second Virtual Console. Then simply press "ALT + F1" key to go back to the first Virtual Console. A newly installed Linux system allows users to use "ALT+F1" to "Alt+f6" keys to access the first six virtual consoles. The most useful thing about virtual consoles is that when a program fails to cause a system deadlock, you can switch to another virtual Console to work and close the program.
shutdown
1. Role
the role of the shutdown command is to shut down the computer, and its use rights are super users.
2. Format
shutdown [-H][-I][-K][-M][-T]
3. Important Parameters
-T: Tell the INIT program how long it will shut down before changing to another runlevel.
- K: Not really shut down, just send a warning signal to each login.
-H: Power off after shutting down the machine.
-c:cancel Current process cancels the currently executing shutdown program. So this option certainly does not have a time parameter, but you can enter a message to interpret, and this information will be sent to each user.
-F: Forces fsck to restart the computer.
-time: Set the time before shutting down the machine.
-M: Change the system to single-user mode.
-I: Displays system information when shutting down.
4. Command Description
The shutdown command can safely shut down the system. It is dangerous for some users to shut down the Linux system in a way that directly shuts off the power supply. Because Linux, unlike Windows, runs many processes in the background, forcing a shutdown can cause data loss to the process, leave the system in an unstable state, or even damage the hardware device (hard disk) in some systems. Using the shutdown command before the system shuts down, the system administrator notifies all logged-in users that the system is shutting down and the login command is frozen, that is, the new user can no longer log on.
Halt
1. Role
the function of the halt command is to shut down the system, and its usage rights are super users.
2. Format
Halt [-N] [-W] [-d] [-f] [-i] [-p]
3. Main parameter Description
-N: Prevents the sync system from being called, it is used after patching the root partition with fsck to prevent the kernel from overwriting the patched super block with the old version of the Super block.
- W: not a real restart or shutdown, just write Wtmp (/var/log/wtmp) record.
- F: No call to shutdown, but forced shutdown or restart.
-I : Turn off all network interfaces before shutting down (or restarting).
-F: Force shutdown, do not call shutdown this command.
- P: The way to turn off the power when the computer is turned off.
-D: shuts down the system but does not leave a record.
4. Command Description
Halt is called shutdown-h. When the halt executes, the application process is killed, the system calls to perform sync (forcing the data stored in buffer into the hard disk), and the kernel is stopped after the file system write operation is complete. If the operating level of the system is 0 or 6, the system is shut down, otherwise the shutdown instruction (plus the-h parameter) is replaced.
reboot
1. Role
the role of the reboot command is to restart the computer, and its use rights are system administrators.
2. Format
reboot [-n] [-W] [-d] [-f] [-I.]
3. Main parameters
-N: Do not write the memory data back to the hard drive before rebooting.
- W: does not really reboot, just write the record in the/var/log/wtmp file.
-D: Do not write the record into the/var/log/wtmp file (-n This parameter contains-D).
-I : Stop all network-related devices before rebooting.
Install
1. Role
the Install command works by installing or upgrading software or backing up data, and its use rights are for all users.
2. Format
(1) Install [options] ... Source Destination
(2) Install [options] ... Source... Catalogue
(3) install-d [options] ... Directory ...
In the first two formats, copying to or copying multiple files to an existing one, and setting the permission mode and owner/owning group. In the third format, all the specified directories and their home directories are created. The parameters that must be used for the long option are also required when using the short option.
3. Main parameters
--backup[=control]: A backup of each existing destination file.
-B: Similar to--backup, but does not accept any parameters.
-C: (This option is not processed).
-d,--directory: All parameters are processed as directories, and all home directories for the specified directory are created.
-D: All the home directories before the creation, then copy to; useful in the first use format.
-g,--group= Group: Sets the owning group itself, not the group to which the process currently belongs.
-m,--mode= mode: Set your own permission mode (like chmod) instead of rwxr-xr-x.
-o,--owner= owner: Self-setting owner (for Superuser only).
-p,--preserve-timestamps: The time attribute of the file's access/modification time as the corresponding destination file.
-s,--strip: Remove the symbol table with the strip command only for the first and second use formats.
-s,--suffix= suffix: Specify the backup file yourself.
-v,--verbose: Prints the name when each file/directory is processed.
--help: Displays this help message and leaves.
--version: Displays the version information and leaves.
Mount
1. Role
The purpose of the Mount command is to load the file system with permissions that are allowed by superuser or/etc/fstab.
2. Format
mount-a [-FV] [-t vfstype] [-n] [-RW] [-f] Device dir
3. Main parameters
-H: Displays auxiliary information.
-V: Displays information, usually and-F for debugging.
-A: Hang all the file systems defined in the/etc/fstab.
- F: This command is usually used with-a, which generates a stroke for each mount action. The speed of loading can be accelerated when the system needs to hang a large number of NFS file systems.
-F: Usually used for debugging. It causes mount to not perform the actual hanging action, but instead simulates the entire hanging process, which is typically used with-V.
-T Vfstype: Displays the type of file system being loaded.
-N: In general, Mount hangs on the/etc/mtab to write a piece of information, in the system does not have a writable file system, you can use this option to cancel this action.
4. Application Tips
on Linux and UNIX systems, all files are accessed as part of a large tree (or root). To access files on a CD-ROM, you need to attach a CD-ROM device to a hanging decoration in the file tree. If the distribution has an auto-mount package installed, this step can be done automatically. In Linux, if you want to use a hard disk, CD-ROM and other storage devices, you have to load it, when the storage device hangs, it can be used as a directory to access. Hang up a device using the Mount command. When using the Mount command, you need to know at least the following three kinds of information: The file system type to load the object, the name of the device to load the object, and the directory to load the device into.
(1) Linux recognizable file system
The FAT 32 file system commonly used in Windows 95/98: vfat;
the file system of Win nt/2000: ntfs;
os/2 file system: HPFS;
Linux File system: ext2, ext3;
file system for CD-ROM: iso9660.
Although VFAT refers to the FAT 32 system, it is also compatible with the Fat 16 file system type.
(2) Determine the name of the device
in Linux, the device name usually exists in/dev. The names of these devices are all rules, and you can use the "reasoning" method to find out the name of the device. For example,/dev/hda1 this IDE device, HD is hard disk (HDD), SD is SCSI DEVICE,FD is floppy device (or floppy disk?). A represents the first device, usually the IDE interface can connect to 4 IDE devices (such as 4 hard drives). So the way to identify the IDE hard disk is HDA, HDB, HDC, HDD. The "1" in hda1 represents the first hard disk partition (partition) of HDA, Hda2 represents the second primary partition of HDA, the first logical partition starts with HDA5, and so on. In addition, you can directly check the/var/log/messages file, in this file can find the computer after the system has been identified after the device code.
(3) Find Hang point
before deciding to hook up your device, check to see if your computer has an empty directory of/mnt, which is a directory dedicated to mount point. It is suggested to build several/mnt/cdrom,/mnt/floppy,/mnt/mo and other directories in/mnt, as the special mount point of the directory. For example, if you want to mount the following 5 devices, their execution instructions may be as follows (assuming all Linux ext2 systems, if Windows XX Please change ext2 to VFAT):
Floppy ===>mount-t Ext2/dev/fd0/mnt/floppy
cdrom ===>mount-t Iso9660/dev/hdc/mnt/cdrom
SCSI cdrom ===>mount-t iso9660/dev/sdb/mnt/scdrom
SCSI cdr ===>mount-t iso9660/dev/sdc/mnt/scdr
However, most newer Linux distributions (including Red Flag Linux, Medium Soft Linux, Mandrake Linux, etc.) can be automatically mounted on file systems, except Red Hat Linux.
Umount
1. Role
the role of the Umount command is to unload a file system that uses permissions that are allowed by superuser or/etc/fstab.
2. Format
unmount-a [-FFNRSVW] [-t vfstype] [-n] [-RW] [-f] Device dir
3. Instructions for use
The umount command is the inverse of the Mount command, and its parameters and usage are the same as the Mount command. After the Linux Mount CD-ROM, the CD-ROM is locked so that it cannot be ejected with the eject button on the CD-ROM panel. However, when the disc is no longer needed, if you have/cdrom as a symbolic link, use Umount/cdrom to uninstall it. The command succeeds only if no user is using the disc. This command includes a terminal window with the current working directory as the directory on the disc.
Chsh
1. Role
The purpose of the CHSH command is to change the user shell settings, which are used by all users.
2. Format
Chsh [-S] [-list] [--help] [-v] [username]
3. Main parameters
-L: Displays all shell types of the system.
-V: Displays the shell version number.
4. Application Tips
There are a variety of shells under Linux, usually the default is bash, if you want to change the shell type you can use the CHSH command. Enter the account password first, then enter the new shell type, and if the operation is correct the system will show "Shell change". The interface is generally as follows:
changing fihanging shell for Cao
Password:
New Shell [/bin/bash]:/bin/tcsh
in the above code, [] is the shell currently in use. Ordinary users can only modify their own shell, the super-user may modify the entire user's shell. To query which shells the system provides, you can use the Chsh-l command, as shown in Figure 1.
Figure 1 Shell types that the system can use
as can be seen from Figure 1, the author of the system can be used in the shell has bash (default), CSH, SH, tcsh four kinds.
Exit
1. Role
the function of the Exit command is to exit the system, and its use rights are all users.
2. Format
Exit
3. Parameters
the Exit command has no parameters and exits the system after running to enter the login screen.
Last
1. Role
the last command is used to show the recent user or terminal logon situation, and its use rights are all users. Using the last command to view the log of the program, the administrator can tell who has or attempted to connect to the system.
2. Format
1ast[-n][-f file][-t TTY] [-H node][-i-ip][-1][-y][1d]
3. Main parameters
-N: Specifies the number of bars for the output record.
-F File: Specifies the log file used as the query for the file.
-T TTY: Displays only the specified Virtual Console login status.
- H node: Displays only the logon status on the specified node.
-I IP: Displays only the cases where the specified IP is logged on.
-1: Use IP to display the remote address.
-y: Displays the year, month, and day of the record.
-id: Knows the user name of the query.
-X: Shows the history of system shutdown, user login, and exit.
hands -on exercises
The Linux installation and login commands are described above, and here are a few examples of how to practice the commands you just talked about.
1. Run multiple commands at once
you can execute multiple commands on a single command line, separating the commands with semicolons, for example:
#last-x;halt
The above code indicates that the computer is turned off after displaying the system shutdown, user logon, and exit history.
2. Accessing the Windows system with Mount Mount file system
Many Linux distributions can now automatically load VFAT partitions to access Windows systems, and Red Hat versions do not automatically load VFAT partitions, so manual action is required.
Mount can attach the Windows partition to an empty folder in Linux as a "file" of Linux, linking the Windows partition to the/MNT directory. As a result, accessing this folder is equivalent to accessing the partition. First, create the Winc folder under/mnt and enter the following command at the command prompt:
#mount-t vfat/dev/hda1/mnt/winc
This means that the C partition of Windows is attached to the Liunx/mnt/winc directory. In this case, you can see the contents of the C drive in Windows in the/mnt/winc directory. Use a similar method to access the D, E drives of the Windows system. The Linux system displays the Windows partition in general order such as: Hda1 for C, Hda5 for D, Hda6 for E drive ... And so on The above method can view the Windows system has a big problem, that is, all the Chinese file name or folder name in Windows is all displayed as a question mark "? , while English can be displayed normally. We can make it appear in Chinese by adding some parameters. Also take the above action as an example, enter the command at this time:
#mount-t vfat-o iocharset=cp936/dev/hda1/mnt/winc
now it can display Chinese as normal.
3. Using the file system on Mount Plus on the flash drive
using a flash drive under Linux is very simple. Linux has a good support for USB devices, and when the flash drive is inserted, the flash drive is recognized as a SCSI disk, usually by entering the following command:
# Mount/dev/sda1/usb
will be able to attach the file system on the flash drive. ()
Linux Common Commands