Skip to main content

Command Palette

Search for a command to run...

Managing Files and Folders on PythonAnywhere with Bash Commands.

Published
3 min read

Introduction

In this post, I’ll explain what directories and files are, how you can create, handle, and delete them with Bash commands on PythonAnywhere. Phrased as these commands they are relevant to any operating system based on Linux since they will help the users to organize, modify and manage directories and files, as well as clean them up. In this part, I will provide insight on how to go about the Basic bash commands like how to create more than one directory, how to add files and how to delete them.

Creating Directories

First, I started with the formation of 20 directories for various usages (documents, music, images, etc. ) in the Bash console using the mkdir command.

mkdir documents pictures downloads music videos projects notes backups reports logs work templates drafts code images scripts tests archives configs keys resources

The command that is used to create new directories is mkdir. It is done this way because all the directory names that are listed are created at the same time. The folders are as follows and each folder can be used for a specific type of data: Documents sub-folder for text files, music sub-folder for audio files, backups sub-folder for backup data.

Verification: To ensure that the directories were created well, I had to use a linux command known is

ls

This lists all the folders in the current directory including the hidden ones and also the subdirectories.

Adding Files

Then, I typed “cd docs” to go to the documents directory then created 10 text files using the command “touch filename”. Here’s how I did it: Here’s how I did it:

  1. First, I moved into the documents directory:

     cd documents
    
  2. Then, I created 10 files in one go using:

touch file{1..10}.txt

The touch command for creating zero bytes files, or alter timestamps on files. Compiling the languages using the {1..10} syntax yields the names of the files as file1. txt to file10. txt automatically.

Verification: To verify the creation of the files, I listed the contents of the documents folder with:

ls

Removing Files and Directories

For cleaning up I had to delete certain files and directories.

  1. Removing Files: I deleted a file using the rm command from the documents directory. For example, to delete file5.

     rm file5.txt
    

    This command removes the file, The rm command is undesirable for recovery as it deletes the file permanently from the OS.

  2. Removing Directories: I also had no choice but to delete root..documents and all the sub directories that were within it. Since the directory contained files, I used the rm -r command, which allows recursive deletion of a directory and its files:Since the directory contained files, I used the rm -r command, which allows recursive deletion of a directory and its files:

     cd ..
     rm -r documents
    

    The -r flag makes the overall command recursive therefore, it is able to delete the folder and all its sub-folder or files.

More from this blog

yvankov

6 posts

for school purposes