Raspberry Pi

Navigating File Structure – Raspberry Pi Linux

The Raspberry Pi is a Linux-based system where most of the tasks are handled through its terminal. From installing a simple application to creating a high-end application, you will always put yourself into a situation where you have no other choice except to move around the Raspberry Pi files and directories.

If you need help in managing files, directories, and other stuff right from your Raspberry Pi terminal, follow this article to learn about navigating file structure on the Raspberry Pi system.

So, let’s start this guide!

Navigating File Structure – Raspberry Pi Linux

Here you will learn different methods to work with files and directories on your Raspberry Pi system.

Navigate Present Writing Directory

At some stage you may need to find the location of the present directory you are in and for this purpose, you can execute the following command in your terminal to see the location of the present writing directory.

$ pwd

As a result of the above command, the present directory will display on the terminal.

List of Files/Directories

If you want to see the list of directories inside the present directory, you can type the following command:

$ ls

As a result of the above command, all the directories listed will be displayed on the terminal.

List the File Size

To display the list of files along with the size of each file, the below-mentioned command can be copied into the terminal.

$ ls -s

File Information

To display the list of files along with the readable size and time/date of each file creation, you can use the following command:

$ ls -lh

Change Directory

The “cd” command is used for changing the directory as it takes you directly toward the other directory through a single command. However, you must need to provide the directory name or path using the following syntax:

$ cd <directory-path>

Note: Remember to use your required directory name at a place of <directory-path> in the above command.

For example, to navigate to the Downloads folder use:

$ cd Downloads

To move back to previous directory below mentioned command can be used:

$ cd --

Move a File

In case you want to move a file from one directory to another, you can easily do it from the following command:

$ mv <file-name> ~/<destination-path>

Note: Remember in the above command replace <file-name> and <destination-path> according to your required file name and directory.

For example, the following command is moving the linux-raspi.txt file to the Downloads directory.

$ mv linux-raspi.txt ~/Downloads

Make sure that the file is there in the current directory you are working in.

Copy a File

If you want to just copy the file and send it to another location, you can follow the below-mentioned command:

$ cp <file-path>/<filename> <destination-path>/

Note: Remember to change the <file-path> and <destination-path> according to your requirement. <file-path> is the directory where your file is placed and <destination-path> is where you want to copy the file.

For example

$ cp Downloads/linux-raspi.txt Desktop/

The ls command in the above image is used to check the copied file on the desktop.

Remove a File

You may need to remove a file from your Raspberry Pi system at some stage. For this purpose, you can use the following command to remove a file from your Raspberry Pi system:

$ rm <file-name>

Note: Remember to replace <file name > with the name of the file you want to remove then press “Enter”.

To remove linux-raspi.txt file use:

$ rm linux-raspi.txt

That’s it for this guide!

Conclusion

Navigating files structure in the Linux-based operating system of Raspberry Pi can be a little different than other operating systems. To navigate file structure in Raspberry Pi, different commands are used like pwd, ls, ls -lh, cd and others. To move and copy the file mv and cp commands are used. Lastly, an rm command can be used to remove the required file.

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.