shell

Linux Command Line Basics

Introduction

Welcome to the Linux command line basics tutorial. In this lesson, you will learn how to use the Linux command line, common commands and file locations, basic functions like starting and stopping services, managing users, connecting to SSH, and configuring network and firewall settings.

Common Commands

Here are some of the most commonly used Linux commands:

  • ls– List directory contents
  • cd– Change the current directory
  • pwd– Print working directory
  • cp– Copy files and directories
  • mv– Move or rename files and directories
  • rm– Remove files or directories
  • touch– Create an empty file
  • mkdir– Create a new directory
  • rmdir– Remove an empty directory
  • chmod– Change file permissions
  • chown– Change file owner and group
  • ps– Display currently running processes
  • kill– Terminate processes
  • df– Display disk space usage
  • du– Display file space usage

Common File Locations

Linux file system is structured in a hierarchical manner. Here are some important directories:

  • /– Root directory
  • /home– User home directories
  • /etc– Configuration files
  • /var– Variable files like logs and databases
  • /usr– User binaries and programs
  • /bin– Essential command binaries
  • /sbin– System binaries
  • /lib– Essential shared libraries and kernel modules
  • /tmp– Temporary files
  • /dev– Device files
  • /proc– Process and kernel information files
  • /mnt– Mount point for temporary filesystems

Starting and Stopping Services

To manage services on a Linux system, you can use thesystemctlcommand:

  • Start a service:sudo systemctl start service_name
  • Stop a service:sudo systemctl stop service_name
  • Restart a service:sudo systemctl restart service_name
  • Enable a service to start on boot:sudo systemctl enable service_name
  • Disable a service:sudo systemctl disable service_name
  • Check the status of a service:sudo systemctl status service_name

Managing Users

To manage users on a Linux system, you can use the following commands:

  • Add a new user:sudo adduser username
  • Delete a user:sudo deluser username
  • Change a user’s password:sudo passwd username
  • Add a user to a group:sudo usermod -aG groupname username
  • View user information:id username

Connecting to SSH

To connect to a remote Linux server using SSH, use the following command:ssh username@hostname_or_ip

For example:ssh [email protected]

Configuring Network

To configure network settings on a Linux system, you can use the following commands:

  • View network interfaces:ip addrorifconfig
  • Bring an interface up:sudo ip link set dev interface uporsudo ifconfig interface up
  • Bring an interface down:sudo ip link set dev interface downorsudo ifconfig interface down
  • Configure an IP address:sudo ip addr add ip_address/dev interfaceorsudo ifconfig interface ip_address
  • View routing table:ip routeorroute
  • Add a static route:sudo ip route add destination via gatewayorsudo route add -net destination netmask netmask gw gateway

Configuring Firewall

To manage firewall settings on a Linux system, you can useufw(Uncomplicated Firewall):

  • Enable firewall:sudo ufw enable
  • Disable firewall:sudo ufw disable
  • Allow a port:sudo ufw allow port_number
  • Deny a port:sudo ufw deny port_number
  • Allow a service:sudo ufw allow service_name
  • Deny a service:sudo ufw deny service_name
  • Check firewall status:sudo ufw status
Other Recent Posts