Centos linux troubles caused by alias problems and solutions

Example: The 9th issue of the old boy linux practical training (October 22) entrance exam question 10:

10. It is known that the test.txt file already exists under /tmp. How to execute the command to overwrite /tmp/test.txt with /mnt/test.txt without the system prompting whether to overwrite (under root authority).

Answer reference:

Brief explanation:

In order to prevent users from misoperation, when the centos linux operating system is designed, the default operation of executing cp is to call the alias of cp (equivalent to executing cp -i). So prompt override. The idea of ​​this question is to shield the system aliases.

Detailed description:

   The cp command will not prompt for overwriting by default, but it will prompt when cp is executed with the -i parameter, and the Linux startup file ~/.bashrc will name cp as alias cp='cp -i', such as:

[root@student tmp]# alias |grep cp
alias cp='cp -i'

In this way, entering the cp command under Linux actually runs cp -i, adding a "\" symbol or writing the full path of cp /bin/cp is to make the cp command run without an alias (cp -i) .

This involves the usage of the alias and unalias commands. At the same time, everyone also thinks about the benefits of aliases and how to use this feature to serve us.

Suggestion: Take time to summarize the usage of the alias and unalias commands.

Student answers and teacher's correction evaluation cases:

hint:

The same command has mv, rm, etc. I hope that everyone can draw inferences from each other as much as possible in doing things, so as to broaden their thinking and vision.

Special note: You can also escape aliases by writing commands directly in the script, but we are used to using the full path. example:

[root@oldboy test]# pwd
/root/test
[root@oldboy test]# ll
total 8
-rw-r--r-- 1 root root  2 Jun 19 10:51 oldboy.log
-rwxr-xr-x 1 root root 54 Jun 19 10:51 test.sh
[root@oldboy test]# cat test.sh
cp oldboy.log /tmp
rm oldboy.log
mv /tmp/oldboy.log .
[root@oldboy test]# sh test.sh
[root@oldboy test]# sh -x test.sh
+ cp oldboy.log /tmp
+ rm oldboy.log
+ mv /tmp/oldboy.log .
[root@oldboy test]# ll
total 8
-rw-r--r-- 1 root root  2 Jun 19 10:52 oldboy.log
-rwxr-xr-x 1 root root 54 Jun 19 10:51 test.sh
[root@oldboy test]# ll --full-time
total 8
-rw-r--r-- 1 root root  2 2012-06-19 10:52:25.000000000 +0800 oldboy.log
-rwxr-xr-x 1 root root 54 2012-06-19 10:51:48.000000000 +0800 test.sh
[root@oldboy test]# sh test.sh
[root@oldboy test]# ll --full-time
total 8
-rw-r--r-- 1 root root  2 2012-06-19 10:52:41.000000000 +0800 oldboy.log
-rwxr-xr-x 1 root root 54 2012-06-19 10:51:48.000000000 +0800 test.sh

This article is from the " Old Boy Linux Training " blog, http://oldboy.blog.51cto.com/2561410/699046

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324682617&siteId=291194637