Linux Simple to use

Source: Internet
Author: User
Tags create directory lowercase readable

Linux Simple to use

1. Basic Commands

Create directory Patha:mkdir Patha

Go to catalogue PATHA:CD Patha

View Catalog contents: ls

To view the files in the directory for more information: Ls-l, can also be: ll (l is lowercase l, don't look wrong)

Copy file FileA to directory Patha (same-level directory premise): CP FileA PATHB

Copy directory Patha (including all directories) to directory PATHB (same-level directory premise): Cp-r Patha PATHB

deleting files Filea:rm FileA

Delete directory Patha (including all of the directories): Rm-r Patha

Move all of the/usr/test directories to the current directory: mv/usr/test/*.

Package Patha in gzip compression: Tar zcvf pathA.tar.gz Patha

Decompression PathA.tar.gz:tar ZXVF pathA.tar.gz

Establish a soft connection for FileA slfilea:ln-s FileA Slfilea (L is lowercase l, don't look wrong)

Establish a hard connection Hlfilea:ln FileA Hlfilea for FileA

View All processes: Ps-aux

Kill a process (specify process with process ID): kill-9 process ID

Refresh Displays the end of the FileA (actual work used to view the log dynamically): Tail-f FileA

Emptying FileA (such as emptying log files): Truncate-s 0 FileA

2. file Permissions

View information about permissions in the current directory: Ls-l

The first field of the output is the encoding that describes the file and directory permissions.

The first character of the field gem file type:

-Representative documents

D Stands for Directory

L representative Link

C stands for the character type device

b Represents a block device

n Represents a network device

The following three characters define 3 access rights:

R stands for file readable

W stands for file writable

X represents file Executable

Access rights are divided into three groups, a set of three characters (RWX), if there is no permission to use "-". The first set of objects of the owner, the second set of objects of the genus Group, the third group of the system to provide other users.

Example: The owner of the Readme.txt file is given readable writable, and other read-only permissions are granted: chmod 644 Readme

3.Vim Simple to use

View FileA files: Vim FileA

Edit FileA file: Vim FileA---> Insert key---> Move cursor to edit---> Edit End Press ESC to end edit

Save and exit Edit Filea:shift key +;---> Wq---> Enter

Discard previous changes and exit: SHIFT +;--->!q---> Enter

Free copy: v---> Move the mouse to select what needs to be copied (starting at the cursor start position)---> y

Copy one line: yy

Copy all: GG---> v---> Shift key +g---> y

Free Cut: v---> Move the mouse to select what needs to be copied (starting at the cursor start position)---> D

Paste: P

Find test: Enter the command in VIM:/test (press N again to find the next, press N to look up)

The basic Linux commands below are basically available commands, with only a few common parameters added.
    1. CD: Switch directoriescd /root
    2. mkdir: Creating Files
    • mkdir /root/testCreating directories requires that the root directory exists
    • mkrir -p /root/testLooping through the creation of catalogs
    1. Touch: Create Text
    • touch /test.txt
    1. Vim: Text editing, Vim divided into edit mode and instruction mode
    • Input I into edit mode in instruction mode, ESC exits edit mode to instruction mode
    • In instruction mode, enter the line number to exit as a ;q forced exit for exit :wq after saving q! :set nu

    1. Echo: Print contentecho "this is out"

    1. Cat: View Contentcat 文件名
    2. CP: Copying files
    • cp test.txt /root/testAssignment test to Path/root/test
    • cp -apr /root/test /root/testcopyCopy Directory
    1. PWD: View current path

    1. MV: Moving filesmv test.sh /root/test
    2. RM: Deleting files
    • rm test.txtDelete this file
    • rm -fr /root/test-r: Delete this directory-F: No prompt message, delete directly
    1. grep: You can pass regular expressions when filtering
    • grep ‘test’ d*Displays all rows that contain test in a file that begins with D.
    • grep ‘[a-z]\{5\}’ aaDisplays all rows that contain a string of at least 5 consecutive lowercase characters for each string.
    1. Head: Displays the n rows of the file's head
    • head -n 5 log2014.logDisplay the first five lines, default to the first 10 rows
    1. Tail: Displays n rows at the end of a file
    • tail -n 5 log2014.logPrint n rows from tail default to 10
    1. Find: Finding
    • Results in find can be handled by pipelines
    • find -name filename #查找名为filename的文件
    1. SEQ: print n digits
    • seq 1 5Printed from 1 to 5
    • seq 1 2 5Print from 1 to 5 with a step size of 2
    • seq -s "z" 1 5Connect the 1-5 with Z.1z2z3z4z5

    1. SED: A good line of action
    • sed -n /a/p t.txtFilter output specified content -n //Output only filter result /a //filter rule (contains a)// /p Output
    • sed -n 20,30p t.txtTake 20-30 rows of output
    • sed -i s#aaa#goo#g t.txtReplace AAA in T.txt with Goo, -i //Replace file contents
    1. Xargs:xargs to do some file operation with the channel, for example, find -type f -name "*.log"|xargs -i rm {} Delete all the log types of files
    • -i: parameter can replace the standard output of the pipeline directly with {}find -type f -name "*.log"|xargs -i rm {}
    • -I: parameter requires the substitution character to be specified beforehandfind -type f -name "*.log"|xargs -I {c} rm {c}
    • find / -type f -name "t.txt"|xargs -i sed s#aa#mmmmm#gChange the contents of all files named T.txt to Mmmmm
    1. awk: An operation that specializes in columns
    • awk -F "," ‘{print $1}‘ localhost.2017-10-12.logFind the first column in a file, split

Linux Simple to use

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.