Common Linux commands

Source: Internet
Author: User

Su
The su command is one of the most basic commands and is often used for switching between different users. For example, to switch to user2 if user1 is logged on, use the following command:
$ Su user2
Then the system prompts you to enter the user2 password. after entering the correct password, you can switch to user2. After that, you can use the exit command to return to user1.
The common usage of the su command is to become the root user or Super User. If the su command without the user name is issued, the system prompts you to enter the root password. after entering the root password, you can switch to the root user.
If you log on as the root user, you can use the su command to become any user on the system without a password.

PWD
The PWD command is also one of the most common and basic commands used to display the current directory of the user.

CD
The CD command not only displays the current status, but also changes the current status. It is basically the same as the CD command in DOS.
CD .. you can enter the directory on the previous Layer
CD-enter the previous directory
Cd ~ You can access the user's home directory

Ls
Like the Dir command in DOS, the LS command is used to display the content of the current directory.
If you want to obtain detailed information, you can use the LS-l command to display detailed information about the directory content.
If the directory contains too many files and cannot be displayed on one screen, use LS-L | more split screen.

Find
The find command is used to find files. This command can be searched by file name, creation or modification date, owner (usually the user who creates the file), file length, or file type.
The basic structure of the find command is as follows:
$ Find
Specify the directory from which to start searching. Specify search criteria. Indicates how to locate the file. Generally, use the-print action to display the path and name of the entire file. If this action is not performed, the find Command performs the search without displaying the result.
For example, to search for all files named Ye on the system, run the following command:
$ Find/-name ye-print
In this way, all files named Ye can be displayed.

Tar
Tar was originally used to create a tape backup system and is currently widely used to create file publishing files. You can use the following method to create a tar file:
$ Tar CVF
For example, to save all files in the current directory to ye.tar, run the following command:
$ Tar CVF ye.tar *.*
To browse the file content, change the C option to T. To view the content in the ye.tar file, run the following command:
$ Tar tvf ye.tar
To retrieve the content in the file, convert the C option to X. To retrieve the content in the ye.tar file to the current directory, run the following command:
$ Tar xvf ye.tar

Gzip
The gzip command is used to compress files. For example, to compress the ye.txt file, run the following command:
$ Gzip ye.txt
In this example, you can compress the file and add a gzextension name after the file name to convert it into a file ye.txt.gz.
Decompress the file using the gzip-D command:
$ Gzip-D ye.txt.gz
In this way, you can decompress the file and delete the GZ extension. In addition, you can use the gunzip command to decompress the file. The effect is the same as that of the gzip-D command.
The old tar command does not compress files and can be compressed using gzip. For example:
$ Tar CVF ye.tar *. txt
$ Gzip ye.tar
You can create a compressed file ye.tar.gz.
The new version of tar can directly access and create gzip compressed tar files, as long as you add the Z option in the tar command. For example:
$ Tar czvf ye.tar *. txt
Generated archives ye.tar.gz,
$ Tar tzvf ye.tar *. txt
Displays the content of the compressed file ye.tar.gz, while
$ Tar xzvf ye.tar *. txt
Obtain the content of the compressed file ye.tar.gz.

Mkdir
This command is very simple. It is used almost the same as the dos md command to create a directory.

CP
The CP command is used to copy files or directories.
The CP command can copy multiple files at a time, for example:
$ Cp *. txt *. Doc *. bak/home
Copy all the files with the extension txt, Doc, and Bak in the current directory to the/home directory.
To copy the entire directory and all its subdirectories, run the CP-R command.

Rm
The RM command is used to delete files or directories.
The RM command forcibly deletes the file. If you want to confirm the deletion, run the RM-I command.
To delete a directory, run the RM-R command. When the RM-R command deletes a directory, a prompt is displayed for each file or directory to be deleted. If the directory is too large, it is unrealistic to respond to each prompt. In this case, you can use the RM-RF command to forcibly Delete the directory. In this case, the-I flag is used and the process is invalid.

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 a time.

