Brother Bird's Linux Notes-----Contents

. 代表此层目录

 .. 代表上一层目录

 - 代表前一个工作目录

 ~ 代表『目前用户身份』所在的家目录

 ~account 代表 account 这个用户的家目录(account是个账号名称)

  • Abbreviation for cd Change Directory, which is a command used to change the working directory
  • pwd (display current directory) 
  • pw -p (show the exact path instead of using the link path)
  • mkdir [-mp] directory name option without arguments:

-m : Permission to configure file case! Direct setting, no need to look at the default permissions (umask)

 -p : help you to build the required directory (including the upper directory) recursively directly!

 

 

1. Why PATH---ls can be used by any user in any directory

 

The content of the PATH (must be uppercase) variable is composed of a bunch of directories, each directory is separated by a colon (:), and each directory has a "sequence". Looking at the above output carefully, you can find that both root and tom have the /bin directory in the PATH variable, so of course you can execute ls anywhere to find the /bin/ls executable file

Increase PATH path

[root@www ~]# PATH="$PATH":/root

能够将/root加入到执行文件搜寻路径PATH中了!不相信的话请您自行使用『echo $PATH』去查看吧

 

If I have two ls commands in different directories, eg /usr/local/bin/ls and /bin/ls then when I issue ls, which ls will be executed?

Answer: Which directory in the PATH is queried first, the instructions in that directory will be executed first!

 

2. CP

 

  •  cp (copy files and directories)

Options and parameters:,

-a : equivalent to the meaning of -pdr; (commonly used)

-i : If the destination file (destination) already exists, it will ask first when overwriting (commonly used)

-d : If the source file is a link file attribute (link file), copy the link file attribute instead of the file itself;

-p : Copy along with the file's attributes instead of using the default attributes (usually used for backups);

-r : recursive continuous replication for the target's replication behavior; (commonly used)

 

# That is to say, if no options are added, cp copies the attributes of the source file, not the linked file!

# To copy the properties of the linked file, you have to use the -d option!

 

3. RM

  • rm (remove file or directory)

 

Options without arguments:

-f : It is the loyalty of force, ignore files that do not exist, and no warning message will appear;

-i : interactive mode, ask the user before deleting

 -r : delete recursively! Most commonly used in directory deletion! This is a very dangerous option! ! !

4. mv (moving files and directories, or renaming)

Options without arguments:

-f : force enforced loyalty, if the target file already exists, it will be overwritten without asking;

-i : If the destination file (destination) already exists, it will ask whether to overwrite!

-u : If the target file already exists and the source is relatively new, it will be updated (update)

 

[root@www tmp]# mv bashrc1 bashrc2 mvtest2

# Note here that if there are multiple source files or directories, the last target file must be "Directory!

# Yizhong means to move all data to this directory!

Five, get the path and directory name

The difference between basename and dirname

basename ===> get the last file name

dirname ===> get the directory name

 

6. Viewing the content of the file

 cat starts from the first line to display the contents of the file
 tac starts from the last line to display, it can be seen that tac is the reverse of cat!
 When nl is displayed, output the line number along the way!
 more displays the contents of the file page by page
 less is not similar to more, but better than more, he can page forward!
 head to see the first few lines
 tail to see the last few lines
 od to read the contents of the file in binary! 

 

7. How to use UMASK

The umask is 003, so the removed permissions are --------wx, so:

File: (-rw-rw-rw-) - (--------wx) = -rw-rw-r--

Directory: (drwxrwxrwx) - (--------wx) = drwxrwxr--

Default permissions are 666 for archives and 777 for directories

umask 022 ------------ set the value of umask

 

8. Searching for file executables

which

[root@www ~]# which [-a] command

Options or parameters:

-a : List all directives found in the PATH directory, not just the first one found

whereis

The system will record all the files in the system in a database file [/var/lib/mlocate/], whereis and local will take the content of this database file as the standard

[root @www ~]# whereis [-bmsu] file or directory name

