亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Operation and Maintenance Linux Operation and Maintenance What are the commands to modify files in Linux?

What are the commands to modify files in Linux?

Mar 09, 2022 pm 06:03 PM
linux Modify files

Linux commands to modify files: 1. "vi" or "vim" command, which can be used to modify the content of the file; 2. "mv" command, which can be used to modify the name of the file; 3. "chmod", The "chgrp" and "chown" commands can be used to modify the permissions of the file; 4. The "touch" command can modify the time of the file.

What are the commands to modify files in Linux?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

linux modify the contents of the file

The command is: vi,vim

  • vi editor, equivalent to Notepad, has editing functions, but weaker

  • vim is a complex editor, equivalent to Windows editplus, notepad Wait

Steps:

1. Execute vi world.txt to enter the editor (default command mode),

2 , click a or i to enter the editing mode, type: hello linux world!

3. Then press the esc key on the keyboard to exit the editing mode (enter the command mode),

4. Finally, type colon:,

5. Type wq again to save and exit.

Linux changes the name of the file

The command is: mv

mv (full spelling in English :move file) command is used to rename a file or directory, or move a file or directory to another location.

Syntax:

mv [options] source dest
mv [options] source... directory

The format is as follows:

mv source_file(文件) dest_file(文件)

Change the source file name source_file to the target file name dest_file.

linux modify file permissions

The commands are: chmod,chgrp,chown

chmod command

The chmod command is very important and is used to change the access permissions of files or directories. It is used by users to control access permissions to files or directories.

Take a folder named "cc" under the main folder as an example. The following is a step-by-step introduction on how to modify permissions:

1. Open the terminal. Enter "su" (without quotation marks)

2. You will be asked to enter your password next. Enter your root password.

3. Assume that my folder is in the home directory and the address is /var/home/dengchao/cc. Suppose I want to change the file permissions to 777, then enter chmod 777 /var/home/userid/cc in the terminal and the permissions of the folder will become 777.

If you want to modify the permissions of folders and subfolders, you can use chmod -R 777 /var/home/userid/cc

The specific permissions (such as the meaning of 777, etc.) are explained below :

1.777 has 3 digits, the highest digit 7 is to set the file owner access permissions, the second digit is to set the group access permissions, and the lowest digit is to set the access permissions of others.

The permissions of each of them are represented by numbers. Specifically, there are these permissions:

  • r (Read, permission value is 4): For files, it has the permission to read the file content; for directories, it has the permission to browse the directory .
  • w (Write, permission value is 2): For files, it has the permission to add and modify file contents; for directories, it has the permission to delete and move files in the directory.
  • x (eXecute, execution, permission value is 1): For files, the user has the permission to execute the file; for directories, the user has the permission to enter the directory.

2. First, let’s look at how to determine the permission value on a single bit. For example, the highest bit represents the file owner permission value. When the number is 7, 7 is represented by “rwx” – {4 (r) 2(w) 1(x)=7}–And if the value is 6, use “rw-” to represent –{4(r) 2(w) 0(x)=6}–, “-” It means that it does not have permission, here it means that it does not have "execution" permission.

If we set the access rights of other users to "r–", the value is 4 0 0 = 4

Many beginners will be confused at first, but it is actually very simple. Treat rwx as a binary number. If it is present, it is represented by 1, and if it is not, it is represented by 0. Then rwx can be represented as: 111

, and 111 in binary is 7.

3. Let’s take a look at how to determine the permissions on 3 digits. If we want to set permissions for a file, the specific permissions are as follows:

The file owner has "read", "write", and "execute" permissions, group users have "read" permissions, and other users have "read" permissions. "Permissions, the corresponding letters are expressed as "rwx r– r–", and the corresponding numbers are 744

Generally, the highest digit represents the file owner permission value, the second digit represents the group user permission, and the lowest bit indicates other user permissions.

Let’s give some examples to get familiar with.

##rw- rw- r–664

例1:

$ chmod a+x sort

即設(shè)定文件sort的屬性為:

文件屬主(u) 增加執(zhí)行權(quán)限

與文件屬主同組用戶(g) 增加執(zhí)行權(quán)限

其他用戶(o) 增加執(zhí)行權(quán)限

例2:

$ chmod ug+w,o-x text

即設(shè)定文件text的屬性為:

文件屬主(u) 增加寫(xiě)權(quán)限

與文件屬主同組用戶(g) 增加寫(xiě)權(quán)限

其他用戶(o) 刪除執(zhí)行權(quán)限

例3:

$ chmod u+s a.out

假設(shè)執(zhí)行chmod后a.out的權(quán)限為(可以用ls – l a.out命令來(lái)看):

