Linux---basic commands

Source: Internet
Author: User
Tags parent directory readable set time touch command

    1. chmod

      Features: Set access permissions for files

      The format of the command permission value:

      <1> user identifier +-= permission character

      +/-/=: Increase the scope of permissions, Cancel, give permission to the permissions represented by the code name

      User symbol:

      U: Owner g: Owner same group user o: Other User A: all users

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/13/wKiom1c2jo-BPJ5QAAAHEIoBOY4597.png "title=" 1.PNG " alt= "Wkiom1c2jo-bpj5qaaaheioboy4597.png"/>

File 1 is a normal file, the user has a readable writable non-executable, the group has a readable writable non-executable, the others has a readable non-writable non-executable.


At this point, add the executable power to the others and add the executable power to the user.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/10/wKioL1c2kIHiBdZDAAAezHJDnnk647.png "title=" 2.PNG " alt= "Wkiol1c2kihibdzdaaaezhjdnnk647.png"/>

To remove all permissions from the user

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/10/wKioL1c2kRPgcO6kAAAV51D8Zw4292.png "title=" 3.PNG " alt= "Wkiol1c2krpgco6kaaav51d8zw4292.png"/>


To add or remove a lot of permissions to a user, we can directly chmod u+rwx 1 or chmod u-rwx 1, when user has all permissions or not all permissions.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/13/wKiom1c2kTySr-MtAAAY2ATGbQw134.png "title=" 4.PNG " alt= "Wkiom1c2ktysr-mtaaay2atgbqw134.png"/>


Because the readable writable executable is composed of three groups, we can also use octal to express permissions, such as 000 means that User,group,others does not have all permissions, 213 means that user has only writable permissions, group has executable permissions, Others has writable executable permissions.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/10/wKioL1c2lA3Bc_SyAAAfnJd1kvk161.png "title=" 5.PNG " alt= "Wkiol1c2la3bc_syaaafnjd1kvk161.png"/>


2.chown

Function: Change the owner of the file to use the permissions as root

If you change the owner of the file directly under the current user, you will get an error. The permissions should be changed to root.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/14/wKiom1c2mwTjLBtHAAA9qRUHjgU028.png "title=" 6.PNG " alt= "Wkiom1c2mwtjlbthaaa9qruhjgu028.png"/>

The owner of file 3 is root, but now it is Xiaoyu, but the group it belongs to is still root.

3.chgrp

Function: Change the owning group of a file or directory


Change the owning group of file 3 to Xiaoyu

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/11/wKioL1c2nLfiGFYZAAAY560CRSw706.png "title=" 7.PNG " alt= "Wkiol1c2nlfigfyzaaay560crsw706.png"/>

3. Umask

Features: View or modify file masks

Format: Umask Permission value

New Folder Default permissions = 0666-Permission Mask

New directory default permissions = 0777-Permission Mask

Super User Default mask value is 0022, normal user defaults to 0002

Description

By subtracting the permission mask from the existing access rights, you can create a preset permission when the file is established.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/11/wKioL1c2onPRNO9FAAAvI9U5JwI914.png "title=" 8.PNG " alt= "Wkiol1c2onprno9faaavi9u5jwi914.png"/>

The default mask is 0022, and the permission for file 2, 3 is 644 (666-022);

If you change the mask to 0032, the permissions for file 2, 3, or 644.

Cause: 644 Binary 110 100 100

032 Binary 000 011 010

Because the group has no writable executable permission, the others does not have the readable permission, so it does not have to be reduced, so it is also 644.


4. ls

<1>-a lists all files in the directory, including hidden files that begin with.

<2>-B lists the characters that are not available in the file name in the form of a backslash and character number

<3>-C The modified time of the I byte of the output file and sorted by this

<4>-D Displays the directory like a folder, rather than displaying the files below it. ls-d the specified directory

<5>-F does not sort the output file

<6>-I index information for the I node of the output file. Ls-ai Specifying files

<7>-K is the size of the file in bytes. Ls-alk Specifying files

