Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2019-05-20 17:30:01 +08:00
commit bb4ec45625
8 changed files with 1045 additions and 322 deletions

View File

@ -1,81 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Check your spelling at the command line with Ispell)
[#]: via: (https://opensource.com/article/19/5/spelling-command-line-ispell)
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt)
Check your spelling at the command line with Ispell
======
Ispell helps you stamp out typos in plain text files written in more
than 50 languages.
![Command line prompt][1]
Good spelling is a skill. A skill that takes time to learn and to master. That said, there are people who never quite pick that skill up—I know a couple or three outstanding writers who can't spell to save their lives.
Even if you spell well, the occasional typo creeps in. That's especially true if you're quickly banging on your keyboard to meet a deadline. Regardless of your spelling chops, it's always a good idea to run what you've written through a spelling checker.
I do most of my writing in [plain text][2] and often use a command line spelling checker called [Aspell][3] to do the deed. Aspell isn't the only game in town. You might also want to check out the venerable [Ispell][4].
### Getting started
Ispell's been around, in various forms, since 1971. Don't let its age fool you. Ispell is still a peppy application that you can use effectively in the 21st century.
Before doing anything else, check whether or not Ispell is installed on your computer by cracking open a terminal window and typing **which ispell**. If it isn't installed, fire up your distribution's package manager and install Ispell from there.
Don't forget to install dictionaries for the languages you work in, too. My only language is English, so I just need to worry about grabbing the US and British English dictionaries. You're not limited to my mother (and only) tongue. Ispell has [dictionaries for over 50 languages][5].
![Installing Ispell dictionaries][6]
### Using Ispell
If you haven't guessed already, Ispell only works with text files. That includes ones marked up with HTML, LaTeX, and [nroff or troff][7]. More on this in a few moments.
To get to work, open a terminal window and navigate to the directory containing the file where you want to run a spelling check. Type **ispell** followed by the file's name and then press Enter.
![Checking spelling with Ispell][8]
Ispell highlights the first word it doesn't recognize. If the word is misspelled, Ispell usually offers one or more alternatives. Press **R** and then the number beside the correct choice. In the screen capture above, I'd press **R** and **0** to fix the error.
If, on the other hand, the word is correctly spelled, press **A** to move to the next misspelled word.
Keep doing that until you reach the end of the file. Ispell saves your changes, creates a backup of the file you just checked (with the extension _.bak_ ), and shuts down.
### A few other options
This example illustrates basic Ispell usage. The program has a [number of options][9], some of which you _might_ use and others you _might never_ use. Let's take a quick peek at some of the ones I regularly use.
A few paragraphs ago, I mentioned that Ispell works with certain markup languages. You need to tell it a file's format. When starting Ispell, add **-t** for a TeX or LaTeX file, **-H** for an HTML file, or **-n** for a groff or troff file. For example, if you enter **ispell -t myReport.tex** , Ispell ignores all markup.
If you don't want the backup file that Ispell creates after checking a file, add **-x** to the command line—for example, **ispell -x myFile.txt**.
What happens if Ispell runs into a word that's spelled correctly but isn't in its dictionary, like a proper name? You can add that word to a personal word list by pressing **I**. This saves the word to a file called _.ispell_default_ in the root of your _/home_ directory.
Those are the options I find most useful when working with Ispell, but check out [Ispell's man page][9] for descriptions of all its options.
Is Ispell any better or faster than Aspell or any other command line spelling checker? I have to say it's no worse than any of them, nor is it any slower. Ispell's not for everyone. It might not be for you. But it is good to have options, isn't it?
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/spelling-command-line-ispell
作者:[Scott Nesbitt ][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://opensource.com/users/scottnesbitt
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/command_line_prompt.png?itok=wbGiJ_yg (Command line prompt)
[2]: https://plaintextproject.online
[3]: https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell
[4]: https://www.cs.hmc.edu/~geoff/ispell.html
[5]: https://www.cs.hmc.edu/~geoff/ispell-dictionaries.html
[6]: https://opensource.com/sites/default/files/uploads/ispell-install-dictionaries.png (Installing Ispell dictionaries)
[7]: https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-me
[8]: https://opensource.com/sites/default/files/uploads/ispell-checking.png (Checking spelling with Ispell)
[9]: https://www.cs.hmc.edu/~geoff/ispell-man.html

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,240 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (Moelf)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Using the force at the Linux command line)
[#]: via: (https://opensource.com/article/19/5/may-the-force-linux)
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
Using the force at the Linux command line
======
Like the Jedi Force, -f is powerful, potentially destructive, and very
helpful when you know how to use it.
![Fireworks][1]
Sometime in recent history, sci-fi nerds began an annual celebration of everything [_Star Wars_ on May the 4th][2], a pun on the Jedi blessing, "May the Force be with you." Although most Linux users are probably not Jedi, they still have ways to use the force. Of course, the movie might not have been quite as exciting if Yoda simply told Luke to type **man X-Wing fighter** or **man force**. Or if he'd said, "RTFM" (Read the Force Manual, of course).
Many Linux commands have an **-f** option, which stands for, you guessed it, force! Sometimes when you execute a command, it fails or prompts you for additional input. This may be an effort to protect the files you are trying to change or inform the user that a device is busy or a file already exists.
If you don't want to be bothered by prompts or don't care about errors, use the force!
Be aware that using a command's force option to override these protections is, generally, destructive. Therefore, the user needs to pay close attention and be sure that they know what they are doing. Using the force can have consequences!
Following are four Linux commands with a force option and a brief description of how and why you might want to use it.
### cp
The **cp** command is short for copy—it's used to copy (or duplicate) a file or directory. The [man page][3] describes the force option for **cp** as:
```
-f, --force
if an existing destination file cannot be opened, remove it
and try again
```
This example is for when you are working with read-only files:
```
[alan@workstation ~]$ ls -l
total 8
-rw-rw---- 1 alan alan 13 May 1 12:24 Hoth
-r--r----- 1 alan alan 14 May 1 12:23 Naboo
[alan@workstation ~]$ cat Hoth Naboo
Icy Planet
Green Planet
```
If you want to copy a file called _Hoth_ to _Naboo_ , the **cp** command will not allow it since _Naboo_ is read-only:
```
[alan@workstation ~]$ cp Hoth Naboo
cp: cannot create regular file 'Naboo': Permission denied
```
But by using the force, **cp** will not prompt. The contents and permissions of _Hoth_ will immediately be copied to _Naboo_ :
```
[alan@workstation ~]$ cp -f Hoth Naboo
[alan@workstation ~]$ cat Hoth Naboo
Icy Planet
Icy Planet
[alan@workstation ~]$ ls -l
total 8
-rw-rw---- 1 alan alan 12 May 1 12:32 Hoth
-rw-rw---- 1 alan alan 12 May 1 12:38 Naboo
```
Oh no! I hope they have winter gear on Naboo.
### ln
The **ln** command is used to make links between files. The [man page][4] describes the force option for **ln** as:
```
-f, --force
remove existing destination files
```
Suppose Princess Leia is maintaining a Java application server and she has a directory where all Java versions are stored. Here is an example:
```
leia@workstation:/usr/lib/java$ ls -lt
total 28
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
As you can see, there are several versions of the Java Development Kit (JDK) and a symbolic link pointing to the latest one. She uses a script with the following commands to install new JDK versions. However, it won't work without a force option or unless the root user runs it:
```
tar xvzmf jdk1.8.0_181.tar.gz -C jdk1.8.0_181/
ln -vs jdk1.8.0_181 jdk
```
The **tar** command will extract the .gz file to the specified directory, but the **ln** command will fail to upgrade the link because one already exists. The result will be that the link no longer points to the latest JDK:
```
leia@workstation:/usr/lib/java$ ln -vs jdk1.8.0_181 jdk
ln: failed to create symbolic link 'jdk/jdk1.8.0_181': File exists
leia@workstation:/usr/lib/java$ ls -lt
total 28
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
She can force **ln** to update the link correctly by passing the force option and one other, **-n**. The **-n** is needed because the link points to a directory. Now, the link again points to the latest JDK:
```
leia@workstation:/usr/lib/java$ ln -vsnf jdk1.8.0_181 jdk
'jdk' -> 'jdk1.8.0_181'
leia@workstation:/usr/lib/java$ ls -lt
total 28
lrwxrwxrwx 1 leia leia 12 May 1 16:13 jdk -> jdk1.8.0_181
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
A Java application can be configured to find the JDK with the path **/usr/lib/java/jdk** instead of having to change it every time Java is updated.
### rm
The **rm** command is short for "remove" (which we often call delete, since some other operating systems have a **del** command for this action). The [man page][5] describes the force option for **rm** as:
```
-f, --force
ignore nonexistent files and arguments, never prompt
```
If you try to delete a read-only file, you will be prompted by **rm** :
```
[alan@workstation ~]$ ls -l
total 4
-r--r----- 1 alan alan 16 May 1 11:38 B-wing
[alan@workstation ~]$ rm B-wing
rm: remove write-protected regular file 'B-wing'?
```
You must type either **y** or **n** to answer the prompt and allow the **rm** command to proceed. If you use the force option, **rm** will not prompt you and will immediately delete the file:
```
[alan@workstation ~]$ rm -f B-wing
[alan@workstation ~]$ ls -l
total 0
[alan@workstation ~]$
```
The most common use of force with **rm** is to delete a directory. The **-r** (recursive) option tells **rm** to remove a directory. When combined with the force option, it will remove the directory and all its contents without prompting.
The **rm** command with certain options can be disastrous. Over the years, online forums have filled with jokes and horror stories of users completely wiping their systems. This notorious usage is **rm -rf ***. This will immediately delete all files and directories without any prompt wherever it is used.
### userdel
The **userdel** command is short for user delete, which will delete a user. The [man page][6] describes the force option for **userdel** as:
```
-f, --force
This option forces the removal of the user account, even if the
user is still logged in. It also forces userdel to remove the
user's home directory and mail spool, even if another user uses
the same home directory or if the mail spool is not owned by the
specified user. If USERGROUPS_ENAB is defined to yes in
/etc/login.defs and if a group exists with the same name as the
deleted user, then this group will be removed, even if it is
still the primary group of another user.
Note: This option is dangerous and may leave your system in an
inconsistent state.
```
When Obi-Wan reached the castle on Mustafar, he knew what had to be done. He had to delete Darth's user account—but Darth was still logged in.
```
[root@workstation ~]# ps -fu darth
UID PID PPID C STIME TTY TIME CMD
darth 7663 7655 0 13:28 pts/3 00:00:00 -bash
[root@workstation ~]# userdel darth
userdel: user darth is currently used by process 7663
```
Since Darth is currently logged in, Obi-Wan has to use the force option to **userdel**. This will delete the user account even though it's logged in.
```
[root@workstation ~]# userdel -f darth
userdel: user darth is currently used by process 7663
[root@workstation ~]# finger darth
finger: darth: no such user.
[root@workstation ~]# ps -fu darth
error: user name does not exist
```
As you can see, the **finger** and **ps** commands confirm the user Darth has been deleted.
### Using force in shell scripts
Many other commands have a force option. One place force is very useful is in shell scripts. Since we use scripts in cron jobs and other automated operations, avoiding any prompts is crucial, or else these automated processes will not complete.
I hope the four examples I shared above help you understand how certain circumstances may require the use of force. You should have a strong understanding of the force option when used at the command line or in creating automation scripts. It's misuse can have devastating effects—sometimes across your infrastructure, and not only on a single machine.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/may-the-force-linux
作者:[Alan Formy-Duval ][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://opensource.com/users/alanfdoss
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fireworks_light_art_design.jpg?itok=hfx9i4By (Fireworks)
[2]: https://www.starwars.com/star-wars-day
[3]: http://man7.org/linux/man-pages/man1/cp.1.html
[4]: http://man7.org/linux/man-pages/man1/ln.1.html
[5]: http://man7.org/linux/man-pages/man1/rm.1.html
[6]: http://man7.org/linux/man-pages/man8/userdel.8.html

View File

@ -0,0 +1,117 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Building Smaller Container Images)
[#]: via: (https://fedoramagazine.org/building-smaller-container-images/)
[#]: author: (Muayyad Alsadi https://fedoramagazine.org/author/alsadi/)
Building Smaller Container Images
======
![][1]
Linux Containers have become a popular topic, making sure that a container image is not bigger than it should be is considered as a good practice. This article give some tips on how to create smaller Fedora container images.
### microdnf
Fedoras DNF is written in Python and and its designed to be extensible as it has wide range of plugins. But Fedora has an alternative base container image which uses an smaller package manager called [microdnf][2] written in C. To use this minimal image in a Dockerfile the FROM line should look like this:
```
FROM registry.fedoraproject.org/fedora-minimal:30
```
This is an important saving if your image does not need typical DNF dependencies like Python. For example, if you are making a NodeJS image.
### Install and Clean up in one layer
To save space its important to remove repos meta data using _dnf clean all_ or its microdnf equivalent _microdnf clean all_. But you should not do this in two steps because that would actually store those files in a container image layer then mark them for deletion in another layer. To do it properly you should do the installation and cleanup in one step like this
```
FROM registry.fedoraproject.org/fedora-minimal:30
RUN microdnf install nodejs && microdnf clean all
```
### Modularity with microdnf
Modularity is a way to offer you different versions of a stack to choose from. For example you might want non-LTS NodeJS version 11 for a project and old LTS NodeJS version 8 for another and latest LTS NodeJS version 10 for another. You can specify which stream using colon
```
# dnf module list
# dnf module install nodejs:8
```
The _dnf module install_ command implies two commands one that enables the stream and one that install nodejs from it.
```
# dnf module enable nodejs:8
# dnf install nodejs
```
Although microdnf does not offer any command related to modularity, it is possible to enable a module with a configuation file, and libdnf (which microdnf uses) [seems][3] to support modularity streams. The file looks like this
```
/etc/dnf/modules.d/nodejs.module
[nodejs]
name=nodejs
stream=8
profiles=
state=enabled
```
A full Dockerfile using modularity with microdnf looks like this:
```
FROM registry.fedoraproject.org/fedora-minimal:30
RUN \
echo -e "[nodejs]\nname=nodejs\nstream=8\nprofiles=\nstate=enabled\n" > /etc/dnf/modules.d/nodejs.module && \
microdnf install nodejs zopfli findutils busybox && \
microdnf clean all
```
### Multi-staged builds
In many cases you might have tons of build-time dependencies that are not needed to run the software for example building a Go binary, which statically link dependencies. Multi-stage build are an efficient way to separate the application build and the application runtime.
For example the Dockerfile below builds [confd][4] a Go application.
```
# building container
FROM registry.fedoraproject.org/fedora-minimal AS build
RUN mkdir /go && microdnf install golang && microdnf clean all
WORKDIR /go
RUN export GOPATH=/go; CGO_ENABLED=0 go get github.com/kelseyhightower/confd
FROM registry.fedoraproject.org/fedora-minimal
WORKDIR /
COPY --from=build /go/bin/confd /usr/local/bin
CMD ["confd"]
```
The multi-stage build is done by adding _AS_ after the _FROM_ instruction and by having another _FROM_ from a base container image then using C _OPY from=_ instruction to copy content from the _build_ container to the second container.
This Dockerfile can then be built and run using podman
```
$ podman build -t myconfd .
$ podman run -it myconfd
```
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/building-smaller-container-images/
作者:[Muayyad Alsadi][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://fedoramagazine.org/author/alsadi/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/05/smaller-container-images-816x345.jpg
[2]: https://github.com/rpm-software-management/microdnf
[3]: https://bugzilla.redhat.com/show_bug.cgi?id=1575626
[4]: https://github.com/kelseyhightower/confd

View File

@ -0,0 +1,499 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Getting Started With Docker)
[#]: via: (https://www.ostechnix.com/getting-started-with-docker/)
[#]: author: (sk https://www.ostechnix.com/author/sk/)
Getting Started With Docker
======
![Getting Started With Docker][1]
In our previous tutorial, we have explained **[how to install Docker in Ubuntu][2]** , and how to [**install Docker in CentOS**][3]. Today, we will see the basic usage of Docker. This guide covers the Docker basics, such as how to create a new container, how to run the container, remove a container, how to build your own Docker image from the Container and so on. Let us get started! All steps given below are tested in Ubuntu 18.04 LTS server edition.
### Getting Started With Docker
Before exploring the Docker basics, dont confuse with Docker images and Docker Containers. As I already explained in the previous tutorial, Docker Image is the file that decides how a Container should behave, and Docker Container is the running or stopped stage of a Docker image.
##### 1\. Search Docker images
We can get the images from either from the registry, for example [**Docker hub**][4], or create our own, For those wondering, Docker hub is cloud hosted place where all Docker users build, test, and save their Docker images.
Docker hub has tens of thousands of Docker images. You can search for the any Docker images with **“docker search”** command.
For instance, to search for docker images based on Ubuntu, run:
```
$ sudo docker search ubuntu
```
**Sample output:**
![][5]
To search images based on CentOS, run:
```
$ sudo docker search ubuntu
```
To search images for AWS, run:
```
$ sudo docker search aws
```
For wordpress:
```
$ sudo docker search wordpress
```
Docker hub has almost all kind of images. Be it an operating system, application, or anything, you will find pre-built Docker images in Docker hub. If something youre looking for is not available, you can build it and make it available for public or keep it private for your own use.
##### 2\. Download Docker image
To download Docker image for Ubuntu OS, run the following command from the Terminal:
```
$ sudo docker pull ubuntu
```
The above command will download the latest Ubuntu image from the **Docker hub**.
**Sample output:**
```
Using default tag: latest
latest: Pulling from library/ubuntu
6abc03819f3e: Pull complete
05731e63f211: Pull complete
0bd67c50d6be: Pull complete
Digest: sha256:f08638ec7ddc90065187e7eabdfac3c96e5ff0f6b2f1762cf31a4f49b53000a5
Status: Downloaded newer image for ubuntu:latest
```
![][6]
Download docker images
You can also download a specific version of Ubuntu image using command:
```
$ docker pull ubuntu:18.04
```
Docker allows us to download any images and start the container regardless of the host OS.
For example, to download CentOS image, run:
```
$ sudo docker pull centos
```
All downloaded Docker images will be saved in **/var/lib/docker/** directory.
To view the list of downloaded Docker images, run:
```
$ sudo docker images
```
**Sample output:**
```
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 7698f282e524 14 hours ago 69.9MB
centos latest 9f38484d220f 2 months ago 202MB
hello-world latest fce289e99eb9 4 months ago 1.84kB
```
As you see above, I have downloaded three Docker images **Ubuntu** , **CentOS** and **hello-world**.
Now, let us go ahead and see how to start or run the containers based on the downloaded images.
##### 3\. Run Docker Containers
We can start the containers in two methods. We can start a container either using its **TAG** or **IMAGE ID**. **TAG** refers to a particular snapshot of the image and the **IMAGE ID** is the corresponding unique identifier for that image.
As you in the above results **“latest”** is the TAG for all containers, and **7698f282e524** is the IMAGE ID of **Ubuntu** Docker image, **9f38484d220f** is the image id of CentOS Docker image and **fce289e99eb9** is the image id of **hello_world** Docker image.
Once you downloaded the Docker images of your choice, run the following command to start a Docker container by using its TAG.
```
$ sudo docker run -t -i ubuntu:latest /bin/bash
```
Here,
* **-t** : Assigns a new Terminal inside the Ubuntu container.
* **-i** : Allows us to make an interactive connection by grabbing the standard in (STDIN) of the container.
* **ubuntu:latest** : Ubuntu container with TAG “latest”.
* **/bin/bash** : BASH shell for the new container.
Or, you can start the container using IMAGE ID as shown below:
```
sudo docker run -t -i 7698f282e524 /bin/bash
```
Here,
* **7698f282e524** Image id
After starting the container, youll be landed automatically into the Containers shell (Command prompt):
![][7]
Docker containers shell
To return back to the host systems Terminal (In my case, it is Ubuntu 18.04 LTS) without terminating the Container (guest os), press **CTRL+P** followed by **CTRL+Q**. Now, youll be safely return back to your original host computers terminal window. Please note that the container is still running in the background and we didnt terminate it yet.
To view the list running of containers, run the following command:
```
$ sudo docker ps
```
**Sample output:**
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32fc32ad0d54 ubuntu:latest "/bin/bash" 7 minutes ago Up 7 minutes modest_jones
```
![][8]
List running containers
Here,
* **32fc32ad0d54** Container ID
* **ubuntu:latest** Docker image
Please note that **Container ID and Docker image ID are different**.
To list all available ( either running or stopped) containers:
```
$ sudo docker ps -a
```
To stop (power off the container) from the hosts shell, run the following command:
```
$ sudo docker stop <container-id>
```
**Example:**
```
$ sudo docker stop 32fc32ad0d54
```
To login back to or attach to the running container, just run:
```
$ sudo docker attach 32fc32ad0d54
```
As you already know, **32fc32ad0d54** is the containers ID.
To power off a Container from inside its shell by typing the following command:
```
# exit
```
You can verify the list of running containers with command:
```
$ sudo docker ps
```
##### 4\. Build your custom Docker images
Docker is not just for downloading and using the existing containers. You can create your own custom docker image as well.
To do so, start any one the downloaded container:
```
$ sudo docker run -t -i ubuntu:latest /bin/bash
```
Now, you will be in the containers shell.
Then, install any software or do what ever you want to do in the container.
For example, let us install **Apache web server** in the container.
Once you did all tweaks, installed all necessary software, run the following command to build your custom Docker image:
```
# apt update
# apt install apache2
```
Similarly, install and test any software of your choice in the Container.
Once you all set, return back to the host systems shell. Do not stop or poweroff the Container. To switch to the host systems shell without stopping Container, press CTRL+P followed by CTRL+Q.
From your host computers shell, run the following command to find the container ID:
```
$ sudo docker ps
```
Finally, create a Docker image of the running Container using command:
```
$ sudo docker commit 3d24b3de0bfc ostechnix/ubuntu_apache
```
**Sample Output:**
```
sha256:ce5aa74a48f1e01ea312165887d30691a59caa0d99a2a4aa5116ae124f02f962
```
Here,
* **3d24b3de0bfc** Ubuntu container ID. As you already, we can
* **ostechnix** Name of the user who created the container.
* **ubuntu_apache** Name of the docker image created by user ostechnix.
Let us check whether the new Docker image is created or not with command:
```
$ sudo docker images
```
**Sample output:**
```
REPOSITORY TAG IMAGE ID CREATED SIZE
ostechnix/ubuntu_apache latest ce5aa74a48f1 About a minute ago 191MB
ubuntu latest 7698f282e524 15 hours ago 69.9MB
centos latest 9f38484d220f 2 months ago 202MB
hello-world latest fce289e99eb9 4 months ago 1.84kB
```
![][9]
List docker images
As you see in the above output, the new Docker image has been created in our localhost system from the running Container.
Now, you can create a new Container from the newly created Docker image as usual suing command:
```
$ sudo docker run -t -i ostechnix/ubuntu_apache /bin/bash
```
##### 5\. Removing Containers
Once youre done all R&D with Docker containers, you can delete if you dont want them anymore.
To do so, First we have to stop (power off) the running Containers.
Let us find out the running containers with command:
```
$ sudo docker ps
```
**Sample output:**
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d24b3de0bfc ubuntu:latest "/bin/bash" 28 minutes ago Up 28 minutes goofy_easley
```
Stop the running container by using its ID:
```
$ sudo docker stop 3d24b3de0bfc
```
Now, delete the container using command:
```
$ sudo docker rm 3d24b3de0bfc
```
Similarly, stop all containers and delete them if they are no longer required.
Deleting multiple containers one by one can be a tedious task. So, we can delete all stopped containers in one go, just run:
```
$ sudo docker container prune
```
Type **“Y”** and hit ENTER key to delete the containers.
```
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
32fc32ad0d5445f2dfd0d46121251c7b5a2aea06bb22588fb2594ddbe46e6564
5ec614e0302061469ece212f0dba303c8fe99889389749e6220fe891997f38d0
Total reclaimed space: 5B
```
This command will work only with latest Docker versions.
##### 6\. Removing Docker images
Once you removed containers, you can delete the Docker images that you no longer need.
To find the list of the Downloaded Docker images:
```
$ sudo docker images
```
**Sample output:**
```
REPOSITORY TAG IMAGE ID CREATED SIZE
ostechnix/ubuntu_apache latest ce5aa74a48f1 5 minutes ago 191MB
ubuntu latest 7698f282e524 15 hours ago 69.9MB
centos latest 9f38484d220f 2 months ago 202MB
hello-world latest fce289e99eb9 4 months ago 1.84kB
```
As you see above, we have three Docker images in our host system.
Let us delete them by using their IMAGE id:
```
$ sudo docker rmi ce5aa74a48f1
```
**Sample output:**
```
Untagged: ostechnix/ubuntu_apache:latest
Deleted: sha256:ce5aa74a48f1e01ea312165887d30691a59caa0d99a2a4aa5116ae124f02f962
Deleted: sha256:d21c926f11a64b811dc75391bbe0191b50b8fe142419f7616b3cee70229f14cd
```
##### Troubleshooting
Docker wont let you to delete the Docker images if they are used by any running or stopped containers.
For example, when I try to delete a Docker Image with ID **b72889fa879c** , from one of my old Ubuntu server. I got the following error:
```
Error response from daemon: conflict: unable to delete b72889fa879c (must be forced) - image is being used by stopped container dde4dd285377
```
This is because the Docker image that you want to delete is currently being used by another Container.
So, let us check the running Container using command:
```
$ sudo docker ps
```
**Sample output:**
![][10]
Oops! There is no running container.
Let us again check for all containers (Running and stopped) with command:
```
$ sudo docker ps -a
```
**Sample output:**
![][11]
As you see there are still some stopped containers are using one of the Docker images. So, let us delete all of the containers.
**Example:**
```
$ sudo docker rm 12e892156219
```
Similarly, remove all containers as shown above using their respective containers ID.
Once you deleted all Containers, finally remove the Docker images.
**Example:**
```
$ sudo docker rmi b72889fa879c
```
Thats it. Let us verify is there any other Docker images in the host with command:
```
$ sudo docker images
```
For more details, refer the official resource links given at the end of this guide or drop a comment in the comment section below.
Also, download and use the following Docker Ebooks to get to know more about it.
** **Download** [**Free eBook: “Docker Containerization Cookbook”**][12]
** **Download** [**Free Guide: “Understanding Docker”**][13]
** **Download** [**Free Guide: “What is Docker and Why is it So Popular?”**][14]
** **Download** [**Free Guide: “Introduction to Docker”**][15]
** **Download** [**Free Guide: “Docker in Production”**][16]
And, thats all for now. Hope you a got the basic idea about Docker usage.
More good stuffs to come. Stay tuned!
Cheers!!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/getting-started-with-docker/
作者:[sk][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.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/wp-content/uploads/2016/04/docker-basics-720x340.png
[2]: http://www.ostechnix.com/install-docker-ubuntu/
[3]: https://www.ostechnix.com/install-docker-centos/
[4]: https://hub.docker.com/
[5]: http://www.ostechnix.com/wp-content/uploads/2016/04/Search-Docker-images.png
[6]: http://www.ostechnix.com/wp-content/uploads/2016/04/Download-docker-images.png
[7]: http://www.ostechnix.com/wp-content/uploads/2016/04/Docker-containers-shell.png
[8]: http://www.ostechnix.com/wp-content/uploads/2016/04/List-running-containers.png
[9]: http://www.ostechnix.com/wp-content/uploads/2016/04/List-docker-images.png
[10]: http://www.ostechnix.com/wp-content/uploads/2016/04/sk@sk-_005-1-1.jpg
[11]: http://www.ostechnix.com/wp-content/uploads/2016/04/sk@sk-_006-1.jpg
[12]: https://ostechnix.tradepub.com/free/w_java39/prgm.cgi?a=1
[13]: https://ostechnix.tradepub.com/free/w_pacb32/prgm.cgi?a=1
[14]: https://ostechnix.tradepub.com/free/w_pacb31/prgm.cgi?a=1
[15]: https://ostechnix.tradepub.com/free/w_pacb29/prgm.cgi?a=1
[16]: https://ostechnix.tradepub.com/free/w_pacb28/prgm.cgi?a=1

View File

@ -0,0 +1,123 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (PiShrink Make Raspberry Pi Images Smaller)
[#]: via: (https://www.ostechnix.com/pishrink-make-raspberry-pi-images-smaller/)
[#]: author: (sk https://www.ostechnix.com/author/sk/)
PiShrink Make Raspberry Pi Images Smaller
======
![Make Raspberry Pi Images Smaller With PiShrink In Linux][1]
**Raspberry Pi** requires no introduction. It is a small, affordable and credit-card sized computer that can be connected to a Monitor or TV. We can attach a standard keyboard and mouse and use it as a full-blown desktop computer to do everyday tasks, such Internet browsing, playing videos/games, word processing and spreadsheet making and a lot more. It has been mainly developed for teaching Computer science in schools. Nowadays, Raspberry Pi is widely being used in colleges, small-medium organizations and institutes to teach coding. If you own a Raspberry Pi device, you might want to check out a bash script named **“PiShrink”** , which is used to make Raspberry Pi Images smaller. PiShrink will automatically shrink a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better. This can be useful to fit the large size images in your SD card. In this brief guide, we are going to learn to shrink Raspberry images to smaller size in Unix-like systems.
### Installing PiShrink
To install PiShrink on your Linux box, first download the latest version using command:
```
$ wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
```
Next, make the downloaded PiShrink binary as executable:
```
$ chmod +x pishrink.sh
```
Finally, move it your path:
```
$ sudo mv pishrink.sh /usr/local/bin/
```
### Make Raspberry Pi Images Smaller
As you may already know, **Raspbian** is the official operating system for all models of Raspberry Pi. The Raspberry foundation has developed **Raspberry Pi Desktop** version for PC and Mac. You can create a live cd, run it in virtual machine and even install it in your desktop as well. There are also few unofficial OS images available for Raspberry Pi. For the purpose of testing, Ive downloaded the official Raspbian OS from the [**official download page**][2].
Unzip the downloaded OS image:
```
$ unzip 2019-04-08-raspbian-stretch-lite.zip
```
The above command will extract contents of **2019-04-08-raspbian-stretch-lite.zip** file in the current working directory.
Let check the actual size of the extracted file:
```
$ du -h 2019-04-08-raspbian-stretch-lite.img
1.7G 2019-04-08-raspbian-stretch-lite.img
```
As you can see, the size of the extracted Raspberry OS img file is **1.7G**.
Now, shrink this files size using PiShrink like below:
```
$ sudo pishrink.sh 2019-04-08-raspbian-stretch-lite.img
```
Sample output:
```
Creating new /etc/rc.local
rootfs: 39795/107072 files (0.1% non-contiguous), 239386/428032 blocks
resize2fs 1.45.0 (6-Mar-2019)
resize2fs 1.45.0 (6-Mar-2019)
Resizing the filesystem on /dev/loop1 to 280763 (4k) blocks.
Begin pass 3 (max = 14)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 3728)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop1 is now 280763 (4k) blocks long.
Shrunk 2019-04-08-raspbian-stretch-lite.img from 1.7G to 1.2G
```
[![Make Raspberry Pi Images Smaller Using PiShrink][1]][3]
Make Raspberry Pi Images Smaller Using PiShrink
As you see in the above output, the size of the Rasberry Pi image has been reduced to **1.2G**.
You can also use **-s** flag to skip the autoexpanding part of the process.
```
$ sudo pishrink.sh -s 2019-04-08-raspbian-stretch-lite.img newpi.img
```
This will create a copy of source img file (i.e 2019-04-08-raspbian-stretch-lite.img) into a new img file (newpi.img) and work on it. For more details, check the official GitHub page given at the end.
And, thats all for now. Hope this was useful. More good stuffs to come. Stay tuned!
And, thats all for now.
**Resource:**
* [**PiShrink GitHub Repository**][4]
* [**Raspberry Pi website**][5]
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/pishrink-make-raspberry-pi-images-smaller/
作者:[sk][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.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/wp-content/uploads/2019/05/pishrink-720x340.png
[2]: https://www.raspberrypi.org/downloads/
[3]: http://www.ostechnix.com/wp-content/uploads/2019/05/pishrink-1.png
[4]: https://github.com/Drewsif/PiShrink
[5]: https://www.raspberrypi.org/

View File

@ -0,0 +1,80 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Check your spelling at the command line with Ispell)
[#]: via: (https://opensource.com/article/19/5/spelling-command-line-ispell)
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt)
使用 Ispell 在命令行中检查拼写
======
Ispell 可以帮助你在纯文本中消除超过 50 种语言的拼写错误。
![Command line prompt][1]
好的拼写是一种技巧。它是一项需要时间学习和掌握的技能。也就是说,有些人从来没有完全掌握这种技能,我知道有两三个出色的作家无法完全掌握拼写。
即使你拼写得很好,偶尔也会输入错字。特别是在最后期限前如果你快速敲击键盘,那就更是如此。无论你的拼写的是什么,通过拼写检查器检查你所写的内容总是一个好主意。
我用[纯文本][2]完成了我的大部分写作,并经常使用名为 [Aspell][3] 的命令行拼写检查器来完成这项工作。Aspell 不是唯一的工具。你可能还想要看下不错的 [Ispell][4]。
### 入门
自 1971 年以来Ispell 以各种形式出现过。不要被它的年龄欺骗。Ispell 仍然是一个可以在 21 世纪高效使用的应用。
在开始之前,请打开终端窗口并输入**which ispell** 来检查计算机上是否安装了 Ispell。如果未安装请打开发行版的软件包管理器并从那里安装 Ispell。
不要忘记为你使用的语言安装词典。我唯一使用的语言是英语所以我只需下载美国和英国英语字典。你可以不局限于我的也是唯一的母语。Ispell 有[超过 50 种语言的词典][5]。
![Installing Ispell dictionaries][6]
### 使用 Ispell
如果你还没有猜到Ispell 只能用在文本文件。这包括用 HTML、LaTeX 和 [nroff 或 troff][7] 标记的文档。之后会有更多相关内容。
要开始使用,请打开终端窗口并进入包含要运行拼写检查的文件的目录。输入 **ispell** 后跟文件名,然后按回车键。
![Checking spelling with Ispell][8]
Ispell 高亮了它无法识别的第一个词。如果单词拼写错误Ispell 通常会提供一个或多个备选方案。按下 **R**,然后按下正确选择旁边的数字。在上面的截图中,我按了 **R****0** 来修复错误。
另一方面,如果单词拼写正确,请按下 **A** 然后移动到下一个拼写错误的单词。
继续这样做直到到达文件的末尾。Ispell 会保存你的更改,创建你刚检查的文件的备份(扩展名为 _.bak_),然后关闭。
### 其他几个选项
此示例说明了 Ispell 的基本用法。这个程序有[很多选项][9]有些你_可能_会用到而另一些你_可能永远_不会使用。让我们快速看下我经常使用的一些。
之前我提到过 Ispell 可以用于某些标记语言。你需要告诉它文件的格式。启动 Ispell 时,为 TeX 或 LaTeX 文件添加 **-t**,为 HTML 文件添加 **-H**,对于 groff 或 troff 文件添加 **-n**。例如,如果输入 **ispell -t myReport.tex**Ispell 将忽略所有标记。
如果你不想在检查文件后创建备份文件,请将 **-x** 添加到命令行。例如,**ispell -x myFile.txt**。
如果 Ispell 遇到拼写正确但不在其字典中的单词,像是名字,会发生什么?你可以按 **I** 将该单词添加到个人单词列表中。这会将单词保存到 _/home_ 家目录下的 _.ispell_default_ 的文件中。
这些是我在使用 Ispel l时最有用的选项但请查看 [Ispell 的手册页][9]以了解其所有选项。
Ispell 比 Aspell 或其他命令行拼写检查器更好或者更快么我会说它不比其他的差或者慢。Ispell 不是适合所有人。它也许也不适合你。但有更多选择也不错,不是么?
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/spelling-command-line-ispell
作者:[Scott Nesbitt ][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://opensource.com/users/scottnesbitt
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/command_line_prompt.png?itok=wbGiJ_yg (Command line prompt)
[2]: https://plaintextproject.online
[3]: https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell
[4]: https://www.cs.hmc.edu/~geoff/ispell.html
[5]: https://www.cs.hmc.edu/~geoff/ispell-dictionaries.html
[6]: https://opensource.com/sites/default/files/uploads/ispell-install-dictionaries.png (Installing Ispell dictionaries)
[7]: https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-me
[8]: https://opensource.com/sites/default/files/uploads/ispell-checking.png (Checking spelling with Ispell)
[9]: https://www.cs.hmc.edu/~geoff/ispell-man.html

View File

@ -0,0 +1,225 @@
[#]: collector: (lujun9972)
[#]: translator: (Moelf)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Using the force at the Linux command line)
[#]: via: (https://opensource.com/article/19/5/may-the-force-linux)
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
在 Linux 命令行下使用 force 参数
======
和绝地武士的原力一样,-f 参数是很强大的,并伴随着潜在的毁灭性,在你能用好的时候又很便利。
![Fireworks][1]
不久的过去科幻发烧友开始庆祝每年的原力日5月4日[_星球大战_][2],英语里和”愿原力和你同在“双关。虽然大多数 Linux 用户可能不是绝地武士,但我们依然可以使用 force。自然如果 Yoda 直接叫路克天行者输入什么 ”man X翼战机“ 或者 “man 原力"的话电影肯定会无聊不少。或者他可以直接说,"RTFM"(Read the Force Manual肯定是这个意思对不对译者通常 RTFM 是 Read The Fucking Manual 的缩写,读读该死的手册吧)。
很多 Linux 指令都有 -f 选项意思你现在肯定也知道了force强制很多时候你先尝试执行指令然后失败了或者提示你需要输入更多选项。通常这都是为了保护你的文件或者告诉用户设备正忙或者文件已经存在之类的设计。
如果你不想被这些提醒打扰或者压根就不在乎,使用 force
不过要小心,通常使用 force 选项是摧毁性的。所以用户一定要格外注意并且确保你知道自己在做什么。用 force 就要承担后果!
以下是一些常见 Linux 命令的 force 选项和他们的效果,以及常见使用场景。
### cp
**cp** 是 copy 的缩写,这是个被用来复制文件或者目录的命令。[man 页面][3] 说:
```
-f, --force
如果已经存在的目标文件无法被打开,删除并重试
```
你可能会用它来处理只读状态的文件:
```
[alan@workstation ~]$ ls -l
total 8
-rw-rw---- 1 alan alan 13 May 1 12:24 Hoth
-r--r----- 1 alan alan 14 May 1 12:23 Naboo
[alan@workstation ~]$ cat Hoth Naboo
Icy Planet
Green Planet
```
如果你想要复制一个叫做 _Hoth_ 的文件到 _Naboo_,但因为 _Naboo_ 目前是只读状态,**cp** 指令不会执行:
```
[alan@workstation ~]$ cp Hoth Naboo
cp: cannot create regular file 'Naboo': Permission denied
```
但通过使用 force 选项,**cp** 会强制执行。_Hoth_ 的内容和文件权限会直接被复制到 _Naboo_
```
[alan@workstation ~]$ cp -f Hoth Naboo
[alan@workstation ~]$ cat Hoth Naboo
Icy Planet
Icy Planet
[alan@workstation ~]$ ls -l
total 8
-rw-rw---- 1 alan alan 12 May 1 12:32 Hoth
-rw-rw---- 1 alan alan 12 May 1 12:38 Naboo
```
### ln
**ln** 指令是用来在文件之间建立链接的,[man 页面][4] 描述的 force 选项如下:
```
-f, --force
移除当前存在的文件
```
假设 Leia 公主在 维护一个 Java 应用服务器并且当前在一个有所有 Java 版本的目录里,她可能会想这么做:
```
leia@workstation:/usr/lib/java$ ls -lt
total 28
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
正如你所看到的,这里有很多个版本的 JDK 和一些符号链接指向最新版的 JDK。她接着用一个脚本来安装最新版本的 JDK。但是如果没有 force 选项的话以下命令是不会成功的:
```
tar xvzmf jdk1.8.0_181.tar.gz -C jdk1.8.0_181/
ln -vs jdk1.8.0_181 jdk
```
**tar** 命令会解压 .gz 文件到一个特定的目标目录,但 **ln** 指令会失败因为这个链接已经存在了。这样的结果是链接不会指向最新版本的 JDK
```
leia@workstation:/usr/lib/java$ ln -vs jdk1.8.0_181 jdk
ln: failed to create symbolic link 'jdk/jdk1.8.0_181': File exists
leia@workstation:/usr/lib/java$ ls -lt
total 28
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk -> jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
她可以通过使用 force 选项强制 **ln** 更新链接,但这里她还需要使用 -n-n 是因为这个情况下链接其实指向一个目录而非文件。这样的话链接就会正确指向最新版本的JDK了。
```
leia@workstation:/usr/lib/java$ ln -vsnf jdk1.8.0_181 jdk
'jdk' -> 'jdk1.8.0_181'
leia@workstation:/usr/lib/java$ ls -lt
total 28
lrwxrwxrwx 1 leia leia 12 May 1 16:13 jdk -> jdk1.8.0_181
drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181
drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162
drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
```
你可以配置 Java 应用使其一直使用在 **/usr/lib/java/jdk** 处的 JDK 而不用每次升级都要更新链接。
### rm
**rm** 指令是 remove 的缩写,叫做移除但也有一部分人喜欢叫它删除。[man 页面][5] 对 force 选项的描述如下:
```
-f, --force
无视不存在的文件或者选项,不向用户确认
```
如果你尝试删除一个只读的文件,**rm** 会寻求用户的确认:
```
[alan@workstation ~]$ ls -l
total 4
-r--r----- 1 alan alan 16 May 1 11:38 B-wing
[alan@workstation ~]$ rm B-wing
rm: remove write-protected regular file 'B-wing'?
```
你一定要输入 **y** 或者 **n** 来回答确认才能让 **rm** 命令继续。如果你使用 force 选项,**rm** 就不会寻求你的确认而直接删除文件:
```
[alan@workstation ~]$ rm -f B-wing
[alan@workstation ~]$ ls -l
total 0
[alan@workstation ~]$
```
最常见的 **rm** force 选项是用来删除目录。 **-r** (递归)选项会让 **rm** 删除目录,和 force 选项结合起来,它会删除这个文件夹及其内容而无需用户确认。
**rm** 命令和一些选项结合起来是致命的,一直以来互联网上都有关于误用 **rm** 删除整个系统之类的玩笑和鬼故事。比如最出名的一不当心执行 **rm -rf .** 会直接删除目录和文件(没有用户确认)。
### userdel
**userdel** 指令使用来删除用户的。[man 页面][6] 是这样描述它的 force 选项的:
```
-f, --force
这个选项会强制移除用户,即便用户当前处于登入状态。它同时还会强制
删除用户的目录和邮件,即便这个用户目录被别人共享或者邮件卷并不只
属于这个用户。如果 USERGROUPS_ENAB 在 /etc/login.defs 里是 yes
并且有一个组和此用户同名的话,这个组也会被移除,即便这个组还是别
的用户的主要用户组也一样。
注意:这个选项有风险并可能让系统处于不稳定状态。
```
当欧比旺抵达穆斯塔法星的时候,他知道自己的使命。他需要删掉达斯·维达的用户账户——但达斯还登录在里面。
```
[root@workstation ~]# ps -fu darth
UID PID PPID C STIME TTY TIME CMD
darth 7663 7655 0 13:28 pts/3 00:00:00 -bash
[root@workstation ~]# userdel darth
userdel: user darth is currently used by process 7663
```
因为达斯还登入在系统里,欧比旺需要使用 force 选项操作 **userdel**。这能强制删除正登入的用户。
```
[root@workstation ~]# userdel -f darth
userdel: user darth is currently used by process 7663
[root@workstation ~]# finger darth
finger: darth: no such user.
[root@workstation ~]# ps -fu darth
error: user name does not exist
```
正如我们所见到的一样,**finger** 和 **ps** 命令让我们确认了达斯已经被删除了。
### 在 Shell 脚本里使用 force
很多指令都有 force 选项,而在 shell 脚本里他们特别游泳。因为我们经常使用脚本完成定期或者自动化的任务,避免用户输入至关重要,不然的话自动任务就无法完成了
我希望上面的几个例子能帮你理解在一些情况下 force 的用法。你在使用 force 或把他们写入脚本之前应当完全理解他们的作用。误用 force 会有毁灭性的后果——时常是对整个系统,甚至不仅限于一台设备。
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/may-the-force-linux
作者:[Alan Formy-Duval ][a]
选题:[lujun9972][b]
译者:[Jerry Ling](https://github.com/Moelf)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/alanfdoss
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/fireworks_light_art_design.jpg?itok=hfx9i4By (Fireworks)
[2]: https://www.starwars.com/star-wars-day
[3]: http://man7.org/linux/man-pages/man1/cp.1.html
[4]: http://man7.org/linux/man-pages/man1/ln.1.html
[5]: http://man7.org/linux/man-pages/man1/rm.1.html
[6]: http://man7.org/linux/man-pages/man8/userdel.8.html