Raspberry Pi

Navigating Raspberry Pi File System Using Terminal

Raspberry Pi uses a Linux based file system which can be difficult for those who are using Raspberry Pi for the first time and have never used Linux operating system before. Terminal is a most used application by the Raspberry Pi users to carry out different tasks, for using terminal effectively one must have a sound knowledge of commands used for performing different tasks. This writeup will explain different commands that one needs to remember while accessing the file system to Raspberry Pi using the terminal.

Creating Any Folder or Directory and Text File in Raspberry Pi

Before jumping to the commands first let’s see how to make directory or folders in raspberry Pi, there are few steps that you need to follow:

Step 1: First select where you want to make the new directory or folder, for instance if I want to make a folder in home directory then use the following command:

$ cd /home

Step 2: Next execute the following command to create a folder or directory:

$ sudo mkdir linuxhint

Now to see of the directory is created or not use the “ls” command:

So, this is how you can create a directory or folder in raspberry Pi using the terminal.

The process of creating a text file is simple as use just need to use the following command:

$ sudo nano linuxhint.txt

Graphical user interface Description automatically generated

In the above command the “linuxhint” is the filename and “.txt” is the format of the file. After executing the above command, a text file like that of notepad will open where you can enter the data and save it. So, this how you can create a file in Raspberry Pi of any format

Moving Files and Folders in Raspberry Using Terminal

Another important task that users normally do is moving the directories or files to their desired place and that is quite simple. Use the following command to move any directory of folder from one place to another:

$ sudo mv linuxhint /home/pi

To move the whole folder, you just need to give the folder name which you want to move and the path of the directory where you want to move the folder. Here in the above command “Linuxhint” is the folder and “/home/pi” is the path of the directory where I want to move this folder.

Moving a file from one directory to another

Moving a file is also quite simple just give the file name you want to move along with the directory where you want to move the file, use the following command in the terminal:

$ mv linuxhint.txt ~/Documents

The file I moved is “linuxhint.txt” in the “Documents” directory, so this how you can move a file in Raspberry Pi.

Copying Files and Folders in Raspberry Using Terminal

To copy a folder all you need to do is to give name of your folder along with the name of directory where you want to copy the folder and use the command given below:

$ cp -r linuxhint Documents

Graphical user interface, text Description automatically generated

Moreover, to copy a file state the file address and the folder name where you want to copy the file by executing the following command:

$ cp Documnets/linuxhint.txt Pictures/

To read further details of copying contents in Raspberry Pi read, how to copy files between directories in Raspberry Pi OS.

Some Useful Commands for Navigating Raspberry Pi File System

Navigating is not only limited to moving or copying files, but it also includes some commands like checking the contents of a directory, checking your current directory and some other similar functions. So here are some commands that can make your life easy while working on raspberry Pi:

“pwd”: This command is used to check the directory in which you are currently working.

Graphical user interface, text, application Description automatically generated

“ls”: To check the contents of any directory this command is used:

“ls -lh”: This command will show the overall size of the readable file along with the time and date of file creation:

“ls -r”: It makes the list of contents in the reverse order:

“ls -s”: It is used to arrange the contents of your current directory by the size of each file and shows the total size of directory along with the size of each file:

“cd”: To change the directory this command is used:

“cd –”: To move back to the previous directory this command is used:

The table below makes the use of commands more understandable:

Commands Description
pwd Gives the address of current directory
ls Shows the contents of directory
ls -lh show the overall size of the readable file along with the time and date of file creation
ls -r Arranges the list of contents in the reverse order:
ls -s Arrange the contents of your current directory by the size of each file and shows the total size of directory along with the size of each file
cd Serves the purpose of changing the directory
cd — To go to the previous directory

Conclusion

Raspberry Pi is a Linux based system that is quite different from other operating systems like Windows and Mac. The users who are working in Raspberry Pi for the first time might find it difficult to navigate through the file system of Raspberry Pi using the terminal. For moving the content, the command mv is used, for copying cp command is used and for getting the contents of a directory ls command is used.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.