Reboot

 

◆ Installation and logon commands: Login, shutdown, halt, reboot, install, mount, umount, CHSH, exit, and last;

◆ File processing commands: file, mkdir, grep, DD, find, MV, ls, diff, Cat, ln;

◆ System management commands: DF, top, free, quota, AT, LP, adduser, groupadd, kill, and crontab;

◆ Network operation commands: ifconfig, IP, ping, netstat, telnet, FTP, route, rlogin, RCP, finger, mail, and NSLookup;

◆ System security related commands: passwd, Su, umask, chgrp, chmod, chown, chattr, sudo ps, WHO;

◆ Other commands: Tar, unzip, gunzip, unarj, mtools, man, unendcode, and uudecode.

This document uses Mandrake Linux 9.1 (kenrel 2.4.21) as an example to introduce the installation and logon commands in Linux.

Login

1. Role

Login is used to log on to the system and has the permission to all users.

2. Format

Login [name] [-p] [-H host name]

3. Main Parameters

-P: notifies login to retain the current environment parameters.

-H: used to transmit user names between remote logins.

If you choose to log on to Linux in command line mode, the first Linux Command is login :.

The general interface is as follows:

Manddrake Linux release 9.1 (bamboo) for i586
Renrel 2.4.21-0.13mdk on i686/tty1
Localhost login: Root
Password:

AboveCodeIn, the first line is the Linux release version, the second line is the kernel version and the virtual console that is logged on, we enter the login name in the third line, press "enter" and enter the account password after the password, you can log on to the system. For security reasons, the characters are not displayed on the screen when the account password is entered, and the cursor is not moved.

After logging on, you will see the following interface (taking the Super User as an example ):

[Root @ localhost root] #
Last login: Tue, Nov 18 10:00:55 on VC/1

The preceding figure shows the logon day, month, day, and time, and the virtual console used.

4. Application Skills

Linux is a real multi-user operating system that allows multiple users to log on simultaneously and allows one user to log on multiple times. This is because Linux, like many versions of UNIX, provides access to the virtual console, allowing users to access the console at the same time (the system console is a monitor and keyboard directly connected to the system) log on multiple times. Each virtual console can be seen as an independent workstation, and can be switched between workstations. The switchover of the virtual console can be done by pressing the Alt key and a function key, typically using a F1-F6.

For example, after a user logs on, press the "Alt + F2" key and the user will see the "login:" prompt above, indicating that the user has seen the second virtual console. Then, press the "Alt + F1" key to return to the first virtual console. A newly installed Linux system allows you to use the Alt + F1 key to access the first six virtual consoles. The most useful thing about the virtual console is that whenProgramWhen an error causes a system deadlock, you can switch to another virtual console to close this program.

Shutdown

1. Role

The shutdown command is used to shut down the computer and its permission is a Super User.

2. Format

Shutdown [-H] [-I] [-K] [-M] [-T]

3. Important Parameters

-T: Tell the INIT program how long it will shut down before it changes to another running level.

-K: it does not actually shut down, but only sends a warning signal to each worker.

-H: power off after shutdown.

-C: Cancel current process cancels the currently executing Shutdown program. Therefore, this option certainly does not have a time parameter, but you can enter a message for explanation, and this information will be sent to each user.

-F: Forces The fsck to restart the computer.

-Time: set the time before shutdown.

-M: Change the system to single-user mode.

-I: The system information is displayed when the instance is shut down.

4. Command description

The shutdown command can safely shut down the system. It is very dangerous for some users to shut down the Linux system by directly disconnecting the power supply. Because Linux and Windows run many processes in the background, forced shutdown may lead to data loss in the process and make the system unstable, in some systems, hardware devices (hard disks) are damaged ). Use the shutdown command before shutting down the system. The system administrator will notify all logged-on users that the system is about to shut down and the LOGIN Command will be frozen. That is, new users cannot log on again.