<8>-l list File details

<9>-F attaches a character after each file name to indicate the type of the file, ' * ' indicates an executable plain file; '/' indicates a directory;

' @ ' means symbolic link; ' | ' Represents fifos; ' = ' represents a socket.

<10>-R Reverse Directory sorting

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/11/wKioL1c2qHfgDIArAABLK7td5q0449.png "title=" 9.PNG " alt= "Wkiol1c2qhfgdiaraablk7td5q0449.png"/>

5. CD command

Objects used: All Users

Command format: CD file name [DirName]

Function: Switch current directory to dirname


CD ~: Go to User Directory

CD-: Return to the most recently accessed directory

CD: Return to Parent directory

CD!$: Use the parameters of the previous command as the target parameter of the CD command

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/14/wKiom1c2qWbxPkjVAAAi_Xwa8AY534.png "title=" 10.PNG "alt=" Wkiom1c2qwbxpkjvaaai_xwa8ay534.png "/>


Note: When we go to the root directory, we want to go to the parent directory or the root directory. Exit can jump directly into the Class2 directory.


6. Date (time-related)

Specify the format display time: Date +%y_%m_%d, date +%y:%m:%d

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/11/wKioL1c2rnbSmlXRAABq_nPE6t4001.png "title=" 11.PNG "alt=" Wkiol1c2rnbsmlxraabq_npe6t4001.png "/>

Date set Time:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/11/wKioL1c2r2nQTHyUAAAlj6rkeA4135.png "title=" 12.PNG "alt=" Wkiol1c2r2nqthyuaaalj6rkea4135.png "/>

you can see that only the root permission can set the time, others can only see the time


Time stamp

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/11/wKioL1c2sNvTtqSaAABmxhNLnss653.png "style=" float: none; "title=" 15.PNG "alt=" Wkiol1c2snvttqsaaabmxhnlnss653.png "/>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/11/wKioL1c2sNvDvm2gAAASmLJ-6qU797.png "style=" float: none; "title=" 14.PNG "alt=" Wkiol1c2snvdvm2gaaasmlj-6qu797.png "/>


7. Cal Instructions

cal commands can be used to display (Gregorian) calendars.

Command function:

<1>-1 shows the one month calendar

<2>-S displays Sunday for the first day of one weeks, the default format

<3>-M displays the first day of the week for one weeks

<4>-j display in the first day of the year


8. Touch command

function: Create a new file that does not exist

Format: Touch file name

9. mkdir Instructions

Function: Implements a folder or directory named DirName (specified folder) in the specified location. The user to create the folder or directory must have write permissions to the parent folder that is created. Also, the folder or directory that you create cannot have the same name as a file in its parent folder or parent directory.

Format: mkdir Directory


RmDir Instructions && RM Instructions

The rmdir is a command that corresponds to the mkdir. MkDir is to create a directory, and RmDir is a delete command. The RM command can delete files or directories at the same time.

<1> rmdir

Applicable to: All users who have permissions to the current directory operation.

Command format: rmdir [-p-v] DirName

role: Delete Empty directory

-P: When the subdirectory is deleted, if the parent directory is also empty, then the parent directory is deleted.

-V: Shows the process of deleting a directory


<2> RM

Objects used: All Users

Command format: RM [-f-i-r-v] DirName

Role: Deleting files

-F: File properties are read-only and can be deleted directly

-I: Ask for confirmation before deleting

-r: Delete directory and all files under it

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/15/wKiom1c2uVmwNIsFAAAzwUPPzpg073.png "title=" 16.PNG "alt=" Wkiom1c2uvmwnisfaaazwuppzpg073.png "/>-


Ten. CP

Function: Copy files or directories

Note: The CP command is used to copy files or directories, such as the presence of more than two files or directories, and the final destination is an existing directory, it will be the previous specified files or directories copied to this directory, if you specify multiple files or directories, The final destination is not an existing directory, and an error message appears.

Format:

CP source file source file

