Skip to content

Basic Linux Commands

Introduction

Linux commands provide the most powerful way to interact with the operating system. Learning these commands is essential for navigating and managing a Linux environment efficiently. This guide covers some of the most commonly used basic Linux commands.

pwd

The pwd command (print working directory) displays the current working directory.

pwd

ls

The ls command lists files and directories in the current directory.

ls

Options: - ls -l: Detailed list - ls -a: Show hidden files

cd

The cd command (change directory) allows you to move between directories.

cd /path/to/directory

mkdir

The mkdir command (make directory) creates a new directory.

mkdir new_directory

rmdir

The rmdir command (remove directory) deletes an empty directory.

rmdir directory_name

rm

The rm command (remove) deletes files or directories.

rm file_name

Options: - rm -r directory_name: Recursively delete a directory and its contents

File Operations

cp

The cp command (copy) copies files or directories.

cp source_file destination_file

Options: - cp -r source_directory destination_directory: Recursively copy a directory

mv

The mv command (move) moves or renames files or directories.

mv old_name new_name

cat

The cat command (concatenate) displays the contents of a file.

cat file_name

less

The less command displays the contents of a file one page at a time.

less file_name

The head command displays the first few lines of a file.

head file_name

tail

The tail command displays the last few lines of a file.

tail file_name

Options: - tail -f file_name: Follow the file as it grows

Managing Processes

ps

The ps command (process status) displays information about running processes.

ps

Options: - ps aux: Detailed process list

top

The top command displays a dynamic, real-time view of running processes.

top

kill

The kill command terminates a process.

kill process_id

Options: - kill -9 process_id: Forcefully terminate a process

Permissions

chmod

The chmod command (change mode) changes file or directory permissions.

chmod permissions file_name

Example: - chmod 755 file_name: Read, write, execute for owner; read, execute for group and others

chown

The chown command (change owner) changes the ownership of a file or directory.

chown owner:group file_name

Networking

ifconfig

The ifconfig command configures network interfaces.

ifconfig

ping

The ping command checks connectivity to a network host.

ping host_name_or_ip

netstat

The netstat command displays network connections, routing tables, and interface statistics.

netstat

Package Management (Debian-based systems)

apt-get

The apt-get command installs, updates, and removes packages.

sudo apt-get update
sudo apt-get install package_name
sudo apt-get remove package_name

apt

The apt command is a more user-friendly interface for apt-get.

sudo apt update
sudo apt install package_name
sudo apt remove package_name

System Information

uname

The uname command displays system information.

uname -a

df

The df command (disk free) displays disk space usage.

df -h

du

The du command (disk usage) displays the size of files and directories.

du -h file_or_directory

free

The free command displays memory usage.

free -h

Conclusion

These basic Linux commands provide a foundation for interacting with and managing a Linux system. Mastering these commands will enhance your ability to navigate the file system, manage files, monitor processes, and handle system administration tasks efficiently.