Linux basic commands

Source: Internet
Author: User
Tags parent directory

1. View the file information in the directory
> LS//list View the file information in the current directory
> ls-l or ll//to display the file information in a detailed list
> ls-a//View all files (including hidden files)
> Ls-al//View all files in a detailed list

2. View your current location
> pwd

3. Directory switching
> CD. Switch to Parent directory
> CD directory//Switch to a "directory" in the current directory
> CD//Switch to the current user's "home directory" inside
> CD ~//switch to the current user's "home directory" inside

4. See who you are
> WhoAmI//View the user in action
> Who am I//check to see user information for the current login system

5. Account switching
SU account name
> su-root//Switch to the root Administrator account (permissions are also root)
> Su-//switch to the root Administrator account (permissions are also root)

> su root//switch to root Administrator account (normal user rights)
> SU General account name
> Exit/Quit as original account
Note: Multiple consecutive use of the SU instructions will result in an accumulation of accounts
If you need to exit your current account, go back to your original account and use the Exit command
Shuhua---->root---->shuhua---->root

6. Switch to the Pure command window
># init 3//Switch to command window
># init 5//Switch to Desktop window

7. Directory Operations
① Creating directories Make Directory
> mkdir dirname//Create a directory
> Mkdir-p dirname/dirname/dirname [-p]//Recursive creation of multi-level catalogs
> mkdir Dir/dir/newdir
> mkdir dir/newdir/newdir-p
Create a directory, the number of new directories more than 2, you need to add-p parameter, recursive creation

② Change the name
> MV Diroldname dirnewname
> MV Dir/oldname dir/newname

③ Move Operation move
> MV Dir1 DIR2//Dir1 move to the bottom of the Dir2 directory
The MV can change the name or move the operation
Change the name: The second argument is a "nonexistent" directory name, that is, change the name
Move operation: The second parameter is the "existence" of the directory name, that is, the mobile
There are two implementations within the MV: moving, changing names

④ copy Operation copy
> CP filename dirname//filename file is copied to the DirName directory
> CP filename dirname/newname//Copy file to target address a new name
> cp-r dir dirname//recursive copy directory needs to set the-R parameter
> Cp-r dir1/dir2 dir3//dir2 is copied to the DIR3 directory below
> Cp-r dir1/dir2 newdir//dir2 is copied to the current directory and changed to a new name

⑤ Delete operation
> RM filename//delete individual files
> rmdir dirname//delete a single empty directory
> rm-r dirname//recursive Recursive deletion of non-empty directories
> RM-RF filename//recursive and force recursively forcibly delete any file
> RM-RF///root Execute kill by yourself


8. File operation
① File View
> Cat filename//file content output to the page at once
> head-n filename//View the top n rows of a file
> tail-n filename//View the contents of the file on the following n lines
> WC filename//view file content line count
> more filename//press Enter to view the contents of the file "progressive"
Do not support back to see, Q key exit
> less filename//view various parts of the document through the "Up or down" key
Q Key to Exit view
② File creation
> Touch filename//Create file

③ Append content to File
> Echo content > FileName//content to be "overwritten" in the filename file
If the corresponding file does not exist, it will be created automatically
> Echo content >> filename//Add content to filename file in "append" mode
If the corresponding file does not exist, it will be created automatically
> Cat file1 >/>> file2//file1 content to file2 inside

9. User operation,
User information is stored in the configuration file/etc/passwd
① Creating a user Useradd
> Useradd User name//Add an ordinary user to the system
To create a group with the same name
> useradd-g GID Group number-D home directory-u user ID username
(The custom home directory will be automatically created by the system.)

② Modifying User Usermod
> usermod-g GID Group number-D home directory-u user ID number-L new name username
(Modified home directories are not created automatically and need to be created manually)

③ Delete User Userdel
> Userdel username//delete user information in/etc/passwd (home directory to keep)
> Userdel username-r//delete user information in/etc/passwd also deletes the user home directory

10. Group Operations Group
User information is stored in the configuration file/etc/group
① Creating a group Groupadd
> Groupadd groupname

② Modify Group Groupmod
> groupmod-g GID Group number-N new name GroupName

③ Delete Group Groupdel
> Groupdel groupname
Note: Users with associations inside the group are prohibited from deleting

11. See what parameters the directive can set
> Man command

12. Set Permissions for Files
① setting permissions in a relative way
chmod u+/-rwx[,g+/-rwx][,o+/-rwx] FileName
> chmod U+RW filename//Add read and Write permissions to the file owner
> chmod u+wx,g-rx,o+rwx filename//Master add Write, execute permissions,
The same group of users to cancel read, execute permissions,
Additional group users increase read, write, execute permissions
> chmod u+r,u-x filename//Add "read" permission to master, Cancel "execute" permission

② Digital Absolute Way Set permissions
READ: 4
Write: 2
Performed: 1

6-------> Reading and writing
1-------> Execute permissions
3-------> Write and Execute
2-------> Write
4-------> Reading
5-------> Reading and execution
7-------> read, Write and execute
0-------> Empty permissions

chmod ABC filename//abc Three digits representing the owner, the same group, the other group user rights information
> chmod 751 filename//HOST: Read, Write, execute
Same group of users: Read, execute
Other group Users: Execute

How do I choose to use letters and numbers?
A: Permission changes "less" using the letter method
Permission Changes "More" use digital mode

13. Search for the specified content in the specified file
grep is searched for content file
> grep login passwd//search for login in passwd file
Will print out the contents of the line with the login word

14. View the size of the file occupying disk space
Disk has block blocks (small lattice), the smallest space inside the disk is a block blocks, the size is 4k (can be modified)

> du-h target file
1000k of the disk can be stored in 1k pictures, the number of storage.
A: Block 4k, can be stored 250, utilization rate of 25%.

15. Piping various Uses
> Ls-l | grep passwd//Get passwd content in the listed file information
> grep sbin passwd | GREP ABC//Find line content in passwd file that matches both ABC and Sbin
> grep sbin passwd | GREP ABC | WC//multiple pipes used simultaneously
Find the number of lines in the passwd file that match both ABC and Sbin

> Ls-l | head-15 | TAIL-5//View the contents of the 第11-15个 file in the current directory

16. File Lookup Instructions
Find directory option option value
> Find/-name passwd//Find a file under the current directory with the name passwd
> Find/-name passwd//traverse the entire directory of the system to search for files named passwd (inefficient)

> Find/-mindepth 3-maxdepth 4-name passwd//Find the file in the directory hierarchy between 3-4

Options:
-name finding files by file name
-name "pass*" searches for files starting with a pass by Fuzzy Lookup method

-maxdepth n Limits the deepest level of the lookup directory
-mindepth n Limit find the lightest level of a directory

-size to find by file size
Default unit: 512 bytes
100c units: bytes
2k units: Kbytes

-100c condition is that the file size is less than 100 bytes
+100c condition is file size greater than 100 bytes
> Find/-size 52c//Find files with a file size of 52 bytes in the current directory
> Find/-size +3k//Locate file size greater than 3k in the current directory
> Find/-size-150c//Locate file size less than 150 bytes in current directory
> Find/-size 3//Find File size 1536 bytes in current directory

This article is from the "Sen Wang" blog, make sure to keep this source http://zhibeiwang.blog.51cto.com/7555525/1786920

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.