Basic Shell Commands in Linux

Last Updated : 11 Aug, 2026

Mastering basic shell commands is essential for anyone using Linux. These commands help users navigate the system, manage files, handle processes, and configure settings efficiently from the terminal. The shell serves as the interface between the user and the operating system, and understanding its commands is crucial for both system administrators and developers.

  • Enables efficient file and directory management
  • Provides essential system monitoring and process control
  • Helps configure network and system settings
  • Supports text processing, compression, and file permissions

Key Concepts

  • Shell: A command-line interface that allows users to interact with the operating system.
  • Commands: Instructions that tell the shell to perform specific tasks, such as managing files, handling processes, and monitoring the system.
  • Terminal: The program that runs the shell, allowing users to enter commands.

Commonly Used Shell Commands for Managing Files & Directories

These commands are essential for managing files and directories in Linux. They allow you to list, create, remove, and manipulate files and directories, which are fundamental tasks for working in the Linux environment.

Key Commands:

1. pwd: Prints the full path of the current working directory.

Example:

pwd

Output:

/home/user/Documents

2. cd: Changes the current directory to the specified path.

Example:

cd /home/user/Documents

3. ls: Lists files and directories in the current directory.

Example:

ls

Output:

file1.txt  file2.txt  directory1  directory2

4. mkdir: Creates a new directory with the specified name.

Example:

mkdir new_directory

5. touch: Creates an empty file or updates the timestamp of an existing file.

Example:

touch newfile.txt

6. cp: Copies files or directories from one location to another.

Example:

cp file1.txt file2.txt

7. mv: Moves or renames files and directories.

Example:

mv old_name new_name

8. rm: Removes a file or directory

Example:

rm file.txt

Text Processing Commands in Linux

These commands allow you to manipulate and display text data efficiently. They are especially useful for viewing, searching, and processing file content.

Key Commands:

1. cat: Displays the contents of a file.

Example:

cat file.txt

Output:

Hello, this is a test file.
This is the second line.

2. grep: Searches for a specific pattern in a file.

Example:

grep "error" log.txt

Output:

error: file not found
error: permission denied

3. sort: Sorts the contents of a file.

Example:

sort file.txt

Output:

line1
line2
line3

4. head: Displays the first few lines of a file (default is 10 lines).

Example:

head file.txt

Output:

Line 1 of file
Line 2 of file
Line 3 of file

5. tail: Displays the last few lines of a file (default is 10 lines).

Example:

tail file.txt

Output:

Last line of the file

6. wc: Counts the number of lines, words, and characters in a file.

Example:

wc file.txt

Output:

5  20  100 file.txt

File Permissions and Ownership Commands

Linux uses a permission system to manage who can access or modify files. These commands help you manage file permissions, ownership, and groups, ensuring secure and controlled access.

Key Commands:

1. chmod: Changes the permissions of a file or directory.

Example:

chmod 755 file.txt
  • 755: sets read, write, and execute permissions for the owner, and read and execute permissions for the group and others.

2. chown: Changes the owner and group of a file or directory.

Example:

chown user:group file.txt
  • user:group specifies the new owner and group for the file.

3. chgrp: Changes the group ownership of a file or directory.

Example:

chgrp group file.txt
  • Changes the group associated with the file to group.

System Monitoring and Process Management Commands

These commands are used to monitor system performance, check resources, and manage running processes. They help ensure that your system is running efficiently.

Key Commands:

1. top: Displays real-te system information, such as CPU and memory usage, along with a list of active processes.

Example:

top

2. ps: Displays a snapshot of current processes running on the system.

Example:

ps aux

Output:

USER    PID   %CPU  %MEM  VSZ  RSS  TTY  STAT  START  TIME  COMMAND
user 1234 0.1 0.2 1234 567 pts/0 S+ 08:00 0:00 bash
  • Lists all running processes along with details like CPU usage, memory usage, and the command that started the process.

3. kill: Terminates a process by its PID (Process ID).

Example:

kill 1234

4. df: Displays disk space usage for all mounted filesystems.

