linux-Basics-Common commands

Source: Internet
Author: User
Tags parent directory readable

A brief introduction to Linux 1.1 Linux overview

Linux is a UNIX-based open source free operating system, because the stability and security of the system almost become the best system environment for program code to run. Linux was originally developed by Linus Torvalds (Linus Torvalds), which has now spawned hundreds of different Linux systems due to the openness of the source code.

The application of Linux system is very extensive, not only can run our program code for a long time, but also can be installed in various computer hardware devices, such as mobile phone, tablet computer, router, etc. In particular, as mentioned here, we are familiar with the bottom of the Android program is running on the Linux system.

1.2 Linux Categories

(1) Linux is divided into two directions depending on the market demand:

1) graphical interface version: Focus on user experience, similar to Windows operating system, but the current lack of maturity

2) Server version: There is no good-looking interface, is to enter the command in the console window operating system, similar to DOS, is we assume the best choice of server

(2) Linux is based on its native level and is divided into two types:

1) Kernel version: Kernel team under the leadership of Linus development of maintenance system kernel version number

2) Release: Some organizations or companies have two development and re-released versions based on the kernel edition

(3) Linux distributions are different and can be divided into N multiple:

Installation of the two Linux installations 2.1 virtual machines

Because Linux is also a system, in essence, the window of our computer is no different, so we have to learn Linux first to the Windows system of our computer into a Linux system, or to install a dual system on our computer, it sounds terrible. In fact, we can install a software on our computer, this soft armor can simulate one or more virtual computer machines, this is the virtual machine

There are two common types of virtual converters:


VMware's virtual machine software, powerful, premium products

Vitrualbox Virtual machine software Oracle company virtual machine software, free merchandise

Because VMware usage is high on the market, we install VMware VMware installation Manual

2.2 Installation of CentOS

CentOS is a Linux distribution, the main version of the current enterprise Application Server system, the installation of CentOS, in fact, the system is installed in the VMware virtual machine software, the VMware virtual machine software to simulate a Linux system computer. CentOS6.5 installation See "CentOS Installation Manual"

Three basic commands of Linux

Server version of the Linux installation is complete, but there is no graphical interface, we can only go through the console to the operating system, we will use a DOS command-like Linux command to go to the operating system, then we will be the Linux command to learn. Linux commands hundreds, courses can not be involved, there is no need one by one involved, according to our programmers in the daily work of the needs, summed up the following several for learning.

3.1 Directory Switching commands

A graphical interface and mouse can be used in window to arbitrarily switch directories that need to be entered, but Linux must switch directories via the CD command. But before we learn the CD command, we need to distinguish the directory structure of Linux (Linux directory structure detailed description)


CD usr switch to this directory in USR directory

Cd.. /switch to the previous level directory

CD/switch to the system root directory

CD ~ Switch to user home directory

CD-Switch to the previous directory

3.2 Operational commands for directories (additional deletions)

(1) Add directory operation (Increase)

Command: mkdir directory name

Example: in the root directory/under MkDir test, a test directory will be generated in the root directory


(2) View catalogue (check)

command: LS [-al] Parent Directory

Example: Using LS under the root directory, you can see all the directories and files in that directory

Example: Using ls-l under the root directory, you can see the details of all directories and files under that directory

Note: Ls-l can be abbreviated as LL

(3) Search catalogue (check)

Command: Find directory parameter

Example: Find the test-related directory (file) under/root find/root-name ' test* '

(3) Modify the name of the directory (change)

Command: MV directory name new directory name

Example: The test directory has a oldtest directory with the MV Oldtest newtest command to modify

(4) Location of mobile directory---cut (change)

Command: The new location of the MV Directory name directory

Example: Cut the Newtest directory below/usr under test, using MV NEWTEST/USR

NOTE: The MV syntax can not only cut the directory, but also perform cutting operations on files and compressed packets.

(5) Copy directory (change)

Command: Cp-r directory name directory copy target location-----R for recursive copy

Example: Copy the newtest under/usr to test in the root directory, using Cp-r/usr/newtest/test

Note: The CP command can not only copy directories but also copy files, compress packages and so on, copy files and compress packages without writing-R recursion

(6) Deleting a directory (delete)

Command: RM [-RF] Directory

Example: Delete the newtest under/usr and enter/usr with rm-r newtest

Example: Delete newtest under/test without asking for forced deletion, using RM-RF newtest under/test

Note: RM can not only delete directories, but also delete other files or compressed packages, in order to enhance the memory of everyone, regardless of the deletion of any directory or files, directly using the RM-RF directory/File/compression Package

3.3 Operation commands for files (add and revise)

(1) Creation of files (increase)

Command: Touch file name-----empty file

Example: Create an empty file under the test directory touch aaa.txt

(2) File view (check)

Command: Cat/more/less/tail file

Example: Using cat to view a/etc/sudo.conf file, only the last screen of content can be displayed

Example: Use more to view the/etc/sudo.conf file, you can display a percentage, the carriage return can be one line down, the space can be a page down, Q can exit view

Example: Using less to view the/etc/sudo.conf file, you can use the PgUp and PgDn on the keyboard to page up and down, Q end view

Example: Using TAIL-10 to view the following 10 lines of the/etc/sudo.conf file, CTRL + C ends

Note: The command tail-f file can dynamically monitor a file, such as Tomcat's log file, which will change as the program runs, and can use tail-f catalina-2016-11-11.log to monitor file changes

