Some linux basic commands and concepts

Some basic commands under Linux, beginners can read, other masters do not need to read:

 

First, file/dir under linux has three different owners: user, group, and others.

Each type of owner has three kinds of displayed permissions, rwx, and two special permissions of s or t.

rwx is read, write, and execute respectively, the command ls -l file/dir can view the permissions

 

The general format of the command is:

command  [-options]  parameter1  parameter2 ......

    Command Options Parameter 1 Parameter 2  …

 

 

man command: You can view the specific usage of a command and query how its options are used;

like man chown

 

chgrp [-R] file/dir: change the user group to which the file belongs, -R recursively change, chgrp usersgroup /tmp/test

chown [-R] username file/dir: change the owner of the file

chmod [-R] 777 file/dir: Change the permissions of the file (r for 4, w for 2, x for 1, just add them up)

chmod 755 /tmp/test, set permissions on /tmp/test to rwxr-xr-x

 

In the use of chown, you can directly chown username:group file/dir, directly modify the file owner and user group, and use " : " to separate;

In the use of chmod, you can also use ugoa to represent users, groups, others, all, -+= to delete, add, set,

For example: chmod a=rwx file/dir; chmod a+w file/dir;

 

cd dir: switch directories and directly cd back to the current user's home folder

pwd [-P]: Displays the current directory, -P displays the current path, not the link (l) path

mkdir [-mp] dir: create a new directory, -m can directly configure permissions, -p can create an upper directory, mkdir -m 755 /tmp/test

rmdir [-p] dir: delete a directory, -p deletes it together with the upper empty directory (rmdir can only delete empty directories)

 

PATH="$PATH":dir: configure environment variables, dir is the directory

 

ls [-options] file/dir: View files or directories. To view specific information, you need to specify different options

ls -l file/fir will appear total in the first line, the unit is k, you can use -h to automatically convert to the appropriate unit, the calculation method is: the actual number of blocks occupied by all data in this directory x the size of the block value,

ls -s can display how many blocks are occupied at the beginning of each line

 

cp [-options] source dest: copy files or directories, -r will continue to copy recursively, -i will ask when overwriting;

If -a is used, then all attributes of the file are completely copied (), otherwise the attributes and permissions of the executor will be copied

rm [-options] file/dir: delete files or directories, -r can delete recursively

mv [-options] source dest: move file or directory, or rename

 

nl [-bnw] file: View the file content, -ba displays the line number, including blank lines, -n adjusts the position of the line number, -n ln/rn, -w adjusts the position of the line number -w 3 The first line is displayed as 001

less file: the same as man's display

 

touch [-acdmt] file: create a file, or modify the time of the file, create a new file when the -c file does not exist, and -dt can specify the time

File time type:

1. The time to update when the mtime content data changes, -m to modify

2. The time that the ctime file permissions or attributes (the attributes displayed by ls -l) will be updated when they are modified.

3. The time that the atime file will be updated when it is read, -a to modify

 

umask [-S]: The default permission value of the current user when creating a new file or directory, the umask is displayed as 4 digits, and the first one is a special permission

-S is displayed in ugo mode, umask -S is displayed as u=rwx,g=rx,o=rx

The umask directly under root shows 0022, and the ordinary user shows 0002.

Indicates that when creating a file or directory, delete the w permission of the corresponding permission location, (because w corresponds to 2)

 

Special permissions appear on the x-bit of rwx, such as drwsrwsrwt, if there is no special permission, it should be drwxrwxrwx

According to the different positions of u, g, and o, they are called SUID, SGID, SBIT, (sst), respectively.

SUID: During the execution of the program, the executor will have the authority of the owner (only valid for binary programs)

SGID: You can set files and directories. The executor has the permission of the user group when executing it. When the executor has the w permission of the directory, the user group of the new file created by the user is the same as the user group of this directory.

SBIT: It is only valid for a directory. Only the user and root can delete the files or directories created by the user in this directory.

 

How to set special permissions:

SUID is 4, SGID is 2, SBIT is 1, which can be set by chmod

chmod  7755  file;chmod  5755  file;

 

file file/dir: View file types

 

which [-a] command: script file name (command) query, query in PATH, -a lists all found commands in PATH

whereis [-options] file/dir: file name query, exact match pattern

locate [-ir] keyword: file name query, fuzzy query, -i ignores case, -r can be followed by a regular expression

find [PATH] [-options] [action]: file name query, the following example:

 

Find the files between 50k-60k under /etc, and list the permissions

find  /etc  -size  +50k  -a  -size  -60k  -exec  ls  -ld  {}  \;

 

The meaning of permissions to files:

r: the content of this file can be read

w: can edit, add or modify the content of the file

x: the file has permission to be executed by the system

The file does not have the permission to execute x by default (rw-rw-rw), and the umask is also integrated to assign the permission when it is created.

For example, the file permissions created by root are: rw-r--r--, and those created by users are rw-rw-r--

 

The meaning of permissions for directories:

r: Indicates the permission to read the directory structure list, (ls)

w: permission to add or delete files or directories, or permission to rename files or directories, and permission to transfer file or directory locations

x: represents whether the user can enter the directory to become the working directory, (cd)

The default permission of the directory is rwxrwxrwx, and the umask should be integrated to assign the permission when it is created.

For example, the directory permissions created by root are rwxr-xr-x, and those created by users are rwxrwxr-x

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326943885&siteId=291194637