Example:

df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1 50G 20G 30G 40% /

Networking Shell Commands

These commands are used to test network connections, transfer files, and manage remote connections. They are essential for network troubleshooting and remote server management.

Key Commands:

1. ping: Checks the network connection to a server or host.

Example:

ping example.com

Output:

PING example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from example.com (93.184.216.34): icmp_seq=1 ttl=56 time=14.1 ms

2. wget: Downloads files from the web using HTTP, HTTPS, or FTP.

Example:

wget http://example.com/file.zip

Output:

--2026-01-31 12:00:00--  http://example.com/file.zip
Resolving example.com... 93.184.216.34
Connecting to example.com|93.184.216.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1024 (1.0K) [application/zip]
Saving to: ‘file.zip’

3. curl: Transfers data from or to a server using various protocols (HTTP, FTP, etc.).

Example:

curl http://example.com

Output:

  • The contents of the web page will be displayed in the terminal

4. ssh: Securely logs into a remote machine via SSH (Secure Shell).

Example:

ssh user@example.com
  • Prompt for password, connects to the remote system

5. scp: Securely copies files between hosts over SSH.

Example:

scp file.txt user@example.com:/path/to/destination/

Output:

file.txt                                100%  5000    5.0KB/s   00:01

6. ftp: Transfers files using the File Transfer Protocol.

Example:

ftp ftp.example.com

Advanced Shell Commands

These commands are used for advanced tasks like searching for files, creating backups, and managing remote systems. They are powerful tools that provide more flexibility in managing files and processes.

Key Commands:

1. find: Searches for files and directories based on criteria like name, size, or modification time.

Example:

find /home/user -type f -name "*.log" -mtime -7

Output:

/home/user/logs/log1.log
/home/user/logs/log2.log

2. rsync: Efficiently syncs files and directories between locations, locally or remotely, with advanced options for backup and transfer.

Example:

rsync -av /source/directory/ /backup/directory/

Output:

sending incremental file list
./
file1.txt
file2.txt

3. cron: Schedules tasks to run automatically at specified intervals.

Example:

Edit the crontab to schedule a backup script to run every day at midnight::

crontab -e
  • Add the following line to the crontab:
0 0 * * * /home/user/backup.sh

4. lsof: Lists open files and processes that are using them. This is useful for troubleshooting file and network issues.

Example:

lsof -i :80

Output:

COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx 1234 root 6u IPv4 123456 0t0 TCP *:http (LISTEN)

Using Shell Command Piping

Piping allows you to combine multiple commands in a chain, where the output of one command is used as the input for the next. This is one of the most powerful features of the Linux shell, enabling more complex and efficient workflows.

Key Commands:

1. | (Pipe Operator): Directs the output of one command as input to another. This allows combining commands to process data in stages.

Example:

View the top 10 processes by CPU usage.

ps aux | sort -nrk 3,3 | head -n 10
  • ps aux: lists all running processes.
  • sort -nrk 3,3: sorts the processes by CPU usage in descending order.
  • head -n 10: displays the top 10 processes.

Output:

USER      1234  50.0  30.0  100000  50000 ?        S    00:00   5.00 /usr/bin/some-process
USER 5678 25.0 20.0 50000 20000 ? S 00:05 3.00 /usr/bin/another-process

2. grep: Searches for specific patterns in input or files.

Example: Search for "error" in a log file and display the results.

cat log.txt | grep "error"

Output:

error: file not found
error: permission denied

3. sort: Sorts input in various ways.

Example: Sort a list of numbers in ascending order.

echo -e "5\n3\n8\n1" | sort -n

Output:

1
3
5
8

4. wc: Counts the number of lines, words, and characters in input.

Example: Count the number of lines in a file.

cat file.txt | wc -l

Output:

15

5. head and tail: Displays the first or last few lines of output.

Example: Display the first 5 lines of a long log file.

cat log.txt | head -n 5

Output:

Line 1 of the log
Line 2 of the log
Line 3 of the log
Line 4 of the log
Line 5 of the log
Comment

Explore