–rws--x--x 1 inin users 7192 Nov 4 14:22 a.out

并且這個(gè)執(zhí)行文件要用到一個(gè)文本文件shiyan1.c,其文件存取權(quán)限為“–rw——-”,即該文件只有其屬主具有讀寫(xiě)權(quán)限。

當(dāng)其他用戶執(zhí)行a.out這個(gè)程序時(shí),他的身份因這個(gè)程序暫時(shí)變成inin(由于chmod命令中使用了s選項(xiàng)),所以他就能夠讀取shiyan1.c這個(gè)文件(雖然這個(gè)文件被設(shè)定為其他人不具備任何權(quán)限),這就是s的功能。

因此,在整個(gè)系統(tǒng)中特別是root本身,最好不要過(guò)多的設(shè)置這種類(lèi)型的文件(除非必要)這樣可以保障系統(tǒng)的安全,避免因?yàn)槟承┏绦虻腷ug而使系統(tǒng)遭到入侵。

例4:

  • <span class="pln">$ chmod a<span class="pun">–<span class="pln">x mm<span class="pun">.<span class="pln">txt</span></span></span></span></span>

  • $ chmod x mm.txt

  • $ chmod ugox mm.txt

以上這三個(gè)命令都是將文件mm.txt的執(zhí)行權(quán)限刪除,它設(shè)定的對(duì)象為所有使用者。

chgrp命令

功能:改變文件或目錄所屬的組。

語(yǔ)法:chgrp [選項(xiàng)] group filename?

參數(shù):

  • -c或–changes 效果類(lèi)似”-v”參數(shù),但僅回報(bào)更改的部分。
  • -f或–quiet或–silent  不顯示錯(cuò)誤信息。
  • -h或–no-dereference  只對(duì)符號(hào)連接的文件作修改,而不更動(dòng)其他任何相關(guān)文件。
  • -R或–recursive  遞歸處理,將指定目錄下的所有文件及子目錄一并處理。
  • -v或–verbose  顯示指令執(zhí)行過(guò)程。
  • –help  在線幫助。
  • –reference=<參考文件或目錄>  把指定文件或目錄的所屬群組全部設(shè)成和參考文件或目錄的所屬群組相同。
  • –version  顯示版本信息。

該命令改變指定指定文件所屬的用戶組。其中g(shù)roup可以是用戶組ID,也可以是/etc/group文件中用戶組的組名。文件名是以空格分開(kāi)的要改變屬組的文件列表,支持通配符。如果用戶不是該文件的屬主或超級(jí)用戶,則不能改變?cè)撐募慕M。

該命令的各選項(xiàng)含義為:

– R 遞歸式地改變指定目錄及其下的所有子目錄和文件的屬組。

例1:

$ chgrp - R book /opt/local /book

改變/opt/local /book/及其子目錄下的所有文件的屬組為book。

chown 命令

功能:更改某個(gè)文件或目錄的屬主和屬組。這個(gè)命令也很常用。例如root用戶把自己的一個(gè)文件拷貝給用戶yusi,為了讓用戶yusi能夠存取這個(gè)文件,root用戶應(yīng)該把這個(gè)文件的屬主設(shè)為yusi,否則,用戶yusi無(wú)法存取這個(gè)文件。

語(yǔ)法:chown [選項(xiàng)] 用戶或組 文件

說(shuō)明:chown將指定文件的擁有者改為指定的用戶或組。用戶可以是用戶名或用戶ID。組可以是組名或組ID。文件是以空格分開(kāi)的要改變權(quán)限的文件列表,支持通配符。

參數(shù)說(shuō)明:

  • user : 新的檔案擁有者的使用者 ID
  • group : 新的檔案擁有者的使用者群體(group)
  • -c : 若該檔案擁有者確實(shí)已經(jīng)更改,才顯示其更改動(dòng)作
  • -f : 若該檔案擁有者無(wú)法被更改也不要顯示錯(cuò)誤訊息
  • -h : 只對(duì)于連結(jié)(link)進(jìn)行變更,而非該 link 真正指向的檔案
  • -v : 顯示擁有者變更的詳細(xì)資料
  • -R : 對(duì)目前目錄下的所有檔案與子目錄進(jìn)行相同的擁有者變更(即以遞回的方式逐個(gè)變更)
  • –help : 顯示輔助說(shuō)明
  • –version : 顯示版本

例1:把文件yusi123.com的所有者改為yusi。

$ chown yusi yusi123.com

例2:把目錄/demo及其下的所有文件和子目錄的屬主改成yusi,屬組改成users。

$ chown - R yusi.users /demo

例如:chown qq /home/qq (把home目錄下的qq目錄的擁有者改為qq用戶)

