首页 > 系统相关 >Linux 笔记

Linux 笔记

时间:2023-12-10 17:46:30浏览次数:29  
标签:shell filesystem 笔记 command same Linux root find

What does "{} ;" mean in the find command?

If you run find with exec{} expands to the filename of each file or directory found with find (so that ls in your example gets every found filename as an argument - note that it calls ls or whatever other command you specify once for each file found).

Semicolon ; ends the command executed by exec. It needs to be escaped with \ so that the shell you run find inside does not treat it as its own special character, but rather passes it to find.

See this article for some more details.


Also, find provides some optimization with exec cmd {} + - when run like that, find appends found files to the end of the command rather than invoking it once per file (so that the command is run only once, if possible).

The difference in behavior (if not in efficiency) is easily noticeable if run with ls, e.g.

find ~ -iname '*.jpg' -exec ls {} \;
# vs
find ~ -iname '*.jpg' -exec ls {} +

Assuming you have some jpg files (with short enough paths), the result is one line per file in first case and standard ls behavior of displaying files in columns for the latter.

What is the difference of cp -p and cp -a in UNIX?

With the -p option, the copy has the same modification time, the same access time, and the same permissions as the original. It also has the same owner and group as the original, if the user doing the copy has the permission to create such files.

The -a option means -R and -p, plus a few other preservation options. It attempts to make a copy that's as close to the original as possible: same directory tree, same file types, same contents, same metadata (times, permissions, extended attributes, etc.).

What is the chroot command used for when resetting a password in RHEL/CentOS 7?

You're talking about the procedure to reset a lost root password. This is needed only when the root password is lost and there is no sudo root access or similar available.

At boot, the bootloader (usually GRUB) loads 2 files: the kernel and the initramfs (also known as initrd) file. The initramfs file contains a minimal filesystem that includes any tools and kernel modules required to activate the real root filesystem, its disk controller(s) and other features necessary to activate it (e.g. any combination of: LVM, disk encryption, multipathing and/or software RAID).

The rd.break boot option tells the boot sequence to stop while the system is still using initramfs, but the real root filesystem is already mounted at /sysroot. Normally the next step would be a pivot_root operation to switch /sysroot into a real root filesystem, start executing stuff from there and then remove the initramfs from memory.

By stopping within the initramfs we gain access to the emergency shell. But the initramfs has a very limited number of commands available, and editing the initramfs's /etc/passwd file would achieve nothing as the entire initramfs gets replaced by the real root filesystem anyway.

The root filesystem is initially mounted in read-only mode in order to allow filesystem checking. The first step is to remount it read-write, to allow the password change to stick.

The chroot /sysroot command means: "start a new shell in such a way that for that shell the /sysroot directory will appear as /." Within that chrooted shell, /etc/passwd and /etc/shadow will refer to the real password files in the real root filesystem, and /bin/passwd will be the same command you'll use when the system is running normally. Since this chrooted shell was started from the emergency shell, you already have full root access, and you can use the passwd command to set a new password for anyone without being asked for the old one first - including setting a new root password.

Once the procedure is complete, the first exit command will exit the chrooted shell and return you to the initial emergency shell, which still sees the real root filesystem as /sysroot. The second exit command will return control to the boot scripts, which usually trigger a reboot whenever emergency shell has been used.

Was this the sort of explanation you needed?

What is chroot Linux sys call and How to Control It: Sandbox with Seccomp | by Seifeddine Rajhi | Medium --- 什么是 chroot Linux sys 调用以及如何控制它:使用 Seccomp 的沙盒 |由 Seifeddine Rajhi |中等

标签:shell,filesystem,笔记,command,same,Linux,root,find
From: https://www.cnblogs.com/ErFu/p/17892962.html

