Linux common commands (notes)

Source: Internet
Author: User
Tags parent directory

1. See what file information is in the directory

List view what files are in the current directory > ls//list  -list View the contents of the file under the directory in detail > ls-l or ll//View the file name information in the specified directory > LS directory// View the file name information in the specified directory as a detailed list > ls-l directory//list  All view all files, including hidden files > ls-a//list list  All view all files in a detailed list, including hidden files > ls- al//See the index number of the file name in the directory > ls-i

2. Directory switching

Switch directory > CD directory name//to parent directory switch > CD. Quickly switch back to your home directory > CD ~      

3. View the current operating position

> pwd

4. View operator information (who is in the operating system)

> WhoAmI

5. Switching between different users

Switch to root user > Su-              //Effect ditto > Su-  root//switch to normal user > su  normal User name//The current user returns to the previous user > exit        su multiple times, the user will "accumulate , it is recommended that "Su" and "Exit" match using Test--->root--->test--->root--->test

6. Switch between graphical mode and command mode

Graphics to command mode toggle > Init 3//command to graphics mode toggle > Init 5

7. View the executable program file location for the instruction

> which directive

8. Directory Operations
1) Create a directory

Create a table of contents > mkdir  newdir//recursively create a multilevel directory > mkdir-p newdir/newdir/newdir     //newdir new directory more than 1 levels (2/3/4, etc.) set the-p parameter, If you have a new directory, you do not need the-P parameter > mkdir  dir/newdir> mkdir  dir/dir/newdir> mkdir-p dir/newdir/newdir

2) Move (change name) directory (Directory/file can be manipulated)

Dir1 move to the DIR2 directory and change the name to "original" > MV  dir1  dir2                //dir1 move to Dir2 directory and change the name to newdir> MV  Dir1  dir2/ Newdir         //dir2 moved to DIR4 directory, and renamed "Original name" > MV  dir1/dir2  dir3/dir4//dir2      moved to DIR4 directory, and changed the name to Newdir> MV  dir1/dir2  dir3/dir4/newdir  //dir2 move to the current directory and change the name to "formerly known" > MV  dir1/dir2  .             // Dir2 move to the current directory and change the name to newdir> MV  Dir1/dir2  ./newdir

3) Copy (change name) directory (Directory/file can be manipulated)

Copy the normal file//file1 is copied to the Dir1 directory next copy, and to change the name of "original" > CP  file1  dir1             //file1 copied to the Dir1 directory next copy, and to change the name of newfile> CP  file1  dir1/newfile     //Copy directory-r parameter requires//recursive copy directory//dir1 copied to Dir2 directory next copy, and renamed "original name" > Cp-r dir1  Dir2            //dir1 was copied to the Dir2 directory next copy, and to change the name of newdir> cp-r dir1 dir2/newdir//dir3     was copied to the Dir5 directory next, and to change the name of "formerly known" > Cp-r dir1/dir2/dir3   dir4/dir5  

4) Delete Remove

Normal file deletion > RM  filename      //delete directory [ignore hierarchy] requires-r parameter > rm-r dir         //recursive force delete file//Avoid deleting hidden files prompt > rm-rf  file      Recursive forced removal of all contents of the System > RM-RF  /

9. File operation
1) View the contents of the file

Display files in the terminal all contents > Cat filename//     through the "hit the return" way from the first line to view the contents of the file//does not support back to see//q key exit View > more filename     //"up and Down" Key way to view the contents of each part of the file//support back to see, Q key exit > Less filename     //view file "Top N rows" content > Head-n  filename  //view file "N-line" content > Tail-  n  filename  //calculation file lines > WC  filename

2) Create a file

> Touch  filename   > Touch  dir/filename

3) Append content (the file does not exist will be "automatically" created)

Append content to File "Overwrite write" > echo  content > FileName    //To file pure append > Echo  content >> filename

10. User Action
User Configuration file/etc/passwd
1) Create add

Creating a user creates a group with the same name > Useradd  username                //create user at the same time set group > Useradd-  G Group number  username     //create user at the same time, specify the group, User number, home directory > Useradd-  G Group number-u user number-D home directory username

2) Modify Modify

Modify group is common operation > Usermod-  g gid  username     //modify group, user number, home directory, name > Usermod-  g gid-u uid-d home directory-L newname US Ername

Note: Home directory modifications need to be created manually, unlike the Create User home directory setting
Set up a home directory when the user is created, which is automatically created
When you modify a user's home directory, the directory is not created automatically (it needs to be created manually)

3) Remove Delete

Delete User (delete passwd file corresponding information), at this time its home directory needs to manually delete ># Userdel username     

11. Group Operations
Group configuration file/etc/group
1) Create add

> Groupadd  GroupName

2) Modify Modify

> Groupmod-g gid-  n newname  groupname

