Lunix file rename

Generally, you need to enter both file names for renaming. If the file name is too long, it will be troublesome. Is there a solution?
Method 1: General rename

$ mv file1.txt file2.txt

Method 2: Advanced 【mv】

$ mv file{
    
    1,2}.txt
# 如果要保留源文件,就选择cp命令即可
$ cp file{
    
    1,2}txt

Method 3: Use the shortcut key [ctl+w] to cut and [ctl+y] to paste.
Method 4: Rename efficiently.
First, we need to use vim to edit the ~/.bashrcfile.
$ vim ~/.bashrc

Add the following code to the end

# Bash Function To Rename Files Without Typing Full Name Twice
 function mv() {
    
    
   if [ "$#" -ne 1 ] || [ ! -e "$1" ]; then
    command mv "$@"
    return
   fi
  read -ei "$1" newfilename
  command mv -v -- "$1" "$newfilename"
 }

Then, press wqsave and exit. Then again, use the sourcecommand to make this change take effect.
$ source ~/.bashrc

When you use the mv file1.txtterminal again , the original file name will be displayed, and then you can directly change the name without having to enter the original name again.

Guess you like

Origin blog.csdn.net/weixin_43298913/article/details/106633400