Published Book on Amazon
![]() |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 |
![]() |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 |
출판된 한글판 도서
![]() |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) |
![]() |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) |
Original Book Contents
16.2.2 Renaming Directory and File
16.2.2.1 "mv" Command - Rename File
To change the name of a directory or file in Shell, you can use the following command.
[Command Format]
mv [OPTION] <from-directory/file> <to- directory/file> |
[Command Overview]
■ This moves or renames a directory or file.
■ User privilege -- Normal user.
[Detail Description]
■ This command has the ability to rename or move file at the same time:
■ Rename -- Specify the same directory for "From" and "To", and specify a different file name
■ Move -- Specify a different directory for "From" and "To".
■ You can specify a path when specifying a directory. If you do not specify a path, it will work in the current directory.
■ When changing the directory name, specify only the directory name. When changing the file name, specify both the directory and the file name.
[Main Option]
--help | display this help and exit |
[Used Example] – change directory name
First, we will try to change the directory name. In the following, if you look at the contents of the "testdata" directory before you work, you will see that there is a "TestFolder01" directory.
pi@raspberrypi ~/testdata $ ls –l |
total 16 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 manual01 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 TestFolder01 drwxr-xr-x 2 pi pi 4096 Apr 10 03:58 TestFolder02 -rwxrwx--- 1 pi pi 18 Mar 24 02:10 user_guide01.txt |
If you perform the following operation for the directory "TestFolder01" and inquire contents again, you can see that the directory name is changed to "TestFolder03".
pi@raspberrypi ~/testdata $ mv TestFolder01 TestFolder03 |
pi@raspberrypi ~/testdata $ ls –l |
total 16 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 manual01 drwxr-xr-x 2 pi pi 4096 Apr 10 03:58 TestFolder02 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 TestFolder03 -rwxrwx--- 1 pi pi 18 Mar 24 02:10 user_guide01.txt |
[Used Example] – change file name
We will try to change the file name here. In the following, if you look at the contents of the "testdata" directory before we work, you will see the "user_guide01.txt" file.
pi@raspberrypi ~/testdata $ ls –l |
total 16 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 manual01 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 TestFolder02 drwxr-xr-x 2 pi pi 4096 Apr 10 03:58 TestFolder03 -rwxrwx--- 1 pi pi 18 Mar 24 02:10 user_guide01.txt |
You can see that the file name is changed to "user_guide03.txt" when you do the following operation on the file "user_guide01.txt" and inquire contents again.
pi@raspberrypi ~/testdata $ mv user_guide03.txt user_guide03.txt |
pi@raspberrypi ~/testdata $ ls –l |
total 16 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 manual01 drwxr-xr-x 2 pi pi 4096 Apr 10 03:58 TestFolder02 drwxr-xr-x 2 pi pi 4096 Apr 10 04:07 TestFolder03 -rwxrwx--- 1 pi pi 18 Mar 24 02:10 user_guide03.txt |
16.2.2.2 Processing in Desktop Window
You can easily change the folder or file name using the [File Manager] in the Desktop window.
Run the program, select the parent folder that contains the folder or file you want to change, and then select the folder or file you want to rename on the right screen. In this case, we will use "TestFolder01", which is included in the "testdata" folder. Then, you can do the work by selecting the menu File à Rename, or using the menu Rename from the popup menu that appears when you click right-mouse button on on it.
Figure 16‑2 Rename folder or file in Desktop window