3) Remove Delete

Note: Only empty groups (no user information internally) are allowed to delete > Groupdel Group names

The VI editor uses
1) Command mode---edit mode toggle (Insert/insert)

A "cursor" moves backwards one I "cursor" and "content" does not change O "new" up a blank line S "Delete" the character of the cursor

2) tail-line mode function

: Q Quit     Editor: Wq    write quit Save and exit: W     Write Save: q!    Force exit (Do not save): w!    Forced write Save: wq!   Force save exit//Set line number to editor: set numbers or set Nu           //Cancel line number setting: Set Nonumber or set Nonu: Number cursor jumps to the line where the number is located//content lookup, lowercase n (next) Next, Upper case N (Next) :/content/  or/content/                                        /content Replacement "Cont1" is replaced with "cont2"//Replace the "first" cont1 of the line on which the cursor is located with the cont2:s/cont1/cont2/         //cursor "line" Replace all cont1 with cont2:s/cont1/cont2/g        

3) Command mode operation
(1) Cursor movement

A. At the character level (    K)  under (j)  Left (h)  right (l) key B. Word level    W  word next word first    e  end under (this) a word tail letter    B  before first letter C. Line level    $ line End    0 beginning D. Paragraph level (there are blank lines in the middle of two parts, each of which becomes a paragraph)    {  above (this) paragraph header    }  (This) End of paragraph E. Screen level (not to turn screen)    H  screen header    L  screen tail F. Document-level    G   document end line    1G  document first row    NG document Nth  line

(2) Content deletion

DD    Delete cursor line N+DD  includes current line delete n line content x     character level delete, delete cursor character CW    cursor deletion to end of word (convenient way to delete word)      and enter edit mode

(3) Content replication

YY      copy cursor line n+yy    include current line under inward copy N line content p       copy (delete) the content to paste operation

(4) Convenient operation

U       undo undo, all actions from File open can undo R       to replace the word character.       Repeat "recent" one instruction J       merge Upper and Lower lines

13. Permission settings
1) "Alphabetic relative" set permissions

Permissions: R Read W write x Execute User: U master  G same group  o other groups chmod  u+/-rwx, g+/-rwx, o+/-rwx  file different users through ", comma" separated in the same user, +/-can only use "one" " Rwx "In the same user can set one or more" UGO "each permission action can be set one or more users//owners add read, write > chmod u+rw  filename        //delete read, execute > chmod g-rx  filename        //Master Delete write, same group add execution > chmod u-w,g+x filename      //Other group user "add write, delete execute" > chmod o+w,o-x  FileName

2) "Digital Absolute Way" set permissions

READ: 4  written: 2  performed: 1 permission type: 0:  no permission 1:  Execute 2:  write 3:  Write, execute 4:  read 5: Read, execute 6: Read, write  , execute// ABC represents master, same group, other group User rights > chmod  ABC  filename   /master read, write, execute, same group read, write, other read > chmod 764  filename   / /Slam privileges > chmod 777  filename   //All users do not have any permissions > chmod  

Letter and digital trade-offs:
The comparison of permissions modification is "less", using the letter method
Permission modifications are compared "many", using the digital way

14. Find the specified content in the file
grep content (absolute/relative path) destination file

Looking for sbin in the passwd file will output the contents of the Sbin line > grep  sbin  /etc/passwd

15. View the size of the file occupying disk space
DU-H Files/Directories

View files as K-m occupying disk space size > du-h file name

16. File Search
Find present value finds table of Contents option option value option option value ....
Specific options:
(1) name finds the specified file based on the file name

Find  directory  -name  full file name//"Recursive traversal" system all directories look for file names equal to passwd > Find  /  -name  passwd[full NAME]    // recursively traverse/etc and all internal directories look for files whose names are equal to passwd > Find  //-name passwd[full NAME]   //Fuzzy Find file name starting with an >find  directory- Name  "an*" [Partial name]

(2) Limit the directory hierarchy of lookups
-maxdepth limit the most "deep" levels of lookups
-mindepth limit the most "shallow" levels of lookups

Locate passwd files > Find/-name passwd-mindepth 3-maxdepth 4 in 3-to 4-level directories

(3) Search by file size
Size units

Find size [equals] 50 bytes of file in current directory > find./  -size  50c

Unit:
Quantity unit Actual Size
-------> 512 bytes "100*512 bytes"
50c-------> bytes "50 bytes"
50k-------> Kbytes "50*1024 bytes"
50M------> MBytes "50*1024*1024 bytes"

Look in the current directory for size [greater than] 50 bytes of file > Find  ./  -size  +50c    //In the current directory look for size [less than] 50 bytes of file > Find  .  Size  -50c

17. Switch machine directive
Restart

> Reboot

Shutdown

> Poweroff  


Linux common commands (notes)

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.