Halt

1. Role

The role of the halt command is to shut down the system, and its permission is super user.

2. Format

Halt [-N] [-W] [-D] [-F] [-I] [-p]

3. Description of main parameters

-N: prevents the sync system from calling. It is used after the root partition is repaired with fsck to prevent the kernel from overwriting the repaired super block with the old version.

-W: Not a real restart or shutdown, but a wtmp (/var/log/wtmp) record.

-F: forced shutdown or restart without calling shutdown.

-I: Shut down all network interfaces before shutting down (or restarting.

-F: Force Shutdown without calling the shutdown command.

-P: when the power is turned off, the power is turned off by the way.

-D: Shut down the system, but no record is left.

4. Command description

Halt is to call shutdown-H. When halt is executed, the application process is killed and the system call is executed by executing sync (forcibly writing data stored in the buffer to the hard disk). After the file system write operation is completed, the kernel is stopped. If the system running level is 0 or 6, the system is shut down; otherwise, the shutdown command (with the-h Parameter added) is replaced.

Reboot

1. Role

The reboot command is used to restart the computer. Its permission is assigned to the system administrator.

2. Format

Reboot [-N] [-W] [-D] [-F] [-I]

3. Main Parameters

-N: Do not write the memory data back to the hard disk before restarting the instance.

-W: The record is not written to the/var/log/wtmp file.

-D: Do not write the record to the/var/log/wtmp file (the-n parameter contains-D ).

-I: Stop all network-related devices before restarting.

Install

1. Role

The Install command is used to install or upgrade software or back up data. Its permission is granted to all users.

2. Format

(1) install [Options]... source destination

(2) install [Options]... source... directory

(3) install-d [Option]... directory...

In the first two formats, <source> copy to <destination> or copy multiple <source> files to an existing <directory>, set the permission mode and owner/group. In the third format, all specified directories and their home directories are created. Long Options are required when short options are used.

3. Main Parameters

-- Backup [= control]: backs up 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 directories in the specified directory are created.

-D: create all the Home Directories Before <destination> and copy <source> to <destination>. This is useful in the first format.

-G, -- group = group: Set the group to which the process belongs, rather than the current group to which the process belongs.

-M, -- mode = mode: Set the permission mode (such as chmod), instead of rwxr-XR-X.

-O, -- owner = owner: Set the owner (applies to Super Users only ).

-P, -- preserve-timestamps: Use the <source> File Access/modification time as the time attribute of the corresponding destination file.

-S, -- Strip: Use the Strip command to delete the symbol table, only applicable to the first and second formats.

-S, -- suffix = Suffix: Specifies the <suffix> of the backup file.

-V, -- verbose: The name is printed when processing each file/directory.

-- Help: displays the help information and leaves.

-- Version: displays the version information and leaves.

Mount

1. Role

The mount command is used to load the file system. Its permission is granted to a Super User or a user allowed in/etc/fstab.

2. Format

Mount-A [-FV] [-T vfstype] [-N] [-RW] [-F] device dir

3. Main Parameters

-H: displays the auxiliary information.

-V: display information, usually used with-F for debugging.

-A: Mount all file systems defined in/etc/fstab.

-F: this command is usually used with-a, which generates a route for each Mount action. It can speed up loading when the system needs to mount a large number of NFS file systems.

-F: usually used for debugging. It causes mount to not execute the actual mounting action, but simulate the entire mounting process, which is usually used together with-v.

-T vfstype: displays the type of the file system to be loaded.

-N: In general, after Mount is mounted, a piece of data will be written to the/etc/mtab. You can use this option to cancel this operation if the system does not have the file system to write data.

4. Application Skills

On Linux and Unix systems, all files are accessed as part of a large tree (with/as the root. To access files on a CD-ROM, You need to mount the CD-ROM device to a mount point in the file tree. If the release version is installed with an automatic mounting package, this step can be performed automatically. In Linux, if you want to use storage devices such as hard disks and optical drives, you must load them first. After the storage devices are mounted, you can use them as a directory for access. Mount a device and run the mount command. When using the mount command, you must first know the following three types of information: file system type of the object to be loaded, device name of the object to be loaded, and directory to which the device is to be loaded.

(1) recognizable file systems in Linux

◆ Windows 95/98 common FAT 32 File System: vfat;

◆ Win NT/2000 File System: NTFS;

◆ OS/2 File System: HPFs;

◆ Linux File Systems: ext2 and ext3;

◆ CD-ROM disc File System: iso9660.

Although vfat is a FAT 32 system, it is actually compatible with the file system type of fat 16.

(2) determine the device name

In Linux, device names are usually stored in/dev. These device names are named in a regular way. You can use the "inference" method to find the device names. For example, the/dev/hda1 ide device, HD is hard disk, SD is SCSI device, FD is floppy device (or floppy disk ?). A Indicates the first device. Generally, the IDE interface can be connected to four ide devices (such as four hard disks ). Therefore, the methods to identify IDE Hard Disks are hda, HDB, HDC, and HDD. In hda1, "1" indicates the first hard disk partition of hda, hda2 indicates the second primary partition of hda, and the first logical partition starts from hda5. In addition, you can directly check the/var/log/messages file to find the device code identified by the system after the computer is started.

(3) Find the mount point

Before deciding to connect a device, check whether the computer has an empty/mnt Directory, which is used as a mount point directory. We recommend that you create several/mnt/CDROM,/mnt/floppy,/mnt/Mo directories in/mnt as dedicated mount points for the directories. For example, if you want to mount the following five devices, the execution command may be as follows (assuming that all are Linux ext2 systems, and if it is Windows XX, change ext2 to vfat ):

Floppy Disk ==> Mount-T ext2/dev/fd0/mnt/floppy
CDROM ==> Mount-T iso9660/dev/HDC/mnt/CDROM
Scsi cdrom ==> Mount-T iso9660/dev/sdb/mnt/content Rom
Scsi cdr ==> Mount-T iso9660/dev/SDC/mnt/scdr

However, most of the latest Linux releases (including Red Flag Linux, mid-soft Linux, and Mandrake Linux) can automatically mount the file system, except Red Hat Linux.

Umount

1. Role

The umount command is used to uninstall a file system. Its permission is granted to a Super User or a user allowed in/etc/fstab.

2. Format

Unmount-A [-ffnrsvw] [-T vfstype] [-N] [-RW] [-F] device dir

3. Instructions for use

The umount command is the inverse operation of the mount command. Its Parameters and usage are the same as those of the mount command. After the Linux mounted CD-ROM, The CD-ROM is locked so that it cannot be popped up with the eject button on the CD-ROM panel. However, if you no longer need a CD, use umount/CDROM to uninstall it if you have used/CDROM as a symbolic link. This command is successful only when no user is using the CD. This command includes a terminal window that uses the current working directory as the directory in the CD.

CHSH

1. Role

The CHSH command is used to change the User Shell settings, and its permission is for 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 Skills

We have introduced a variety of shells in Linux. The default is Bash. To change the shell type, you can use the CHSH command. Enter the account password and the new shell type. If the operation is correct, "shell change" is displayed ". The interface is generally as follows:

Changing fihanging shell for Cao
Password:
New shell [/bin/bash]:/bin/tcsh

In the above Code, the current shell is used in. Normal users can only modify their own shells. Super Users can modify the shells of all users. To query which shells are provided, run the CHSH-l command, as shown in figure 1.

Figure 1 shell types available for the System

As shown in figure 1, the shell that can be used in my system includes bash (default), CSH, sh, and tcsh.

Exit

1. Role

The exit command exits the system and has the permission to all users.

2. Format

Exit

3. Parameters

The exit command has no parameters. After running the command, exit the system and enter the logon interface.

Last

1. Role

The last command is used to display the logon status of recent users or terminals. Its permission is granted to all users. Run the last command to view the log of the program. The administrator can find out who has tried 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: Number of output records.

-F file: specifies that the file is used as the log file for query.

-T tty: only the logon status on the specified virtual console is displayed.

-H node: only the logon status on the specified node is displayed.

-I IP: only the logon status on the specified IP address is displayed.

-1: use an IP address to display the remote address.

-Y: displays the year, month, and day of the record.

-ID: the user name to be queried.

-X: displays the system shutdown, user logon, and logout history.

Hands-on exercises

The above describes the Linux installation and logon commands. The following describes several instances and describes how to practice the commands just mentioned.

1. run multiple commands at a time

You can execute multiple commands in one command line and separate them with semicolons. For example:

# Last-X; halt

The code above indicates that the computer is disabled after the system is disabled, user logon, and logout history are displayed.

2. Use Mount mounted file system to access windows

Many Linux versions can now automatically load vfat partitions to access the Windows system, while Red Hat versions do not automatically load vfat partitions. Therefore, manual operations are required.

Mount can be used to mount a Windows partition as a "file" of Linux to an empty folder in Linux to associate the Windows partition with the/mnt directory. Therefore, accessing this folder is equivalent to accessing this partition. First, create a winc folder under/mnt and enter the following command at the command prompt:

# Mount-T vfat/dev/hda1/mnt/winc

That is, the Windows C partition is mounted to the/mnt/winc directory of liunx. In this case, the content of drive C in Windows is displayed in the/mnt/winc directory. You can use a similar method to access D and E disks in windows. In Linux, Windows partitions are displayed in the following sequence: hda1 is drive C, hda5 is drive D, hda6 is drive E ...... And so on. In the above method, we can see that there is a big problem in windows, that is, all Chinese file names or folder names in windows are displayed as question marks "?". English is displayed normally. We can add some parameters to display Chinese characters. For example, enter the following command:

# Mount-T vfat-O iocharset = cp936/dev/hda1/mnt/winc

Now it can display Chinese characters normally.

3. Mount the file system on the flash disk with Mount

Using flash disks in Linux is very simple. Linux has good support for USB devices. After a flash disk is inserted, the flash disk is recognized as a SCSI disk. Generally, run the following command:

# Mount/dev/sda1/USB

You can mount the file system on the flash disk.

Knowledge

Linux commands and Shell

Shell is a command-interpreted program. It provides an interface for programming. Learning shell is very important for Linux beginners to understand the Linux system. As the operating system shell, the Linux system shell provides users with an interface to use the operating system. Shell is a general term for the command language, command interpreter program, and programming language. It is an interface program between the user and the Linux kernel. If you think of the Linux kernel as the center of a sphere, shell is the outer layer around the kernel. When commands are passed from shell or other programs to Linux, the kernel will respond accordingly. Shell is similar to command. com in ms dos and cmder.exe in Windows 95/98 in Linux. Although shell is not a part of the system core, it is only an extension of the system core, but it can call most of the functions of the system kernel. Therefore, shell is the most important utility in unux/Linux.

There are multiple types of Shell in Linux. The most common types are Bourne shell (SH), c shell (CSH), and Korn shell (Ksh ). The default shell of most Linux releases is the Bourne again shell, which is an extension of the Bourne shell, bash for short. It is completely backward compatible with the Bourne shell and adds many features based on the Bourne shell. Bash is placed in/bin/bash and provides functions such as command completion, command editing, and command history table. It also contains many advantages of C shell and Korn shell, flexible and powerful programming interfaces, and friendly user interfaces. In Linux, 40 of the more than 200 commands are Bash Internal commands, including exit, less, LP, kill, CD, PWD, FC, FG, etc.

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.