Operation and Maintenance Foundation--linux Basic command

Source: Internet
Author: User

Linux basic Commands

New to Linux, there will often be an impression that Linux operation than we are familiar with Windows difficult, it is not, as long as the understanding of the Linux CLI interface a lot of command usage can make many in the GUI interface operation becomes very simple The following are some of the basic commands used in Linux:

1.CD:

CD [-l|-p] [dir] changes the working directory of the Shell, which is the user's home directory by default;

CD dir: Switch to dir directory;

CD: Switch to the current user's home directory;

CD-: Switch The working directory to the working directory of the first time, and switch between two directories!

Principle: Two variables in the shell:

$PWD

$OLDPWD

CD ~: Switch working directory to home directory, root user can switch to the home directory of the specified normal user;

CD ~usrname;

2.PWD:

Displays the contents of the PWD variable, which displays the current directory; pwd [-LP]

3.ls:

Display directory contents (file name)

In the Linux file system, all with "." The starting file is called the hidden file;

Options:

-A: Displays except "." and ".." All files, including hidden files

-D: The contents of the directory are not displayed, only the directory name is displayed;

-l,--long: Displaying detailed property information for a file in a long format

/* For example: Drwxr-xr-x. 2 whj1 whj1 4096 Mar 4 14:15 Desktop

D: File type identification

Rwxr-xr-x: File Permissions

RWX: The owner of the document has the authority;

R-x: The permissions of the group of files;

R-x: The permissions that other users have on the file;

. : Indicates whether the file has a special attribute;

2: The number of times the file was hard-connected;

Whj1: The owner of the document;

WHJ1: an array of files;

4096: The size of the file;

Mar 4 14:15--The last time the file was modified;

Desktop: File name (filename does not belong to file's attribute information-metadata)

* All information except the file name is a property of the document;



Device Details:


8: The main device number (major) is used to identify the device type and to determine which driver to load;

0: The secondary device number (minor) is used to identify different devices of the same device type;


The device number uses a 8-bit binary representation, and the default indicates the range: 0-255;*/

-H: Easy to read file size format, 1024 binary conversion;

-f:--classify file type identification (/@*|=)

-r: Output results in alphabetical order

-r:--recursive recursively displays the contents of the directory and subdirectories (CTRL + C end process)

-S: Sort by file size display

-1: Show one file per line

-Z: Display the file's SELinux security context


Exit Status:

0:if OK, successful execution

1:if minor problems (e.g. cannot access subdirectory)

2:if serious problems (e.g. destination file or directory does not exist, etc.)

4.mkdir:

mkdir [opt] DIRECTORY ...

-P: When creating a directory, if the parent directory does not exist, it is created first;

-V: Displays the execution process of the command when executing the command;

5.rmdir:

Only empty directories can be deleted; options same as MkDir

6.RM: Removal of files or directories;

RM [opt] ... FILE ...

Options:

-I: Interactive deletion with the user;

-F: Forced deletion;

-r,-r: recursive delete directory;

7.touch:

The change file timestamps modifies the timestamp to make the files three times consistent.

touch [opt] ... FILE ...

8.stat:

Display file or file system status

Stat [opt] ... FILE ...

Access: Accessing Time

Modify: Modification time, changes in file content

Change: Metadata changes, changes in time

Options:

-C Format: Displays file specified properties in a specific format;

Example:%a,access rights in octal

9.nano:

Full Screen Editing Tool,

^ represents the CTRL key;

O: Save

X: Exit

......

10.cat:

Concatenate (connect) files and print on the standard output

Options:

-E: Displays the end of the hidden line ending with the "$" symbol;

-N: Line numbering for all rows;

-B: Row numbering for non-empty line content, that is, the line number of the blank line is not displayed;

-S: Merge multiple lines of blank behavior in one row;


Note: If there are no parameters, the operation is done by standard input, ctrl+d

11.TAC:

Concatenate and print files in reverse

is actually the reverse output of cat;

12.head:

Output the first part of the files

Options:

-C #[b|k|m|g]:

Displays the first # Characters of a file;