CP Source Files Directory

CP Directory-T source file


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/15/wKiom1c2vzeQX5eiAAA8QJUx3A0304.png "title=" 17.PNG "alt=" Wkiom1c2vzeqx5eiaaa8qjux3a0304.png "/>


One. MV Instruction

used to move files or rename files , often used to back up files or directories.

Format: MV source file or directory destination file or directory

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/11/wKioL1c2wWaRTdFyAAAkq0dDMAc645.png "title=" 18.PNG "alt=" Wkiol1c2wwartdfyaaakq0ddmac645.png "/>


basename directives

Returns the base file name of a string parameter

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/11/wKioL1c2wuOTfEKtAAAiTqJBFfc687.png "title=" 19.PNG "alt=" Wkiol1c2wuotfektaaaitqjbffc687.png "/>


DIRNAME directive

Action: Processes the path to get the parent directory of the path and does not check whether the path is legitimate.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/15/wKiom1c2w0jA0WYpAAB7dogPgqk507.png "title=" 21.PNG "alt=" Wkiom1c2w0ja0wypaab7dogpgqk507.png "/>


. more Directives

Features: More commands, functions similar to the CAT,CAT command is the entire contents of the file displayed on the screen from top to bottom. More page-by-page display makes it easy for users to read pages by page. The more command reads the file backwards from the front, so it loads the entire file at startup.


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/15/wKiom1c2xxLCjHt6AAAZKfYBeSQ108.png "title=" 22.PNG "alt=" Wkiom1c2xxlcjht6aaazkfybesq108.png "/>

A file is created and 0~99 is used when you use more files.

Enter down n rows to be defined. Default 1 rows

CTRL+F Scroll down one screen

Ctrl+b Back to previous screen

The. less directive

Less is also a tool for paging through files or other output, which should be said to be a tool for Linux to view the contents of a file. Less usage is more resilient than more. In more time, we have no way to turn front, can only look back, but if used less, you can use the upper and lower key functions to go to look at the document. You can also search up and down. less does not load the entire file until it is viewed.

-N Display Line number

Q exit

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/12/wKioL1c2yq-Q5vdqAAAJFFY5lCs966.png "title=" 23.PNG "alt=" Wkiol1c2yq-q5vdqaaajffy5lcs966.png "/>

. Head Tail Instructions

Used to display a block of text at the beginning or end of a volume.

The head is used to display the beginning of the file to the standard output; tail See the end of the file.

Head Default prints the first 10 lines of the file at the beginning.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/12/wKioL1c2y9qguBlpAAAdu5L1QAs905.png "title=" 24.PNG "alt=" Wkiol1c2y9qgublpaaadu5l1qas905.png "/>


. file directive

Function: Identify file types

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/15/wKiom1c2zJaQllj4AAAQuXWMg0g427.png "title=" 26.PNG "alt=" Wkiom1c2zjaqllj4aaaquxwmg0g427.png "/>


which directive

We often find a file in Linux, but not where it is built. You can use the command to search:

Which viewing the location of an executable file

Whereis viewing the location of a file

Locate to view the location of a file with a database

Find actual search hard disk query file name


which command : searches for the location of a system command in the path specified by the path variable, and returns the first search result. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/12/wKioL1c20I6QmbzkAAAydcKBYEw924.png "style=" float: none; "title=" 27.PNG "alt=" Wkiol1c20i6qmbzkaaaydckbyew924.png "/>


whereis Command: search only for program name, and search binaries (parameter-B), man description file (parameter-m) and source code file (parameter-s).

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/15/wKiom1c2z6vQepmqAAAWRo3wxkc647.png "style=" float: none; "title=" 28.PNG "alt=" Wkiom1c2z6vqepmqaaawro3wxkc647.png "/>


Find command: Actual search hard Drive query file name

This is highlighted in the next blog post.


19.BC instruction

Function: Calculator

This article from "Together to see the Stars" blog, reproduced please contact the author!

Linux---basic 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.