mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
1e1fb8c1fa
24
README.md
24
README.md
@ -15,30 +15,26 @@
|
||||
|
||||
LCTT 已经拥有几百名活跃成员,并欢迎更多的 Linux 志愿者加入我们的团队。
|
||||
|
||||
![logo](https://linux.cn/static/image/common/lctt_logo.png)
|
||||
![LCTT](https://lctt.github.io/wiki/images/lctt_logo.png)
|
||||
|
||||
LCTT 的组成
|
||||
-------------------------------
|
||||
|
||||
**选题**,负责选择合适的内容,并将原文转换为 markdown 格式,提交到 LCTT 的 [TranslateProject](https://github.com/LCTT/TranslateProject) 库中。
|
||||
|
||||
**译者**,负责从选题中选择内容进行翻译。
|
||||
|
||||
**校对**,负责将初译的文章进行文字润色、技术校对等工作。
|
||||
|
||||
**发布**,负责将校对后的文章,排版进行发布。
|
||||
- LCTT 官网: [https://linux.cn/lctt/](https://linux.cn/lctt/)
|
||||
- LCTT 状态: [https://lctt.github.io/](https://lctt.github.io/)
|
||||
|
||||
加入我们
|
||||
-------------------------------
|
||||
|
||||
请首先加入翻译组的 QQ 群,群号是:**198889102**,加群时请说明是“*志愿者*”。加入后记得修改您的群名片为您的 GitHub 的 ID。
|
||||
请首先加入翻译组的 QQ 群,群号是:**198889102**,加群时请说明是“*志愿者*”。
|
||||
|
||||
加入的成员,请先阅读 [WIKI 如何开始](https://github.com/LCTT/TranslateProject/wiki/01-如何开始)。
|
||||
加入的成员,请:
|
||||
|
||||
1. 修改你的 QQ 群名片为“译者-您的_GitHub_ID”。
|
||||
2. 阅读 [WIKI](http://lctt.github.io/wiki) 了解如何开始。
|
||||
3. 遇到不解之处,请在群内发问。
|
||||
|
||||
如何开始
|
||||
-------------------------------
|
||||
|
||||
请阅读 [WIKI](https://github.com/LCTT/TranslateProject/wiki)。如需要协助,请在群内发问。
|
||||
请阅读 [WIKI](http://lctt.github.io/wiki)。如需要协助,请在群内发问。
|
||||
|
||||
历史
|
||||
-------------------------------
|
||||
|
@ -1,3 +1,4 @@
|
||||
wxy is translating
|
||||
TLDR pages: Simplified Alternative To Linux Man Pages
|
||||
============================================================
|
||||
|
||||
|
@ -1,155 +0,0 @@
|
||||
Translating by MjSeven
|
||||
|
||||
Users, Groups, and Other Linux Beasts
|
||||
======
|
||||
|
||||
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/flamingo-2458782_1920.jpg?itok=_gkzGGx5)
|
||||
|
||||
Having reached this stage, [after seeing how to manipulate folders/directories][1], but before flinging ourselves headlong into fiddling with files, we have to brush up on the matter of _permissions_ , _users_ and _groups_. Luckily, [there is already an excellent and comprehensive tutorial on this site that covers permissions][2], so you should go and read that right now. In a nutshell: you use permissions to establish who can do stuff to files and directories and what they can do with each file and directory -- read from it, write to it, move it, erase it, etc.
|
||||
|
||||
To try everything this tutorial covers, you'll need to create a new user on your system. Let's be practical and make a user for anybody who needs to borrow your computer, that is, what we call a _guest account_.
|
||||
|
||||
**WARNING:** _Creating and especially deleting users, along with home directories, can seriously damage your system if, for example, you remove your own user and files by mistake. You may want to practice on another machine which is not your main work machine or on a virtual machine. Regardless of whether you want to play it safe, or not, it is always a good idea to back up your stuff frequently, check the backups have worked correctly, and save yourself a lot of gnashing of teeth later on._
|
||||
|
||||
### A New User
|
||||
|
||||
You can create a new user with the `useradd` command. Run `useradd` with superuser/root privileges, that is using `sudo` or `su`, depending on your system, you can do:
|
||||
```
|
||||
sudo useradd -m guest
|
||||
|
||||
```
|
||||
|
||||
... and input your password. Or do:
|
||||
```
|
||||
su -c "useradd -m guest"
|
||||
|
||||
```
|
||||
|
||||
... and input the password of root/the superuser.
|
||||
|
||||
( _For the sake of brevity, we'll assume from now on that you get superuser/root privileges by using`sudo`_ ).
|
||||
|
||||
By including the `-m` argument, `useradd` will create a home directory for the new user. You can see its contents by listing _/home/guest_.
|
||||
|
||||
Next you can set up a password for the new user with
|
||||
```
|
||||
sudo passwd guest
|
||||
|
||||
```
|
||||
|
||||
Or you could also use `adduser`, which is interactive and asks you a bunch of questions, including what shell you want to assign the user (yes, there are more than one), where you want their home directory to be, what groups you want them to belong to (more about that in a second) and so on. At the end of running `adduser`, you get to set the password. Note that `adduser` is not installed by default on many distributions, while `useradd` is.
|
||||
|
||||
Incidentally, you can get rid of a user with `userdel`:
|
||||
```
|
||||
sudo userdel -r guest
|
||||
|
||||
```
|
||||
|
||||
With the `-r` option, `userdel` not only removes the _guest_ user, but also deletes their home directory and removes their entry in the mailing spool, if they had one.
|
||||
|
||||
### Skeletons at Home
|
||||
|
||||
Talking of users' home directories, depending on what distro you're on, you may have noticed that when you use the `-m` option, `useradd` populates a user's directory with subdirectories for music, documents, and whatnot as well as an assortment of hidden files. To see everything in you guest's home directory run `sudo ls -la /home/guest`.
|
||||
|
||||
What goes into a new user's directory is determined by a skeleton directory which is usually _/etc/skel_. Sometimes it may be a different directory, though. To check which directory is being used, run:
|
||||
```
|
||||
useradd -D
|
||||
GROUP=100
|
||||
HOME=/home
|
||||
INACTIVE=-1
|
||||
EXPIRE=
|
||||
SHELL=/bin/bash
|
||||
SKEL=/etc/skel
|
||||
CREATE_MAIL_SPOOL=no
|
||||
|
||||
```
|
||||
|
||||
This gives you some extra interesting information, but what you're interested in right now is the `SKEL=/etc/skel` line. In this case, and as is customary, it is pointing to _/etc/skel/_.
|
||||
|
||||
As everything is customizable in Linux, you can, of course, change what gets put into a newly created user directory. Try this: Create a new directory in _/etc/skel/_ :
|
||||
```
|
||||
sudo mkdir /etc/skel/Documents
|
||||
|
||||
```
|
||||
|
||||
And create a file containing a welcome text and copy it over:
|
||||
```
|
||||
sudo cp welcome.txt /etc/skel/Documents
|
||||
|
||||
```
|
||||
|
||||
Now delete the guest account:
|
||||
```
|
||||
sudo userdel -r guest
|
||||
|
||||
```
|
||||
|
||||
And create it again:
|
||||
```
|
||||
sudo useradd -m guest
|
||||
|
||||
```
|
||||
|
||||
Hey presto! Your _Documents/_ directory and _welcome.txt_ file magically appear in the guest's home directory.
|
||||
|
||||
You can also modify other things when you create a user by editing _/etc/default/useradd_. Mine looks like this:
|
||||
```
|
||||
GROUP=users
|
||||
HOME=/home
|
||||
INACTIVE=-1
|
||||
EXPIRE=
|
||||
SHELL=/bin/bash
|
||||
SKEL=/etc/skel
|
||||
CREATE_MAIL_SPOOL=no
|
||||
|
||||
```
|
||||
|
||||
Most of these options are self-explanatory, but let's take a closer look at the `GROUP` option.
|
||||
|
||||
### Herd Mentality
|
||||
|
||||
Instead of assigning permissions and privileges to users one by one, Linux and other Unix-like operating systems rely on _groups_. A group is a what you imagine it to be: a bunch of users that are related in some way. On your system you may have a group of users that are allowed to use the printer. They would belong to the _lp_ (for " _line printer_ ") group. The members of the _wheel_ group were traditionally the only ones who could become superuser/root by using _su_. The _network_ group of users can bring up and power down the network. And so on and so forth.
|
||||
|
||||
Different distributions have different groups and groups with the same or similar names have different privileges also depending on the distribution you are using. So don't be surprised if what you read in the prior paragraph doesn't match what is going on in your system.
|
||||
|
||||
Either way, to see which groups are on your system you can use:
|
||||
```
|
||||
getent group
|
||||
|
||||
```
|
||||
|
||||
The `getent` command lists the contents of some of the system's databases.
|
||||
|
||||
To find out which groups your current user belongs to, try:
|
||||
```
|
||||
groups
|
||||
|
||||
```
|
||||
|
||||
When you create a new user with `useradd`, unless you specify otherwise, the user will only belong to one group: their own. A _guest_ user will belong to a _guest_ group and the group gives the user the power to administer their own stuff and that is about it.
|
||||
|
||||
You can create new groups and then add users to them at will with the `groupadd` command:
|
||||
```
|
||||
sudo groupadd photos
|
||||
|
||||
```
|
||||
|
||||
will create the _photos_ group, for example. Next time, we’ll use this to build a shared directory all members of the group can read from and write to, and we'll learn even more about permissions and privileges. Stay tuned!
|
||||
|
||||
Learn more about Linux through the free ["Introduction to Linux" ][3]course from The Linux Foundation and edX.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linux.com/users/bro66
|
||||
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
|
||||
[2]:https://www.linux.com/learn/understanding-linux-file-permissions
|
||||
[3]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|
@ -1,153 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Four Easy Ways to Search Or Find Files And Folders in Linux)
|
||||
[#]: via: (https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
Four Easy Ways to Search Or Find Files And Folders in Linux
|
||||
======
|
||||
|
||||
Linux admins can’t able to leave a day without performing a file search as this one of the activity for their routine.
|
||||
|
||||
It’s good to know all the file search stuffs because it would help you in many ways when you are working on headless server.
|
||||
|
||||
These commands are not complicate to remember because these are using a standard syntax.
|
||||
|
||||
This can be performed through Four Linux commands and each command has their own unique feature.
|
||||
|
||||
### Method-1: Search Files And Folders in Linux Using find Command
|
||||
|
||||
Find command is widely used and very famous command to search files and folders in Linux. It searches given files in the current directory and recursively through its sub-directories based on the search criteria.
|
||||
|
||||
It allow users to perform all kind of file searches based on the criteria lie by size, name, owner, group, type, permissions, date, and other criteria.
|
||||
|
||||
Run the following command to find a given file in system.
|
||||
|
||||
```
|
||||
# find / -iname "sshd_config"
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
Run the following command to find a given folder in system. To search a folder in Linux we need to use `-type` parameter.
|
||||
|
||||
```
|
||||
# find / -type d -iname "ssh"
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/etc/ssh
|
||||
```
|
||||
|
||||
Use wildcard option to search set of files on your system. We are going to search all files available in the system with `.config` extension.
|
||||
|
||||
```
|
||||
# find / -name "*.config"
|
||||
/usr/lib/mono/gac/avahi-sharp/1.0.0.0__4d116c78973743f5/avahi-sharp.dll.config
|
||||
/usr/lib/mono/gac/avahi-ui-sharp/0.0.0.0__4d116c78973743f5/avahi-ui-sharp.dll.config
|
||||
/usr/lib/python2.7/config/Setup.config
|
||||
/usr/share/git/mw-to-git/t/test.config
|
||||
/var/lib/lightdm/.config
|
||||
/home/daygeek/.config
|
||||
/root/.config
|
||||
/etc/skel/.config
|
||||
```
|
||||
|
||||
Use the following command format to find an empty files and folders in system.
|
||||
|
||||
```
|
||||
# find / -empty
|
||||
```
|
||||
|
||||
Use the following command combination to find all files containing specific text on Linux.
|
||||
|
||||
```
|
||||
# find / -type f -exec grep "Port 22" '{}' \; -print
|
||||
# find / -type f -print | xargs grep "Port 22"
|
||||
# find / -type f | xargs grep 'Port 22'
|
||||
# find / -type f -exec grep -H 'Port 22' {} \;
|
||||
```
|
||||
|
||||
### Method-2: Search Files And Folders in Linux Using locate command
|
||||
|
||||
locate command works faster than the find command because it uses updatedb database, whereas the find command searches in the real system.
|
||||
|
||||
It uses a database rather than hunting individual directory paths to get a given file.
|
||||
|
||||
locate command doesn’t pre-installed in most of the distributions so, use your distribution package manager to install it.
|
||||
|
||||
The database is updated regularly through cron, however we can manually update it by running the following command.
|
||||
|
||||
```
|
||||
$ sudo updatedb
|
||||
```
|
||||
|
||||
Simply run the following command to list the given file or folder. There is no specific options need to be specified in locate command to print file or folder.
|
||||
|
||||
To search `ssh` folder in system.
|
||||
|
||||
```
|
||||
# locate --basename '\ssh'
|
||||
/etc/ssh
|
||||
/usr/bin/ssh
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/src/cmd/go/testdata/failssh/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
```
|
||||
|
||||
To search `ssh_config` file in system.
|
||||
|
||||
```
|
||||
# locate --basename '\sshd_config'
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
### Method-3: Search Files in Linux Using which command
|
||||
|
||||
TThe which command returns the full path of the executable that would have been executed when the command had been entered in terminal.
|
||||
|
||||
It’s very useful when you want to create a desktop shortcut or symbolic link for executable files.
|
||||
|
||||
Which command searches the directories listed in the current user’s PATH environment variable not for all the users. I mean, when you are logged in your own account and you can’t able to search for root user file or directory.
|
||||
|
||||
Run the following command to print the full path of the vim executable file location.
|
||||
|
||||
```
|
||||
# which vi
|
||||
/usr/bin/vi
|
||||
```
|
||||
|
||||
Alternatively, it’s allowing user to perform multiple file search in one shot.
|
||||
|
||||
```
|
||||
# which -a vi sudo
|
||||
/usr/bin/vi
|
||||
/bin/vi
|
||||
/usr/bin/sudo
|
||||
/bin/sudo
|
||||
```
|
||||
|
||||
### Method-4: Search Files in Linux Using whereis command
|
||||
|
||||
The whereis command used to search the binary, source, and man page files for a given command.
|
||||
|
||||
```
|
||||
# whereis vi
|
||||
vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (HankChow)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,139 @@
|
||||
用户,组和其他 Linux 用户
|
||||
======
|
||||
|
||||
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/flamingo-2458782_1920.jpg?itok=_gkzGGx5)
|
||||
|
||||
到这个阶段,[在看到如何操作目录或文件夹之后][1],但在让自己一头扎进文件之前,我们必须重新审视 _权限_, _users_ 和 _group_。幸运的是,[有一个网站上已经有了一个优秀而全面的教程,包括了权限][2],所以你应该去立刻阅读它。简而言之,你使用权限来确定谁可以对文件和目录执行操作,以及他们可以对每个文件和目录执行什么操作 -- 从中读取,写入,擦除等等。
|
||||
|
||||
要尝试本教程涵盖的所有内容,你需要在系统上创建新用户。让我们实践起来,为每一个需要借用你电脑的人创建一个用户,我们称之为 _guest 账户_。
|
||||
|
||||
**警告:** _例如,如果你错误地删除了自己的用户和目录,那么创建,特别是删除用户以及主目录会严重损坏系统。你可能不想在你日常的工作机中练习,那么请在另一台机器或者虚拟机上练习。无论你是否想要安全地练习,经常备份你的东西总是一个好主意。检查备份是否正常工作,为你自己以后避免很多咬牙切齿的事情。_
|
||||
|
||||
### 一个新用户
|
||||
|
||||
你可以使用 `useradd` 命令来创建一个新用户。使用超级用户或 root 权限运行 `useradd`,即使用 `sudo` 或 `su`,这具体取决于你的系统,你可以:
|
||||
```
|
||||
sudo useradd -m guest
|
||||
```
|
||||
|
||||
然后输入你的密码。或者也可以这样:
|
||||
```
|
||||
su -c "useradd -m guest"
|
||||
```
|
||||
|
||||
然后输入 root 或超级用户的密码。
|
||||
|
||||
(_为了简洁起见,我们将从现在开始假设你使用 `sudo` 获得超级用户或 root 权限。_)
|
||||
|
||||
通过使用 `-m` 参数,`useradd` 将为新用户创建一个主目录。你可以通过列出 _/home/guest_ 来查看其内容。
|
||||
|
||||
然后你可以使用以下命令来为新用户设置密码:
|
||||
```
|
||||
sudo passwd guest
|
||||
```
|
||||
|
||||
或者你也可以使用 `adduser`,这是一个交互式的命令,它会询问你一些问题,包括你要为用户分配的 shell(是的,不止一个),你希望其主目录在哪里,你希望他们属于哪些组(有关这点稍后会讲到)等等。在运行 `adduser` 结束时,你可以设置密码。注意,默认情况下,在许多发行版中都没有安装 `adduser`,但安装了 `useradd`。
|
||||
|
||||
顺便说一下,你可以使用 `userdel` 来移除一个用户:
|
||||
```
|
||||
sudo userdel -r guest
|
||||
```
|
||||
|
||||
使用 `-r` 选项,`userdel` 不仅删除了 _guest_ 用户,还删除了他们的主目录和邮件中的条目(如果有的话)。
|
||||
|
||||
### home 中的内容
|
||||
|
||||
谈到用户的主目录,它依赖于你所使用的发行版。你可能已经注意到,当你使用 `-m` 选项时,`useradd` 使用子目录填充用户的目录,包括音乐,文档和诸如此类的内容以及各种各样的隐藏文件。要查看 guest 主目录中的所有内容,运行 `sudo ls -la /home/guest`。
|
||||
|
||||
进入新用户目录的内容通常是由 _/etc/skel_ 架构目录确定的。有时它可能是一个不同的目录。要检查正在使用的目录,运行:
|
||||
```
|
||||
useradd -D
|
||||
GROUP=100
|
||||
HOME=/home
|
||||
INACTIVE=-1
|
||||
EXPIRE=
|
||||
SHELL=/bin/bash
|
||||
SKEL=/etc/skel
|
||||
CREATE_MAIL_SPOOL=no
|
||||
```
|
||||
|
||||
这给你一些额外的有趣信息,但你现在感兴趣的是 `SKEL=/etc/skel` 这一行,在这种情况下,按照惯例,它指向 _/etc/skel/_。
|
||||
|
||||
由于 Linux 中的所有东西都是可定制的,因此你可以更改那些放入新创建的用户目录的内容。试试这样做:在 _/etc/skel/_ 中创建一个新目录:
|
||||
```
|
||||
sudo mkdir /etc/skel/Documents
|
||||
```
|
||||
|
||||
然后创建一个包含欢迎消息的文件,并将其复制过来:
|
||||
```
|
||||
sudo cp welcome.txt /etc/skel/Documents
|
||||
```
|
||||
|
||||
现在删除 guest 账户:
|
||||
```
|
||||
sudo userdel -r guest
|
||||
```
|
||||
|
||||
再次创建:
|
||||
```
|
||||
sudo useradd -m guest
|
||||
```
|
||||
|
||||
嘿 presto!(to 校正:这个 presto 是什么?)你的 _Documents/_ 目录和 _welcome.txt_ 文件神奇地出现在了 guest 的主目录中。
|
||||
|
||||
你还可以在创建用户时通过编辑 _/etc/default/useradd_ 来修改其他内容。我的看起来像这样:
|
||||
```
|
||||
GROUP=users
|
||||
HOME=/home
|
||||
INACTIVE=-1
|
||||
EXPIRE=
|
||||
SHELL=/bin/bash
|
||||
SKEL=/etc/skel
|
||||
CREATE_MAIL_SPOOL=no
|
||||
```
|
||||
|
||||
这些选项大多数都是不言自明的,但让我们仔细看看 `GROUP` 选项。
|
||||
|
||||
### 群组心态
|
||||
|
||||
Linux 和其他类 Unix 操作系统依赖于 _groups_,而不是逐个为用户分配权限和特权。一个组就是你想象的那样:一群在某种程度上相关的用户。在你的系统上可能有一组允许使用打印机的用户,他们属于 _lp_(即 "_line printer_")组。传统上 _wheel_ 组的成员是唯一可以通过使用 _su_ 成为超级用户或 root 的成员。_network_ 用户组可以启动或关闭网络。还有许多诸如此类的。
|
||||
|
||||
不同的发行版有不同的组,具有相同或相似名称的组具有不同的权限,这也取决于你使用的发行版。因此,如果你在前一段中读到的内容与你系统中的内容不匹配,不要感到惊讶。
|
||||
|
||||
不管怎样g,要查看系统中有哪些组,你可以使用:
|
||||
```
|
||||
getent group
|
||||
```
|
||||
|
||||
`getent` 命令列出了某些系统数据库的内容。
|
||||
|
||||
要查找当前用户所属的组,尝试:
|
||||
```
|
||||
groups
|
||||
```
|
||||
|
||||
当你使用 `useradd` 创建新用户时,除非你另行指定,否则用户讲只属于一个组:他们自己。一个 _guest_ 用户属于 _guest_ 组。组使用户有权管理自己的东西,仅此而已。
|
||||
|
||||
你可以使用 `groupadd` 命令创建新组,然后添加用户:
|
||||
```
|
||||
sudo groupadd photos
|
||||
```
|
||||
|
||||
例如,这将创建 _photos_ 组。下一次,我们将使用它来构建一个共享目录,该组的所有成员都可以读取和写入,我们将更多地了解权限和特权。敬请关注!
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linux.com/users/bro66
|
||||
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
|
||||
[2]:https://www.linux.com/learn/understanding-linux-file-permissions
|
||||
[3]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|
@ -0,0 +1,153 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Four Easy Ways to Search Or Find Files And Folders in Linux)
|
||||
[#]: via: (https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
四种简单的方法来搜索或查找 Linux 中的文件和文件夹
|
||||
======
|
||||
|
||||
Linux 管理员一天都不能离开搜索文件,因为这是他们的日常活动。
|
||||
|
||||
了解一些搜索的东西是不错的,因为这能帮助你在命令行服务器中工作。
|
||||
|
||||
这些命令记忆起来不复杂,因为它们使用的是标准语法。
|
||||
|
||||
这里执行四个 Linux 命令,每个命令都有自己独特的功能。
|
||||
|
||||
### 方法 1:使用 find 命令在 Linux 中搜索文件和文件夹
|
||||
|
||||
find 命令被广泛使用,并且是非常著名的在 Linux 中搜索文件和文件夹的命令。它搜索当前目录中的给定文件,并根据搜索条件递归遍历其子目录。
|
||||
|
||||
它允许用户根据大小、名称、所有者、组、类型、权限、日期和其他条件执行所有类型的文件搜索。
|
||||
|
||||
运行以下命令以在系统中查找给定文件。
|
||||
|
||||
```
|
||||
# find / -iname "sshd_config"
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
运行以下命令以查找系统中的给定文件夹。要在 Linux 中搜索文件夹,我们需要使用 `-type` 参数。
|
||||
|
||||
```
|
||||
# find / -type d -iname "ssh"
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/etc/ssh
|
||||
```
|
||||
|
||||
使用通配符搜索系统上的所有文件。我们将搜索系统中所有以 `.config` 为扩展名的文件。
|
||||
|
||||
```
|
||||
# find / -name "*.config"
|
||||
/usr/lib/mono/gac/avahi-sharp/1.0.0.0__4d116c78973743f5/avahi-sharp.dll.config
|
||||
/usr/lib/mono/gac/avahi-ui-sharp/0.0.0.0__4d116c78973743f5/avahi-ui-sharp.dll.config
|
||||
/usr/lib/python2.7/config/Setup.config
|
||||
/usr/share/git/mw-to-git/t/test.config
|
||||
/var/lib/lightdm/.config
|
||||
/home/daygeek/.config
|
||||
/root/.config
|
||||
/etc/skel/.config
|
||||
```
|
||||
|
||||
使用以下命令格式在系统中查找空文件和文件夹。
|
||||
|
||||
```
|
||||
# find / -empty
|
||||
```
|
||||
|
||||
使用以下命令组合查找 Linux 上包含特定文本的所有文件。
|
||||
|
||||
```
|
||||
# find / -type f -exec grep "Port 22" '{}' \; -print
|
||||
# find / -type f -print | xargs grep "Port 22"
|
||||
# find / -type f | xargs grep 'Port 22'
|
||||
# find / -type f -exec grep -H 'Port 22' {} \;
|
||||
```
|
||||
|
||||
### 方法 2:使用 locate 命令在 Linux 中搜索文件和文件夹
|
||||
|
||||
locate 命令比 find 命令运行得更快,因为它使用 updatedb 数据库,而 find 命令在真实系统中搜索。
|
||||
|
||||
它使用数据库而不是搜索单个目录路径来获取给定文件。
|
||||
|
||||
locate 命令未在大多数发行版中预安装,因此,请使用你的包管理器进行安装。
|
||||
|
||||
数据库通过 cron 定期更新,但我们可以通过运行以下命令手动更新它。
|
||||
|
||||
```
|
||||
$ sudo updatedb
|
||||
```
|
||||
|
||||
只需运行以下命令即可列出给定的文件或文件夹。在 locate 命令中不需要指定特定选项来打印文件或文件夹。
|
||||
|
||||
在系统中搜索 `ssh` 文件夹。
|
||||
|
||||
```
|
||||
# locate --basename '\ssh'
|
||||
/etc/ssh
|
||||
/usr/bin/ssh
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/src/cmd/go/testdata/failssh/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
```
|
||||
|
||||
在系统中搜索 `ssh_config` 文件。
|
||||
|
||||
```
|
||||
# locate --basename '\sshd_config'
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
### 方法 3:在 Linux 中搜索文件使用 which 命令
|
||||
|
||||
which 返回在终端输入命令时执行的可执行文件的完整路径。
|
||||
|
||||
当你想要为可执行文件创建桌面快捷方式或符号链接时,它非常有用。
|
||||
|
||||
which 命令搜索当前用户而不是所有用户的 PATH 环境变量中列出的目录。我的意思是,当你登录自己的帐户时,你无法搜索 root 用户文件或目录。
|
||||
|
||||
运行以下命令以打印 vim 可执行文件的完整路径。
|
||||
|
||||
```
|
||||
# which vi
|
||||
/usr/bin/vi
|
||||
```
|
||||
|
||||
或者,它允许用户一次执行多个文件搜索。
|
||||
|
||||
```
|
||||
# which -a vi sudo
|
||||
/usr/bin/vi
|
||||
/bin/vi
|
||||
/usr/bin/sudo
|
||||
/bin/sudo
|
||||
```
|
||||
|
||||
### 方法 4:使用 whereis 命令在 Linux 中搜索文件
|
||||
|
||||
whereis 命令用于搜索给定命令的二进制、源码和手册页文件。
|
||||
|
||||
```
|
||||
# whereis vi
|
||||
vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
Loading…
Reference in New Issue
Block a user