相关文章

  • Linux --- DNS
    一、概要1.环境(1)CentOS7(2)RockyLinux9.1(3)RockyLinux9.3二、配置1.配置文件(1)DNS的配置文件位于:/etc/resolv.conf从CentOS7开始,该文件由NetworkManager维护,可直接修改,也可以通过nmcli命令来修改。(2)NetworkManger服务systemctlstatusNetworkMa......
  • 4、Linux学习之文件权限(二)
    二、基本权限ACLACL(AccessControlList)为访问控制列表。ACL可以设置特定用户或用户组对于一个文件或文件夹的操作权限。 即ACL用于设定某个用户针对文件的权限。 权限的优先级顺序:所有者-->ACL自定义用户-->ACL自定义组-->其他人1、查看ACL权限:getfacl命令2、设置ACL权......
  • Adaptive Graph Contrastive Learning for Recommendation论文阅读笔记
    Abstract在实际的场景中,用户的行为数据往往是有噪声的,并且表现出偏态分布。所以需要利用自监督学习来改善用户表示。我们提出了一种新的自适应图对比学习(AdaGCL)框架,该框架使用两个自适应对比视图生成器来进行数据增强,以更好地增强CF范式。具体的说,我们使用了两个可训练的视图生......
  • C++学习笔记四:变量与数据类型(布尔型)
    今天来整理一下布尔型变量的使用方法1.声明和初始化一个布尔类型的变量占据1Byte空间,数值0代表false,其他非0数值代表trueboolred_light{false};boolgreen_light{true};std::cout<<"sizeof(bool):"<<sizeof(bool)<<std::endl; 2.打印一个布尔变量std::......
  • Linux课程随笔(五)
    作为一名计算机专业的学生,深入学习Linux操作系统的进程管理是至关重要的一部分。在本篇博客中,我们将深入探讨Linux系统中进程的概念、创建、管理以及监控。通过对进程管理的学习,我们可以更好地理解操作系统的运行机制,提高系统管理和调优的技能。什么是进程?在计算机科学中,进程是......
  • Linux课程随笔(四)
    Linux操作系统以其稳定性和安全性而闻名,文件权限是Linux系统中重要的安全机制之一。本篇博客将介绍Linux文件的基本权限概念以及如何使用命令行进行文件权限的管理。文件权限概述在Linux中,每个文件都有一组权限,用于定义文件的访问规则。这组权限分为三个部分:用户(Owner)、群组(Grou......
  • Linux课程随笔(三)
    在Linux系统中,用户管理是系统管理员和普通用户都需要了解和掌握的重要主题。本篇学习博文将介绍一些基本的Linux用户管理命令,帮助你有效地管理用户账户,确保系统的安全性和稳定性。用户账户基础在Linux系统中,每个用户都有一个唯一的用户名(Username)和一个相关的用户ID(UID)。用户信......
  • Linux课程随笔(八)
    当你希望在Windows操作系统上进行Linux系统的学习或开发时,使用虚拟机是一个理想的选择。VMware是一款强大的虚拟机软件,它允许你在Windows中创建虚拟计算机,从而在其中安装和运行Linux系统。本文将指导你使用VMware在Windows中安装Linux,并提供一些基本的步骤和注意事项。在Windows......
  • Linux课程随笔(七)
    在Linux操作系统中,I/O(输入/输出)重定向和管道是强大的工具,它们允许用户有效地处理命令之间的输入和输出流。本篇博客将深入探讨Linux中的I/O重定向和管道的概念,以及如何利用它们来提高命令行的灵活性和效率。I/O重定向什么是I/O重定向?I/O重定向是一种将命令的输入和输出流导向......
  • Linux课程随笔(六)
    作为一名计算机专业的学生,深入了解操作系统是必不可少的一部分。在众多操作系统中,Linux因其开放源代码、稳定性和灵活性而备受欢迎。本文将聚焦于Linux的存储管理,深入探讨文件系统、磁盘管理以及存储优化等方面的知识。文件系统1.文件系统概述在Linux中,文件系统是组织和存储数......