Summary of 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-- Print Working Directory

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

Displays the path name of the working directory. Syntax pwd [-L |-P]

Description

The pwd commandCurrent DirectoryWrite the full path name (from the root directory) to the standard output. All directories are separated by slash. The first/indicates the root directory, and the last directory is the current directory.

Flag

-L

If the PWD environment variable contains the absolute path name of the current directory that does not contain the file name. (DOT) or. (DOT), the value of the PWD environment variable is displayed. Otherwise, the-L flag runs like the-P Flag.

-P

Displays the absolute path name of the current directory. The absolute path displayed with the-P Flag does not include the name of the file involving the symbolic link type in the absolute path of the path name.

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 previous directory cd-you can enter the previous directory

Cd ~ You can access the user's home directory

Ls(List displays files and directories in the current directory. ls-l detailed display = ll)

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.

Ls
[Root @ linux ~] # Ls [-aAdfFhilRS] Directory Name
[Root @ linux ~] # Ls [-- color = {none, auto, always}] Directory Name
[Root @ linux ~] # Ls [-- full-time] Directory Name
Parameters:
-A: All files are listed together with hidden files (Files starting ~
-A: All files, together with hidden files, are listed together, but do not include the two directories "." and ~
-D: only list the directory itself, not the archive data in the directory.
-F: directly list the results without sorting them (ls is sorted by file name by default !)
-F: attaches a Data Structure Based on files, directories, and other information, for example:
*: Indicates the executable file;/: indicates the Directory; =: indicates the socket file; |: indicates the FIFO file;
-H: lists the file capacity in a readable manner (such as GB and KB;
-I: List inode locations, not archive attributes;
-L: Serial Output of long data, including the attributes of files and other data;
-N: List UID and GID, rather than the names of users and groups (UID and GID will be mentioned in account management !)
-R: reversely outputs the sorting result. For example, if the original file name is from small to large, the reverse file is from large to small;
-R: It is listed together with the sub-directory content;
-S: sort by file capacity!
-T: sort by Time
-- Color = never: do not display the color based on the file features;
-- Color = always: Display color
-- Color = auto: allows the system to determine whether to give color based on the settings.
-- Full-time: Output in full time mode (including year, month, day, hour, and minute)
-- Time = {atime, ctime}: Output access time or change permission attribute time (ctime)
Instead of the content change time (modification time)

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 to display all the files named ye on the system.

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, if you want to save all files in the current directory to ye.tar,

Run the following command: $ tar cvf ye.tar *. * to view 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 by running the gzip-d command: $ gzip-d ye.txt.gz to 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 can be used to 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 generates the archives ye.tar.gz and $ tar tzvf ye.tar *. txt displays the contents of the archives ye.tar.gz, while $ tar xzvf ye.tar *. txt extracts the contents of the archives 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. 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.

Cat

Displays the file content starting from the first line.
[Root @ linux ~] # Cat [-AEnTv]
Parameters:
-A: equivalent to the Integration parameter of-vET. It can list some special characters ~
-E: The ending line break character $ is displayed;
-N: print the travel number;
-T: Click the [tab] button to display it with ^ I;
-V: list special characters that cannot be seen
Tac

From the last line, we can see that tac is a cat inverted write!
When nl is displayed, the line number is output!

Touch

Create an empty archive and revise the archive date to the current (mtime and atime)
[Root @ linux ~] # Touch [-acdmt] Archives
Parameters:
-A: only modify access time;
-C: only modify the time without creating an archive;
-D: Followed by a date, or -- date = "date or time"
-M: only modify mtime;
-T: Followed by a time in the format of [YYMMDDhhmm]

Vi

Vi file2 (new file file2 by vi compiler)
(Press I to enter the insert status, that is, insert mode. Press Esc to exit insert mode. In non-insert mode, press dd to delete the current row of the cursor, Press x to delete the current word, and press j, n, l move the cursor)
: Wq (save and quit): q! (Exit without saving)

MoreDisplay file content on one page
Space): Indicates turning a page down;
Enter:Indicates turning a line down 』;
/String:Searches for the "string" in the displayed content 』;
: F: The file name and the number of currently displayed rows are displayed immediately;

Q: The archive content is no longer displayed when you leave more immediately.

Clear
Purpose: Clear the screen.
Usage: enter clear on the console.

Write
Permission: All Users
Usage: write user [ttyname]
Description: transmits messages to other users.
Calculation:
User: the user account for which the message is to be sent
Ttyname: if the user has more than two tty connections at the same time, you can select a suitable tty to send messages.
Example. 1:
Send a message to Rollaend. At this time, Rollaend has only one line:
Write Rollaend

Sleep
Permission: All Users
Usage: sleep [-- help] [-- version] number [smhd]

Note: sleep can be used to delay the current action for a period of time.
Parameter description:
-- Help: displays auxiliary messages.
-- Version: displays the version number.
Number: the length of time. It can be followed by s, m, h, or d.
S indicates the second, m indicates the minute, h indicates the hour, and d indicates the number of days.
Example:
Display the current time after 1 minute delay, and then display the time again:
Date; sleep 1 m; date

Reboot

Restart command. Needless to say.

HaltShutdown command. Needless to say.

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.