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 contentscd
– Change the current directorypwd
– Print working directorycp
– Copy files and directoriesmv
– Move or rename files and directoriesrm
– Remove files or directoriestouch
– Create an empty filemkdir
– Create a new directoryrmdir
– Remove an empty directorychmod
– Change file permissionschown
– Change file owner and groupps
– Display currently running processeskill
– Terminate processesdf
– Display disk space usagedu
– 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 thesystemctl
command:
- 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 addr
orifconfig
- Bring an interface up:
sudo ip link set dev interface up
orsudo ifconfig interface up
- Bring an interface down:
sudo ip link set dev interface down
orsudo ifconfig interface down
- Configure an IP address:
sudo ip addr add ip_address/dev interface
orsudo ifconfig interface ip_address
- View routing table:
ip route
orroute
- Add a static route:
sudo ip route add destination via gateway
orsudo 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