Common Linux commands (version 2) and common linux commands

Source: Internet
Author: User

Common Linux commands (version 2) and common linux commands
Permission management commands

1. chmod [change the permissions mode of a file]:/bin/chmod

Syntax: chmod [{ugo} {+-=}{ rwx}] [file or directory name] // intuitive

E. g. chmod u + wx filename

Chmod o-x filename

Chmod g = rwx filename

Or: chmod [mode = 421] [file or directory] // recommended

Number of the permission pair:

R-4

W-2

X-1

 

E.g. rwxr-xr -- 754

Rw-r-x -- x651

752 rwxr-x-w-

 

Chmod 777 dir1 // set the directory dir1 to have all permissions for all users

Appendix: su [-] username: users that can be switched // experiment content

Exit: exit

 

Summary:

 

Directory:

R-ls

W-rm, touch, mkdir

X-cd

[Therefore, in Linux, basically all directories have the rx permission. Otherwise, it would be more awkward...]

 

2. chown [change file ownership]/bin/chown

Chown [user] [file name or directory name] # change the file owner

 

E.g. chown nobody file1 # change the owner of file file1 to "nobody" and "nobody" to the default user.

 

Appendix-Add a user:

1) useradd afang

2) passwdafang # set a password for passwdafang.

 

3. chgrp [change file group ownership]/bin/chgrp

Chgrp [user group] [file or directory] # change the group to which the file or directory belongs

# Must be an existing system group

 

E. g. chgrp adm file1 # change the file1 group to adm.

# Adm is an existing group in the system.

[How do I use a group to change the user group? Let's study later...]

 

4. umask/bin/umask # display and set the default file permissions

Umask [-S] //-S displays the default permissions of new files or directories in the form of rwx, which is more intuitive.

 

E.g. umask // view the default permissions.

# Display 0022: 0-Special Permission bit, 022-user permission bit [u, o], representing the mask value;

Calculation: 777-022 = 755 // This is the default permission for creating a directory

666-022 = 644 // is the default permission for creating a file, which does not have the x permission. The File Permission is less than the directory permission. X

 

Appendix 1: many UNIX systems do not have the-S option, so they can only be calculated based on the above!

Appendix 2-Linux permission rules: default file creation, cannot grant executable permissions (X )! The advantage is that it shields many attacks and viruses.

Appendix 3-change default permission value: umask [mask value] // The Mask value must be calculated first, instead of the initial permission value. It must be the calculated mask value, but do not change it!


Common linux Commands include

Common linux commands (BASICS)

1. man provides help explanations for familiar or unfamiliar commands

For example: man ls, you can view the ls-related usage.

Note: Press q or ctrl + c to exit. in linux, you can use ctrl + c to terminate the current program.
2. ls view the directory or file owner * and list the files under any directory

Eg: ls/usr/man

Ls-l

A. d indicates directory. If it is a "-", it indicates a file. If it is l, it indicates a connection file (link)

B. Permission for file or directory permission. Read (r), write (w), and run (x) respectively ).

3. Copy files using cp

Eg: cp filename1 filename2 // copy filename1 to filename2

Cp 1.c netseek/2.c // copy 1.c to the netseek directory and name it 2.c.

4. rm delete files and directories

Eg: rm 1.c // Delete the. c file.

5. Remove the directory or change the file name.

Eg: mv filename1 filename2 // rename filename1 to filename2

Mv qib. tgz ../qib. tgz // move to the upper-level directory

6. Change the current directory pwd on cd to view the complete path of the current directory

Eg: pwd // view the current directory path

Cd netseek // enter the netseek directory

Cd // exit the current directory

7. cat, more command

Displays the content of a file. The two commands are different: cat prints the file content all the time, and more is displayed on the split screen.

For example; cat> 1.c // You can paste the code into the. c file and press ctrl + d to save the code.

Cat 1.c or more 1.c // you can view the content in it.

Gcc-o 1 1.c // compile 1.c into the. exe file. We can compile the Code with this command.

8. Modify the chmod command permission usage: chmod one-digit octal number filename.

Eg: chmod u + x filenmame // you only want to run the command for yourself.

