LINUX Common Command Set

Source: Internet
Author: User

LINUX Common Command Set

This is my study of Linux online search information, basically from the online resources or other people's blog, now can not find the source, if anyone found its source, please notify me,

I must attach the link.

Su
The SU command is one of the most basic commands and is commonly used for switching between different users. For example, if you are logged in as User1, to switch to User2, simply use the following command:
$su User2
Then you are prompted to enter the User2 password and you can switch to User2 after you enter the correct password. Once finished, you can return to User1 with the Exit command.
A common use of the SU command is to become a root user or superuser. If you issue a su command without a user name, you are prompted for the root password, and you can switch to the root user after you enter it.
If you are logged on as the root user, you can use the SU command to become any user on the system without requiring a password.

Pwd
The PWD command is also one of the most common and basic commands used to display the directory where the user is currently located.

Cd
The CD command not only shows the current status, but also changes the current state, which is basically consistent with the CD command under DOS.
Cd.. Access to the previous level directory
CD-access to the previous entry directory
CD ~ Access to user's home directory

Ls
The LS command, like the dir command under DOS, is used to display the contents of the current directory.
If you want to get detailed information, you can use the Ls-l command, which allows you to display detailed information about the contents of the directory.
If there are too many files in the directory, with one screen can not be displayed with Ls-l |more split screen display.

Find
The Find command is used to locate files. This command can be searched by file name, date created or modified, owner (usually the user who created the file), file length, or file type.
The basic structure of the Find command is as follows:
$find
Where you specify the directory from which to start the search. Specifies the search criteria. Indicates what to do with the found file. In general, use the-print action to display the entire file path and name. Without this action, the Find command does the search without displaying the result, which equals white effort.
For example, to search for all files on the system named Ye, use the following command:
$find/-name Ye-print
This will show all the files named Ye on the system.

Tar
Tar was originally used to establish a tape backup system and is now widely used to create file release files. You can use the following methods to create a tar archive:
$tar CVF
For example, if you want to archive all the files in the current directory to Ye.tar, you can use the following command:
$tar CVF Ye.tar * *
To browse the contents of the archive, change the C option to T. If you want to browse the contents of the Ye.tar archive, you can use the following command:
$tar TVF Ye.tar
To remove the contents of the file, change the C option to X. If you want to take the contents of the Ye.tar archive to the current directory, you can use the following command:
$tar XVF Ye.tar

Gzip
The gzip command is used to compress files. For example, if you want to compress the Ye.txt file, you can use the following command:
$gzip Ye.txt
This allows the file to be compressed and the GZ extension appended to the file name to become the ye.txt.gz.
The unzip file can be implemented using the GZIP-D command:
$gzip-D ye.txt.gz
This will extract the files and delete the GZ extension. In addition, you can use the Gunzip command to extract the file, the effect is the same as with the gzip-d command.
The previous version of the TAR command does not compress the archive and can be compressed with gzip. For example:
$tar CVF Ye.tar *.txt
$gzip Ye.tar
The compressed file ye.tar.gz can be established.
The new version of TAR allows direct access to and creation of gzip compressed tar files, as long as the z option is added to the tar command. For example:
$tar CZVF Ye.tar *.txt
Generate compressed archive ye.tar.gz,
$tar TZVF Ye.tar *.txt
Displays the contents of the compressed archive ye.tar.gz, while
$tar XZVF Ye.tar *.txt
Remove the contents of the compressed archive ye.tar.gz.

Mkdir
This command is simple, almost the same as DOS command usage, used to create a directory.

Cp
The CP command is used to copy files or directories.
The CP command can replicate multiple files at once, for example:
$CP *.txt *.doc *.bak/home
Copies all files in the current directory with the extension txt, doc, and Bak to the/home directory.
If you want to copy the entire directory and all of its subdirectories, you can use the Cp-r command.

Rm
The RM command is used to delete files or directories.
The RM command forces the file to be deleted, and if you want to prompt for confirmation on deletion, the Rm-i command is available.
If you want to delete a directory, the Rm-r command is available. Rm-r command when deleting a directory, each deletion of a file or directory will show a prompt, if the directory is too large, response to each prompt is unrealistic. You can then use the RM-RF command to force the deletion of the directory, so that even with the-I flag when invalid processing.

Mv
The MV command is used to move files and rename files. For example:
$MV Ye.txt/home
Move the Ye.txt file under the current directory to the/home directory,
$MV Ye.txt Ye1.txt
Rename the Ye.txt file to Ye1.txt.
Similar to the CP command, the MV command can also move multiple files at once, which is no longer redundant.

Reboot

Installation and Login commands: Login, shutdown, halt, reboot, install, mount, Umount, Chsh, exit, last;

Document processing commands: File, mkdir, grep, DD, find, MV, LS, diff, Cat, ln;

System Management Related commands: DF, top, free, quota, at, LP, AddUser, Groupadd, Kill, crontab;

Network operation 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.

This article takes Mandrake Linux 9.1 (Kenrel 2.4.21) as an example to introduce the installation and login commands under Linux.

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 just press the "ALT+F1" key and you can 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

2. Use

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: Changes 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-on users that the system is about to close, and the login command is frozen, that is, the new user can no longer log on.

Halt

2. Use

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. The halt executes, kills the application process, executes the system call of sync (which forces data stored in buffer to the hard disk), and stops the kernel after the file system writes are 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

2. Use

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

2. Use

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... Directory

(3) install-d [options] ... Directory...

In the first two formats, the < source > is copied to < destination > or multiple < source > files are copied to the existing < directory, and both the permission mode and the owner/owning group are set. 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: Create all home directories < destinations >, and then copy < source > to < destinations >; 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 corresponding destination file with the access/modification time of the < source > file.

-s,--strip: Remove the symbol table with the strip command only for the first and second use formats.

-s,--suffix= suffix: Specify the < suffix > for 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

2. Use

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 file systems defined in/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

2. Use

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

2. Use

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 one 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.

Small knowledge

Linux command and Shell

The so-called Shell is the command interpreter, which provides programming interfaces that can be programmed using programs. Learning the shell is very important for Linux beginners to understand Linux systems. The shell of the Linux system, as the shell of the operating system, provides the user with an interface to use the operating system. Shell is the general term of command Language, command interpreter and programming language, and it is the interface program between user and Linux kernel. If you think of the Linux kernel as the center of a sphere, the shell is around the outer layer of the kernel. When a command is passed to Linux from a shell or other program, the kernel responds accordingly. The role of the shell in Linux systems is similar to the Command.com of MS DOS and the Explorer.exe of Windows 95/98. While the shell is not part of the system core, it is only an extension of the system core, but it can invoke most of the functions of the system kernel. Therefore, it can be said that the shell is the Unux/linux most important utility program.

There are several types of shells in Linux, the most commonly used are the Bourne shell (SH), the C Shell (CSH), and the Korn shell (Ksh). The default shell for most Linux distributions is the Bourne Again Shell, which is an extension of the Bourne Shell, called Bash, completely backwards compatible with the Bourne shell, and adds a lot of features to the Bourne shell. Bash is placed in/bin/bash to provide functions such as command completion, command editing, and command history tables. It also contains many of the advantages of the C shell and Korn shell, with its flexible and powerful programming interface, while having a friendly user interface. More than 200 commands in the Linux system are the internal commands of bash, including exit, less, LP, Kill, CD, PWD, FC, FG, etc.

LINUX Common Command Set

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.