Menu driven Python program to execute Linux commands Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Linux is one of the most popular operating systems and is a common choice for developers. However, it is difficult to remember the vast range of commands that Linux supports, and hence a Python program that can run these commands easily is demonstrated below. In this article, we will deal with a Python program that can be used to run complex Linux commands. This program is a drop-down menu that gives the user a choice list and the user can proceed with his/her required option. Python has an OS module that can be used to run or execute Linux commands. The os module helps interact with the Operating System. Here are the functionalities implemented in this program: Displaying the current date.Displaying the calendar.Configuring the web.Configuring docker.Adding a user.Deleting a user.Creating a file.Creating a folder. Python3 # importing the module import os # sets the text colour to green os.system("tput setaf 2") print("Launching Terminal User Interface") # sets the text color to red os.system("tput setaf 1") print("\t\tWELCOME TO Terminal User Interface\t\t\t") # sets the text color to white os.system("tput setaf 7") print("\t-------------------------------------------------") print("Entering local device") while True: print(""" 1.Print date 2.Print cal 3.Configure web 4.Configure docker 5.Add user 6.Delete user 7.Create a file 8.Create a folder 9.Exit""") ch=int(input("Enter your choice: ")) if(ch == 1): os.system("date") elif ch == 2: os.system("cal") elif ch == 3: os.system("yum install httpd -y") os.system("systemctl start httpd") os.system("systemctl status httpd") elif ch == 4: os.system("yum install docker-ce -y") os.system("systemctl start docker") os.system("systemctl status docker") elif ch == 5: new_user=input("Enter the name of new user: ") os.system("sudo useradd {}".format(new_user)) os.system("id -u {}".format(new_user) ) elif ch == 6: del_user=input("Enter the name of the user to delete: ") os.system("sudo userdel {}".format(del_user)) elif ch == 7: filename=input("Enter the filename: ") f=os.system("sudo touch {}".format(filename)) if f!=0: print("Some error occurred") else: print("File created successfully") elif ch == 8: foldername=input("Enter the foldername: ") f=os.system("sudo mkdir {}".format(foldername)) if f!=0: print("Some error occurred") else: print("Folder created successfully") elif ch == 9: print("Exiting application") exit() else: print("Invalid entry") input("Press enter to continue") os.system("clear") Running the application The application must be run on a Linux terminal. Steps to run the application: Open the root account from the computer. If one does not have access to the root account then some of the root privileged commands may not work properly.Open the Linux terminalGo to the location where the .py file is saved using the cd commandRun the .py file using python3 tui.py command Output Create Quiz Comment S Shreyasi_Chakraborty Follow 2 Improve S Shreyasi_Chakraborty Follow 2 Improve Article Tags : Python Python Programs python-utility python-os-module Python os-module-programs +1 More Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like