Options and parameters:

-b : only look for files in binary format

-m : only find the files in the manual path of the manual

-s : only look for source source files

-u : search for other special files that are not among the above three items

local

[root@www ~]# locate [-ir] keyword

Options and parameters:

-i : ignore differences in case;

-r : can be followed by a regular expression;

  •  updatedb: According to the setting of /etc/updatedb.conf, search the file name in the system hard disk, and update the database file in /var/lib/mlocate;
  •  locate: According to the database records in /var/lib/mlocate, find the keyword file name entered by the user

find

find is a very powerful search command, but it takes a lot of time, because find directly searches the hard disk

[root@www ~]# find [PATH] [option] [action]

Options and parameters:

1. Time-related options:

There are -atime, -ctime and -mtime, with -mtime description

-mtime n : n is a number, meaning files whose contents have been changed "within one day" before n days;

-mtime +n : List the file names that have changed content before n days (excluding n days themselves);

-mtime -n : List the file names that have changed content within n days (including n days itself).

-newer file : file is an existing file, listing file names that are newer than file

2. Parameters related to user or group name:

-uid n: n is a number, this number is the user's account ID, that is, UID, this UID is the number corresponding to the account name recorded in /etc/passwd.

-gid n : n is a number, this number is the ID of the group name, that is, the GID, which is recorded in /etc/group.

 -user name : name is the user account name! for example tom 

-group name: name is the group name, such as users;

-nouser : look for the owner of the file who does not exist in /etc/passwd

-nogroup : Find files whose owning group does not exist in /etc/group! When you install software by yourself, it is very likely that the software has no file owner in its properties, it is possible! At this point, you can use -nouser and -nogroup to search.

3. Parameters related to file permissions and names:

-name filename: search for the file with the filename filename;

-size [+-]SIZE: Search for files larger (+) or smaller (-) than SIZE. The specifications of this SIZE are:

                   c: stands for byte, k: stands for 1024bytes. Therefore, if you want to find a file larger than 50KB, it is "-size +50k" -type TYPE: the type of the search file is TYPE, the main types are: general regular file (f), device file (b, c), Attributes such as directory (d), link file (l), socket (s), and FIFO (p).

-perm mode : Search for files whose file permissions are "just equal to" mode, which is an attribute value similar to chmod.

For example, -rwsr-xr-x has an attribute of 4755!

         -perm -mode : search for files whose file permissions "must include all the permissions of mode", for example, we want to search for -rwxr--r--, that is, 0744 files, use -perm -0744, when a file When the permission is -rwsr-xr-x, that is, 4755, it will also be listed, because the attributes of -rwsr-xr-x already include the attributes of -rwxr--r--.

         -perm +mode : search for files with file permissions "including the permissions of any mode", for example, we search for -rwxr-xr-x, which is -perm +755, but a file attribute is -rw--- ---- will also be listed, because he has the attribute -rw.... !

 

4. Additional actions that can be performed:

-exec command: command is another command, after -exec can be followed by additional commands to process the searched results.

-print : print the result to the screen, this action is a preset action!

 

               

 

  •  {} represents "content found by find", as shown in the figure above, the result of find will be placed in the {} position;
  •  -exec up to \; is a keyword that represents the start (-exec) to the end (\;) of the extra action of find, and in between is the extra action in the find command. In this case it is " ls -l {} "!
  • Because ";" has a special meaning in the bash environment, it is escaped with a backslash.

 

 

Replenish:

There are three time parameters for a file record, namely access time (atime), status time (ctime), modification time (mtime), and ls displays mtime by default.

  • When the file has the special authority of SUID, it means that when the user executes this binary program, the user will temporarily have the authority of the program owner during the execution process.
  •  When a directory has the special permission of SGID, the group representing the new file created by the user under this directory will be the same as the group name of the directory.
  • When the directory has the special permission of SBIT, it means that the files created by the user in this directory can only be deleted without root!

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325064133&siteId=291194637