(3) Modify the contents of the file (change)

Command: Vim file

Example: Edit the Aaa.txt file under/test, using Vim aaa.txt

But this is not editable at this time, because in command mode, click on the keyboard i/a/o into the editing mode, you can

Edit File

When the edit is complete, press ESC to return to command mode

At this point, although the file has been edited, but not saved, you need to enter a colon: Enter the bottom row mode, enter WQ in the bottom line mode to write the content and exit, that is, save; input q! for force exit not saved

Summarize:

The VIM editor is a powerful component of Linux, a reinforced version of the VI editor, with a number of commands and shortcuts for the Vim editor, but not explained here.

There is no need to study very thoroughly, using vim to edit the way the file is basically used. Attached: "VI Introduction to the use of methods" and "Vim Command Collection"

About VIM Use process:

In practical development, the main function of using the VIM editor is to modify the configuration file

Vim file------> enter file-----> Command mode------> Press I to enter edit mode-----> Edit File-------> Press ESC to enter bottom line mode-----> Input: wq/q!

(4) Deletion of files (deleted)

Same directory Delete: memorize RM-RF files can

3.4 Operation commands for compressed files

(1) Packaging and compressing files

Packaged files in Linux generally end in. tar, and compressed commands typically end in. gz.

In general, packaging and compression are carried out together, packaged and compressed files with the suffix name. tar.gz.

Command: TAR-ZCVF Package compressed file name to package compressed files

Where: Z: Call the gzip compression command to compress

C: Packaging files

V: Show the running process

F: Specify file name

Example: Package and compress all files under/test compressed package with the specified name xxx.tar.gz

TAR-ZCVF xxx.tar.gz aaa.txt bbb.txt ccc.txt

Or: TAR-ZCVF xxx.tar.gz/test/*

(2) Decompression package (emphasis)

Command: Tar [-XVF] Compressed file

Where: x: Representative Decompression

Example: Extract the xxx.tar.gz under/test to the current directory

TAR-XVF xxx.tar.gz

Example: Extract the xxx.tar.gz under/test to the root directory/usr

TAR-XVF xxx.tar.gz-c/usr------C represents the location of the specified decompression

3.5 Other Commands

(1) Show current location

Pwd

(2) Search command

Command: grep to search for a string of files to search for

Example: Searching for a line in a/usr/sudu.conf file that contains a string to

Example: Search the/usr/sudu.conf file that contains the string to the line to highlight

(3) Piping command

Command: | Enter the output of the previous command as the current directory

Example: View a process that includes the system string in all processes in the current system

(4) View process

Command: PS-EF

Example: Viewing a process running in the current system

(5) Kill process

Command: PID of the kill-9 process

(6) network communication command

View network card information for the current system: ifconfig

To view a connection to a machine: ping

To view the port usage of the current system: Netstat-an

3.6 Permissions Command for Linux

Permissions are important concepts in Linux, each file/directory has permissions, and we can view the permissions of a file or directory under a directory through the ls-l command

Example: Ls-l in a random directory

The information for the first column is explained as follows:

Type of File:

D: Representative Directory

-: Representative file

L: Represents a link (can be considered a shortcut in window)

The following 9 bits are divided into 3 groups, each with 3 positions, each representing the owner's rights, the permissions of the user in the same group as the current user, and the permissions of the other users.

R: The delegate permission is readable, R can also be represented by the number 4

W: Delegate permission is writable, W can also be represented by the number 2

X: The delegate permission is executable, X can also be represented by the number 1

Type of File:

D: Representative Directory

-: Representative file

L: Represents a link (can be considered a shortcut in window)

The following 9 bits are divided into 3 groups, each with 3 positions, each representing the owner's rights, the permissions of the user in the same group as the current user, and the permissions of the other users.

R: The delegate permission is readable, R can also be represented by the number 4

W: Delegate permission is writable, W can also be represented by the number 2

X: The delegate permission is executable, X can also be represented by the number 1

Owner ( User )

Genus Group ( Group )

Other users

R

W

X

R

W

X

R

W

X

4

2

1

4

2

1

4

2

1

command to modify permissions for a file/directory: chmod

Example: Modify the permissions of the Aaa.txt under/test to have all permissions for the owner, the group that belongs to the host has read and write permissions,

Other users have read-only permissions

chmod u=rwx,g=rw,o=r Aaa.txt

The above example can also be represented using a number:

chmod 764 Aaa.txt

Use of the four remote connection tools

In the actual development, the Linux server is in other places, we want to connect the Linux through the remote way to operate it, the Linux remote Operation tool has many, the enterprise commonly used has puttty, SECURECRT, SSH secure and so on. We use the SSH secure tool for remote connection, which is a free graphical interface and a remote tool set in the command-line window. The installation package is as follows:

After installation, two icons will appear

Click the graphical interface icon

Enter the interface:

About the remote tool garbled solution:

When using remote Tools to connect, if Linux has a Chinese file or directory, the display will appear garbled, because the Linux encoding is UTF-8, and the remote tool by default is the current system local encoding is GBK. So the solution is to unify the two code is OK, but the SSH secure tool can not set the encoding, so by modifying the Linux system encoding method for uniform encoding.

In the Linux/etc/sysconfig directory there is a i18n file that represents the Linux system encoding

Modify it from UTF-8 to GBK to reproduce the connection to Linux:

linux-Basics-Common commands

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.