b:512byte;k:1024;

-N,--lines=[-]k

Displays the first n rows of the file, or it can be abbreviated as-#;

Note: The first 10 rows are displayed by default when no option is added, and less than 10 lines are all output;

13.tail:

Output the last part of the files

The options are almost the same as head:

-F: Real-time monitoring of file end changes; ^+c exit;

★ Pagination display content;

The More:man command shows the format of the blank page, carriage return;

More can only next page, can not turn back;

Less: Can page back

★ Date Time Related commands:

There are two of clocks:

Hardware clock: Hwclock,clock. Accurate to 1 microseconds

System clock: Date

Aa.

16.date [OPTION] ... [+format]

Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]

There are many ways to set up:

As date "031211012017.40"

Date-s "2017/10/10 10:10:10"

Format:

%F: date in full format;

%T: Time in full format;

%Y: Year;

%m: Month;

%d: day;

%hms: Hours, minutes, seconds, 1day 24h 1440m 86400s

%s: timestamp, the number of seconds elapsed from 1970-1-1 00:00:00 to the current system time;

......

17.hwclock:

-S,--hctosys:

Set the System time from the Hardware Clock.

Set the system clock as a reference to the hardware clock;

-W,--SYSTOHC

Set the Hardware Clock to the current System time.

Set the hardware clock as a reference to the system clock

--set--date "Time":

Set the hardware clock to "time";

18.cal: Display the calendar;

NTP server: Network Time protocol, error control in MS, automatic synchronization;


Shutdown command:

19.halt, Poweroff:

20.shutdown: More secure than the previous two;

Shutdown [OPTIONS ...] [TIME] [WALL ...]


Time:

Absolute time: 12:00;

Relative time: +#, executed after # minutes;

+0 equals now

Options:

-H: Shut down the system;

-R: Restart; (reboot);

-c;cancel a pending shutdown.

21. Log out and log out:

Exit: Unregister a shell

Logout: Quit a login shell.

22.CP:

Copy files and directories:

CP [OPTION] ... SOURCE DEST (Single source replication)

CP [OPTION] ... SOURCE ... DIRECTORY (Multi-source replication)

Single source copy can modify the file name;

Options:

-d Copy the symbolic link file itself, not the source file;

-P When copying files, can keep the file permissions, ownership and timestamp information;

-R, R: recursively copy directories and files in the directory;

A: equivalent to a combination of-DPR;


Note: The 1.CP command requires a minimum of two parameters;

2. Typically, the last parameter is the target of this copy behavior;

3. If a single source replication, the target can not exist, the target can be non-directory files;

4. If multi-source replication, the target must be a multi-source directory, and the process can not change the file name;

23.MV:

MV [OPTION] ... SOURCE DEST

MV [OPTION] ... SOURCE ... DIRECTORY


-F: Force overwrite the duplicate name file in the target location;

24.which:

Shows the full path of (shell) commands.

To view the path of an executable command

"Syntax" which COMMAND

"Options":

-a,--all: Displays all matching executables, not just the first one.

25.whatis:

Search the Whatis database for complete words

Find the complete command in the Whatis library

is an auxiliary command that assists the man with this help command

26.whereis:

Locate the binary, source, and manual page files for a command

Find relevant locations for files, manual pages, commands, etc.,

"Syntax" Whereis [options] Argument

Options

-B: Find only binary file locations

-M: Find the manual page section only

-S: Find only the source code section

27.W who whoami:

W-Shows the logged in user and the operation in progress

Who-show users who are already logged in

"Options":

-Q,--count displays all logins and logins

WHOAMI-Displays the user name when logging on to the system, even if the user has switched to another user who also displays the login

28.DU: report Disk space usage

POSIX Options

-A displays statistics for all files, not just subdirectories

-K with 1024 bytes as the counting unit

-X outputs only the actual usage space for the specified parameter, not the subdirectories below it

GNU Options

-A,--all

Show statistics on all files, not just subdirectories

-B,--bytes

Outputs the size in bytes, overriding the default 1024-byte count unit.


Operation and Maintenance Foundation--linux Basic command

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.