Raspberry Pi

Naming Files and Folders – Raspberry Pi

Files are the major part of a storage in any system and the ideal way to keep the files saved is to organize them inside a folder. A folder is basically a place where you store all your files. To properly organize the data, it’s necessary for everyone to name them. Since Raspberry Pi is a Linux-based system, the process of naming the files and folders differs from other systems like Windows and macOS.

In this article, we will discuss how you can name the files and folders on your Raspberry Pi system.

Let’s begin!

Naming Files and Folders

The process of naming a file starts when you first create a file and it is always recommended to set a proper name for a file at the time of its creation.

If you want to create a file on Raspberry Pi system, follow the below-mentioned syntax:

$ sudo nano <file name>

To create my-linux-file, use:

$ sudo nano my-linux-file

Executing the above command will open an empty file on your terminal.

Users can add any text to the file.

Later, the file can be saved using the “Ctrl + X” keys and add “Y” to confirm saving the file and finally press the Enter key to exit the file.

However, if there is a space between the file name, you can use the “\” between the space to access the file. Like, a file named “my linux” can be accessed using the command “my\ linux”, while the rest process is like the one shown above.

$ sudo nano my\ linux

Create a Folder/Directory

In Linux terminology, we call folders as directories. To create a new directory with a user-assigned name, follow the below-mentioned syntax:

$ mkdir <name of folder>

Example of the above command syntax is given below:

$ mkdir linuxhint-folder

linuxhint-folder” is the name of my folder/directory that I have created here, you can use any other name of your choice. Again, in a similar fashion if you want to name a folder with space between the name, you have to use “/”.

To check whether the folder is created in the home directory, you can type the following command:

$ ls

It is always recommended to create folders/directories with the name that represents the content of files present in it. For instance, if you are creating a directory to keep image files, you can name it as “Images”. Similarly for text files, create a directory with the name “Documents” and for audio files, you can name the directory as “Audios” or “Music”. However, make sure that the directories you want to create don’t exist at the desired location.

Let’s suppose if I want to create a directory with the name “Music” inside the home directory, I will get an error if the file already exists and it cannot create the directory. You must provide another name for your directory.

Once the directories are created, you can navigate to the directory using the following command:

$ cd <directory name>

In the below example, I am navigating to my directory, which I created earlier:

$ cd linuxhint-folder

If you want to go back to home directory, you can use the following command:

$ cd ~

You can also provide the directory path to navigate to a directory:

$ cd <Path to directory>

To enter Downloads directory:

$ cd /home/pi/Downloads

Renaming a File and Folder

If you have previously created a file and want to rename it, you can use the below-mentioned syntax:

$ mv <source file_name> <new_file_name>

An example of the above code is given below:

$ mv my-linux-file my-new-file

Note: “my-linux-file” is the name of my file and “my-new-file” is the new file name that I assigned to file.

If you want to rename a directory, you can use the mv command in the same way as it is used to rename a file:

$ mv <directory name> <new name for directory>

In the below image, linuxhint-folder is the name of my folder, which I want to rename and new-folder is the new name for the folder. Users can change these according to their requirements.

$ mv linuxhint-folder new-folder

The mv command can also be used to move files from one folder to another, so let’s move our file from the home/pi directory to the Documents directory, and for that follow the below-mentioned command:

$ mv <path of file> <new destination>

Note: In the image below, I am moving my renamed file which is my-new-file to the Documents directory, users can change this according to their requirement.

$ mv my-new-file /home/pi/Documents

To move one folder/directory to another location, use the below-mentioned command:

$ mv <path of directory> <new destination>

Here, I have moved the new-folder from Desktop to the Downloads directory.

$ mv /home/pi/Desktop/new-folder /home/pi/Downloads

You can choose the same syntax to move your directory to another location.

That’s it for this guide!

Conclusion

Naming files and folders properly is useful as this will help you organize your data. Through the above guidelines, you will learn how to name a file and folder with and without spaces. Further, you should ensure that for proper file organization, try to name folders that define the files category, and you should put all your files inside this directory like audio files must be placed inside a Music directory and so on.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.