Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the install command in Linux system

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In view of how to use the install command in the Linux system, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Usage: install [option]. [- T] Source file target file

Or: install [options]... Source file. Catalogue

Or: install [options]... -t directory source file.

Or: install [options]... -d directory.

This install copies files (usually only compiled files) to the destination of your choice.

If you want to download and install a ready-to-use software package on the GNU/Linux operating system

You should use package managers such as yum (1) and apt-get (1).

In the first three forms, copy the source file to the destination file or multiple source files to an existing directory

Both its ownership and permission modes are set in the. In the fourth form, create all the components in the given target directory.

The parameters that must be used for long options are also required for short options.

-- backup [= CONTROL] creates a backup for each existing file

-b is similar to-- backup but does not accept parameters

-c (ignore)

-C,-- compare compares each set of source and target files, and in some cases does not modify the target file

-d,-- directory treats all parameters as directory names; creates all components for the specified directory

-D create all necessary parent directories of the destination directory, and then copy the source files to that directory

-g,-- group= group sets the group it belongs to instead of the group to which the process currently belongs

-m,-- mode= mode sets its own permission mode (like chmod) instead of rwxr-xr-x

-o,-- the owner= owner sets the owner himself (for superusers only)

-p,-- preserve-timestamps modifies the access / modification time of the source file to be consistent with the target file

-s,-- strip disassembles the symbol table

The strip-program= program specifies the program to disassemble the binary file

-S,-- suffix= suffix overrides common backup file suffix

-t,-- target-directory= directory copies all parameters of the source file to the specified directory

-T,-- no-target-directory treats the target file as a normal file

-v,-- verbose displays its name when it creates a directory

-- preserve-context maintains a secure environment for SELinux

-Z,-- context=CONTEXT sets the SELinux security environment for files and directories

-- help displays this help and exits

-- version displays version information and exits

Backup files are suffixed with "~" unless with the-- suffix option or SIMPLE_BACKUP_SUFFIX

Environment variable assignment. Version control can be done through the-- backup option or the VERSION_CONTROL environment

Variable to select. The following are the available variable values:

None, off does not backup (even if the-- backup option is used)

Numbered, t backup files are sorted with numbers

Existing, nil use numbers if digital backup files already exist, otherwise backup by normal method

Simple, never always back up in the normal way

Example:

The code is as follows:

[root@linux ~] # install test.php ar_test # copy test.php to ar_test

[root@linux ~] # install-d hao # create directory

[root@linux ~] # install-t hao utf8 test.php # utf8 test.php cp to the hao directory

The difference between install Command and cp Command in linux

Basically, install is used in Makefile, and the cp command is used elsewhere.

They accomplish the same task-copying files, and the main differences between them are as follows:

1. Most importantly, if the target file exists, cp will empty the file and then write the new file to it, while install will delete the original file and then write to the new file. This is because writing to a file in use may cause problems, such as a failure to write to an executing file, such as an error caused by writing a new file to a file handle that is already being written continuously. Using install to delete and then write (will generate a new file handle) to install can avoid these problems.

2. The install command will properly handle the issue of file permissions. For example, install-c sets the permissions of the target file to rwxr-xr-x

3. The install command can print out more and more appropriate debug information, and automatically deal with the problem of SElinux context.

The code is as follows:

Install-copy files and set attributes

When install makes a copy, set attributes.

Therefore, try to use the install command in Makefile.

For example

The code is as follows:

@ install-d / usr/bin-p-D-m 0755 targets / usr/bin

Equivalent to

The code is as follows:

@ mkdir-p / usr/bin targets / usr/bin 755 / usr/bin/targets / usr/bin/tagets

Update file timestamp

The install command is so powerful.

In addition, the @ prefix means that the results are not output on the console.

This is the answer to the question about how to use the install command in the Linux system. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report