例如:chown -R qq /home/qq (把home目錄下的qq目錄下的所有子文件的擁有者改為qq用戶)

linux修改文件的時(shí)間

命令是:touch

Linux系統(tǒng)文件創(chuàng)建的時(shí)間并不是不能修改的,通過(guò)touch命令可以修改文件的時(shí)間,從而達(dá)到以假亂真的效果。

實(shí)例:將系統(tǒng)里某些文件修改為三個(gè)月前的時(shí)間:

當(dāng)前系統(tǒng)文件信息如下:

[root@case test]# ls -l
total 28
drwxr-xr-x 2 root root 4096 Jan 9 15:47 1333
-rwxrwxr-x 1 oracle oinstall 8143 Jan 9 14:41 3.sh
drwxr-xr-x 2 root root 4096 Jan 9 15:49 444
-rw-r--r-- 1 root root 0 Jan 9 14:41 4.sh
-rwxr-xr-x 1 root root 8143 Jan 9 14:44 77.sh
-rwxrwxr-x 1 root root 54 Jan 9 16:03 find.sh

把所有的.sh文件修改到三個(gè)月前(2015年10月13)的時(shí)間。操作命令:

[root@case test]# touch -d “10/13/2013” *.sh

結(jié)果是:

[root@case test]# ls -l
total 28
drwxr-xr-x 2 root root 4096 Jan 9 15:47 1333
-rwxrwxr-x 1 oracle oinstall 8143 Oct 13 00:00 3.sh
drwxr-xr-x 2 root root 4096 Jan 9 15:49 444
-rw-r--r-- 1 root root 0 Oct 13 00:00 4.sh
-rwxr-xr-x 1 root root 8143 Oct 13 00:00 77.sh
-rwxrwxr-x 1 root root 54 Oct 13 00:00 find.sh

另外也可以單獨(dú)修改時(shí)間或者月份,如下

以使用 am, pm 或是 24 小時(shí)的格式,日期可以使用其他格式如 6 May 2000 。

touch -d “6:03pm” file
touch -d “05/06/2000” file
touch -d “6:03pm 05/06/2000” file

相關(guān)推薦:《Linux視頻教程

The above is the detailed content of What are the commands to modify files in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to adjust mysql into Chinese interface? Easy to set the Chinese language environment of mysql How to adjust mysql into Chinese interface? Easy to set the Chinese language environment of mysql Jun 04, 2025 pm 06:36 PM

To tune MySQL into a Chinese interface, it can be implemented through MySQLWorkbench or command line tools. 1) In MySQLWorkbench, open "Preferences", select the "Appearance" tab, and then select "Chinese(Simplified)" in the "Language" drop-down menu, and restart. 2) When using command line tools, set the operating system locale variables, such as using "exportLANG=zh_CN.UTF-8" on Linux or macOS, and then run the mysql client.

How does resource usage (CPU, memory) differ between Linux and Windows? How does resource usage (CPU, memory) differ between Linux and Windows? Jun 05, 2025 am 12:13 AM

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

How does the cost of ownership differ between Linux and Windows? How does the cost of ownership differ between Linux and Windows? Jun 09, 2025 am 12:17 AM

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

How does the performance of I/O operations differ between Linux and Windows? How does the performance of I/O operations differ between Linux and Windows? Jun 07, 2025 am 12:06 AM

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications

How to install Linux alongside Windows (dual boot)? How to install Linux alongside Windows (dual boot)? Jun 18, 2025 am 12:19 AM

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

How to enable the EPEL (Extra Packages for Enterprise Linux) repository? How to enable the EPEL (Extra Packages for Enterprise Linux) repository? Jun 17, 2025 am 09:15 AM

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

How does Linux perform compared to Windows for web server workloads? How does Linux perform compared to Windows for web server workloads? Jun 08, 2025 am 12:18 AM

Linux usually performs better in web server performance, mainly due to its advantages in kernel optimization, resource management and open source ecosystem. 1) After years of optimization of the Linux kernel, mechanisms such as epoll and kqueue make it more efficient in handling high concurrent requests. 2) Linux provides fine-grained resource management tools such as cgroups. 3) The open source community continuously optimizes Linux performance, and many high-performance web servers such as Nginx are developed on Linux. By contrast, Windows performs well when handling ASP.NET applications and provides better development tools and commercial support.

How to choose a Linux distro for a beginner? How to choose a Linux distro for a beginner? Jun 19, 2025 am 12:09 AM

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

See all articles

<u id="ccz3y"></u><u id="ccz3y"></u>
    • PermissionValue
      rwx rw- r–764
      rw- r– r–644