In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the Force options under the Linux command line, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
Cp
Cp is the abbreviation of "copy", which is a command used to copy files or directories. Its man page says:
-f.-force.
If an existing target file cannot be opened, delete it and try again
You might use it to deal with read-only files:
[alan@workstation] $ls-ltotal 8 RWMurray RWMurray-1 alan alan 13 May 1 12:24 Hoth-r--r- 1 alan alan 14 May 1 12:23 Naboo [alan@workstation] $cat Hoth NabooIcy Planet Green Planet
If you want to copy a file called Hoth to Naboo, but because Naboo is currently read-only, the cp command will not be executed:
[alan@workstation ~] $cp Hoth Naboocp: cannot create regular file 'Naboo': Permission denied
But by using the Force, cp enforces it. The contents and file permissions of Hoth are copied directly to Naboo:
[alan@workstation ~] $cp-f Hoth Naboo [alan@workstation ~] $cat Hoth NabooIcy Planet Icy Planet [alan@workstation ~] $ls-ltotal 8 RW Hoth-rw-rw-----1 alan alan 12 May 1 12:32 Hoth-rw-rw---- 1 alan alan 12 May 1 12:38 Nabooln
The ln command is used to establish links between files, and its man page describes the Force options as follows:
-f.-force.
Remove a file that currently exists
Suppose Princess Leia is maintaining a Java application server and she has another directory where all the Java versions are stored, such as:
Leia@workstation:/usr/lib/java$ ls-lttotal 28lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk-> jdk1.8.0_162drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
As you can see, there are many versions of JDK, with a symbolic link to JDK. She then uses a script to install JDK. But the following command will not succeed without the Force option:
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 a specific target directory, but the ln command will fail because the link already exists. The result is that the symbolic link does not point to JDK:
Leia@workstation:/usr/lib/java$ ln-vs jdk1.8.0_181 jdkln: failed to create symbolic link 'jdk/jdk1.8.0_181': File existsleia@workstation:/usr/lib/java$ ls-lttotal 28drwxr jdk-2 leia leia 4096 May 1 15:44 jdk1.8.0_181lrwxrwxrwx 1 leia leia 12 Mar 5 2018 jdk-> jdk1.8.0_162drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
She can force ln to update the link by using the Force option, but here she also needs to use-NMagneWhen because in this case the link actually points to a directory rather than a file. In this way, the link will correctly point to JDK.
Leia@workstation:/usr/lib/java$ ln-vsnf jdk1.8.0_181 jdk'jdk'-> 'jdk1.8.0_181'leia@workstation:/usr/lib/java$ ls-lttotal 28lrwxrwxrwx 1 leia leia 12 May 1 16:13 jdk-> jdk1.8.0_181drwxr-x--- 2 leia leia 4096 May 1 15:44 jdk1.8.0_181drwxr-xr-x 8 leia leia 4096 Mar 5 2018 jdk1.8.0_162drwxr-xr-x 8 leia leia 4096 Aug 28 2017 jdk1.8.0_144
You can configure the Java app to always use the JDK at / usr/lib/java/jdk without having to update it every time you upgrade.
Rm
The rm command is an acronym for "remove" (also called delete, because some system del commands do the same thing). Its man page describes the Force options as follows:
-f.-force.
Ignore files or parameters that do not exist and do not confirm to the user
If you try to delete a read-only file, rm will seek confirmation from the user:
[alan@workstation] $ls-ltotal 4 Murray r-1 alan alan 16 May 1 11:38 B-wing [alan@workstation ~] $rm B-wing rm: remove write-protected regular file'Bmurwi?
You must type y or n to answer confirmation in order for the rm command to continue. If you use the Force option, rm will not seek your confirmation and delete the file directly:
[alan@workstation ~] $rm-f B-wing [alan@workstation ~] $ls-ltotal 0 [alan@workstation ~] $
The most common use of the rm Force option is to delete directories. The-r (recursive) option causes rm to delete the directory, and when combined with the Force option, it deletes the folder and its contents without user confirmation.
The combination of the rm command and some options is fatal, and there have been jokes and ghost stories on the Internet about misusing rm to delete the entire system. For example, the most famous one inadvertently implements rm-rf. Directories and files are deleted directly (without user confirmation). (LCTT translation note: proofreaders who have really done this float by ~ Please confirm again and again before pressing enter: who I am, where I am and what I am doing.)
Userdel
That is used by the userdel command to delete the user. Its man page describes its Force options as follows:
-f.-force.
This option forcibly removes the user, even if the user is currently logged in. It also forces the deletion of a user's directory and mail store, even if the user directory is shared or the mail store does not belong to that user. If USERGROUPS_ENAB is yes in / etc/login.defs and there is a group with the same name as the user, the group will also be removed, even if the group is the primary user group of another user.
Note: this option is risky and may leave the system in an unstable state.
When Obi-Wan arrived on Mustafa, he knew his mission. He needs to delete Darth Vader's user account-and Darth is still in it.
[root@workstation ~] # ps-fu darthUID PID PPID C STIME TTY TIME CMDdarth 7663 7655 0 13:28 pts/3 00:00:00-bash [root@workstation ~] # userdel darthuserdel: user darth is currently used by process 7663
Because Das is still in the system, Obi-Wan needs to use the Force option to operate userdel. This forces the currently logged-in user to be deleted.
[root@workstation ~] # userdel-f darthuserdel: user darth is currently used by process 7663 [root@workstation ~] # finger darthfinger: darth: no such user. [root@workstation ~] # ps-fu dartherror: user name does not exist
As we have seen, the finger and ps commands let us confirm that Das has been deleted.
The above is all the contents of the article "how to use the Force options on the Linux command line". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.