// U indicates the file owner. g indicates the group of the file. O indicates others; r table readable; w table writable; x table can run

Chmod g + x filename // the same group of people to execute

9. clear, date command

Clear: clear screen, equivalent to cls in DOS; date: displays the current time.

10. mount a hardware device

Usage: mount [parameter] device load point to be loaded

Eg: mount/dev/cdrom

Cd/mnt/cdrom // enter the cd directory

11. su switches to another person's identity without logging out.

Usage: su-l user name (if the user name defaults, the user name is switched to the root state)

Eg: su-l netseek (switch to the netseek user and the user will be prompted to enter the password)

12. whoami, whereis, which, id

// Whoami: confirm your identity

// Whereis: queries the directory where the command is located and the directory where the help document is located

// Which: query the directory where the command is located (similar to whereis)

... The remaining full text>

Examples of common linux commands

There are a lot of commands, and I will forget what I learned at once. I can only accumulate them slowly. Many of them are generally not used. 1. File Viewing and connection commands
Connect the file together, use the ">" operation to combine several files into a new file, or use ">" to append the file to the end of the saved file.
Syntax:
Cat [parameter] filelist
-N or -- number: numbers the number of all output rows starting from 1
-B or -- number-nonblank: similar to n, but not numbered for empty rows
-S: two blank lines are displayed. replace them with one blank line.
-V: displays unprintable characters.
Filelist: an optional list used to combine files. 2. split-screen display command
Similar to cat, But it displays a page each time, displays the next page by space, exits by pressing the <q> key, and provides help information by pressing the Syntax
More [Options] <file>...
-Num: specifies the number of lines displayed per screen.
-D: a message is displayed below the screen.
-L: by default, more will suspend if it encounters a paper delivery character ^ L. You can use this option to cancel this function.
-F: calculate the actual number of rows.
-P: Not to display every page in a scroll mode, but to display the page first.
-S: two blank lines are displayed. replace them with one blank line.
-U: No underline is displayed.
+/<String>: Search for string in the file and display the content on the page where the string is located.
+/<Num>: displays data starting from row num.
File: the file to be displayed.
3. Display files by page. Similar to more, but can be moved before and after the file.
Syntax:
Less [parameter] File Name
-I: Case sensitivity is ignored during query.
-Num: specifies the number of lines displayed per page.
-P <string>: Search for the string in the file and display it from the first matching position.
-S: when the content of a column exceeds the width of the display screen, the excess part is directly truncated. By default, the excess part is folded back to display the commands for copying, deleting, and moving.
1. Copy an object.
Syntax:
Cp [Option] <source> <dest>
Cp [Option] <source>... <directory>
-R recursive copy directory
-F delete an existing target file and copy it again
-A tries its best to retain the structure and attributes of the source file in the backup.
2. Delete
Rm [Option] <name> ....
This command is used to delete specified files or directories one by one. By default, <name> is the file name. The rm command does not delete the directory. The directory can be deleted only when the-d option is specified.
Syntax:
-F force Delete, including read-only files, without prompting the user
-I prompt the user when deleting each file
-R recursively deletes contents in a directory to move or rename files and directories.
Syntax:
Target file of the mv [parameter] source file
-F forcibly overwrite existing files.
-I prompt the user before overwriting existing files.
-U does not overwrite the target file when the target file is earlier than the original file.
-V outputs relevant information when moving files. Create and delete directory commands
1. Create a directory command
Mkdir [parameter] Directory Name
-P if the parent directory does not exist, create all parent directories. 2. Delete the empty directory.
Syntax:
Rmdir [parameter] Directory List
-P indicates that after a specified directory is deleted, if the parent directory of the directory is empty, the switch working directory and display directory commands will be deleted.
1. Change the current working directory.
Syntax:
Cd directory name
If the directory name is not followed, the root directory of the user is returned. In addition, the user must have the permission to enter the directory. In addition, cd ~ Switch to your home directory. You can switch cd... to the upper directory 2 in front of the ticket to display the working or current directory name.
Pwd [parameter] 3. List contents in the directory.
Syntax:
Ls [parameter] [Directory]
-A shows all files, including hidden files... the remaining full text>
 

Related Article

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.