A simple Command Line Interface (CLI) application written in Python that mimics basic file operations like mkdir, cd, ls, cat, touch, echo, mv, cp, and rm. This tool allows users to perform these file operations directly from the terminal. It’s a modular CLI app where each command is implemented in its own separate file for easy maintenance and extension.
- mkdir: Create a new directory.
- cd: Change the current directory, including support for navigating to the parent directory using
.., the root directory using/, and any specified absolute path. - ls: List the contents of the current directory or a specified directory.
- cat: Display the contents of a file.
- touch: Create a new empty file.
- echo: Write text to a file.
- mv: Move a file or directory to another location.
- cp: Copy a file or directory to another location.
- rm: Remove a file or directory.
Make sure you have Python 3.x installed on your system. You can check the version of Python installed by running:
python --versionIf you don’t have Python installed, you can download it from python.org.
First, fork and clone the repository to your local system using Git:
git clone https://github.com/yourusername/in-memory-file-system.gitNavigate to the project directory:
cd in-memory-file-systemThis project does not have any external dependencies, as it only uses Python's built-in libraries (os, shutil, etc.), so no installation of extra packages is necessary. However, it’s always a good practice to work in a virtual environment:
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- For Windows:
venv\Scripts\activate
- For macOS/Linux:
source venv/bin/activate
- For Windows:
Once the repository is cloned and dependencies are set up, you can run the application by executing:
python app.pyThis will start a command-line interface where you can use the following commands:
- Usage:
mkdir <directory_path> - Description: Creates a new directory at the specified path.
- Example:
mkdir new_folder— Creates a directory namednew_folderin the current working directory.mkdir /home/user/projects— Creates a directory at the specified absolute path.
- Usage:
cd <directory_path> - Description: Changes the current working directory. Supports navigation to the parent directory using
.., to the root directory using/, and to a specified absolute or relative path. - Example:
cd ..— Moves up one level to the parent directory.cd /home/user/projects— Navigates to the absolute path/home/user/projects.cd ~— This will take you to the root directory (/).
- Usage:
ls <directory_path> - Description: Lists the contents (files and directories) of the current directory or a specified directory.
- Example:
ls— Lists the contents of the current directory.ls /home/user/projects— Lists the contents of the directory/home/user/projects.
- Usage:
cat <file_path> - Description: Displays the contents of the specified file in the terminal.
- Example:
cat file.txt— Displays the contents offile.txtin the terminal.cat /home/user/documents/notes.txt— Displays the contents of the file at the specified path.
- Usage:
touch <file_path> - Description: Creates a new empty file at the specified location. If the file already exists, it updates the file’s timestamp.
- Example:
touch newfile.txt— Creates an empty file namednewfile.txtin the current directory.touch /home/user/documents/file.txt— Creates an empty file at the specified absolute path.
- Usage:
echo '<text>' > <file_path> - Description: Writes the provided text to a file. If the file does not exist, it will be created. The
>operator overwrites the file, while>>appends the text. - Example:
echo 'Hello, World!' > hello.txt— Creates a filehello.txtand writes 'Hello, World!' into it.echo 'Appending text' >> file.txt— Appends the text tofile.txt.
- Usage:
mv <source_path> <destination_path> - Description: Moves a file or directory from the source path to the destination path.
- Example:
mv file.txt /home/user/new_folder/— Movesfile.txtto/home/user/new_folder/.mv old_file.txt new_file.txt— Renamesold_file.txttonew_file.txt.
- Usage:
cp <source_path> <destination_path> - Description: Copies a file or directory from the source path to the destination path.
- Example:
cp file.txt /home/user/backup/— Copiesfile.txtto/home/user/backup/.cp -r folder/ /home/user/backup/— Copies the directoryfolder/and all its contents to the backup location.
- Usage:
rm <file_or_directory_path> - Description: Removes the specified file or directory. Use the
-rflag to remove directories and their contents recursively. - Example:
rm file.txt— Removesfile.txtfrom the current directory.rm -r folder/— Removes the directoryfolder/and its contents.
To exit the CLI interface, you can use the exit command:
exitThe project is organized into the following files:
main.py: The main entry point for the CLI tool. Handles user input and calls the appropriate command functions.commands/: This directory contains separate Python files for each command (mkdir.py,cd.py,ls.py,cat.py,touch.py,echo.py,mv.py,cp.py,rm.py). Each file defines the functionality for a specific command.utils/: This directory can be used for shared utility functions, though this project does not require any currently.__init__.py: Required to mark directories as Python packages, allowing easy imports across files.
Thank you for using this CLI File Operations Tool. Happy coding! 🚀