Home > Article > Computer Tutorials > How to rename files in Linux
I recently encountered a problem when using the Ubuntu system for software development. I created an icon for Android Studio, but it cannot be used normally, and an "Application Startup Error" message appears. I searched a lot of articles online and most of them said this is because the folder path contains spaces. However, I confirmed that my file path did not contain spaces, but did contain a hyphen "-", which is "android-studio". To try and fix the problem, I decided to rename the folder. However, I encountered the "bareword not allowed" error message again.
There are two commands for renaming files under Linux: mv,rename
mv is very simple, move files
mv /dir/file1 /dir2/file1
Two parameters, the first is the source file, the second is the destination, if the second parameter file name is different, it will be renamed.
When the two parameters do not take a directory, but only a file name, it is renamed. This is a single file rename.
rename arg1 arg2 arg3
rename is the real batch rename command. And it has 3 parameters, not 2.
arg1: old string
arg2: new string
arg3: Match the file to be renamed. You can use 3 wildcard characters, *,? , [char], * represents any number of characters,? Represents a single character, [char] matches a single customized exact character of char, and any character can be filled in. foo[a]* indicates that it only matches the file name starting with fooa. If a file is foobcc.txt, it will not be matched.
Note that this command is different in different Linux versions, and the Debian series of operating systems have different uses. for example:
For example, there are two files under /home abbcc.txt, addbb.txt, a.txt
I want to replace a with xxx, the command is like this: rename “a” “xxx” *.txt
Then it will first match which files need to be modified. Here, all files with the .txt suffix will be matched. What if it is changed to? .txt will only match one file, which is a.txt. Then replace the a character in the matched file with xxx. Note that when testing abab.txt, only the first a will be replaced, which remains to be understood.
Speaking of Debian series operating systems, such as Ubuntu, it is incorrect to use this command like this. If an error is reported, please respond to the following:
Bareword “a” not allowed while “strict subs” in use at (eval 1) line 1.
After searching Google, I found this statement:
On Debian-based distros it takes a perl expression and a list of files. you need to would need to use:
rename 's/foo/foox/' *
This is a perl expression. To be easy to understand, it combines the first two parameters into one, so only 2 parameters are needed instead of the 3 parameter form mentioned above.
So when executing the renaming example above under Ubuntu, the command is as follows: rename 's/a/xxx/' *.txt
Modify the host name in this file etc/sysconfig/network.
NETWORKING=yes
HOSTNAME=Hostname
-------------------------------------------------- --------------------------
Remember to restart! ! !
-------------------------------------------------- --------------------------
whole:
first step:
#hostname oratest
Step 2:
Modify the hostname in /etc/sysconfig/network
third step:
Modify the /etc/hosts file
Method/Step
Log in as the root user, or switch to the root user after logging in, and then enter the hostname command at the prompt. You can see that the host name of the current system is localhost.localdomain.
Change the network file under /etc/sysconfig, enter vi /etc/sysconfig/network at the prompt, and then change the value after HOSTNAME to the host name you want to set.
Change the hosts file under /etc, enter vi /etc/hosts at the prompt, and then change localhost.localdomain to the host name you want to set.
Enter the reboot command at the prompt to restart the server.
After the restart is completed, use the hostname command to query the system host name. It can be seen that the system host name has been changed to mycomputer.
The above is the detailed content of How to rename files in Linux. For more information, please follow other related articles on the PHP Chinese website!