The Wayback Machine - https://web.archive.org/web/20250327123459/https://www.geeksforgeeks.org/basic-shell-commands-in-linux/
Open In App

Basic Shell Commands in Linux: Complete List

Last Updated : 08 Mar, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Anyone using Linux should become an expert in the essential shell commands, as they form the backbone of working with the Linux terminal. These commands enable you to navigate the system, manage files, handle processes, and configure settings effectively.

The Linux shell serves as an interface for users to interact with the operating system. Mastering its commands can greatly enhance your efficiency, whether you’re a system administrator or a developer. In this guide, we’ll introduce some of the most fundamental Linux commands, covering file management, system monitoring, and command syntax, along with practical examples. By the end, you’ll have the knowledge needed to perform everyday tasks confidently in the Linux command-line environment.

Basic-Shell-Commands-in-Linux_-Complete-List

Basic Shell Commands in Linux

What are Shell Commands in Linux?

A shell in Linux is a program that serves as an interface between the user and the operating system. It accepts commands from the user, interprets them, and passes them to the operating system for execution. The commands can be used for a wide range of tasks, from file manipulation to system management.

Some of the essential basic shell commands in Linux for different operations are:

  • File Management -> cp, mv, rm, mkdir
  • Navigation -> cd, pwd, ls
  • Text Processing -> cat, grep, sort, head
  • System Monitoring -> top, ps, df
  • Permissions and Ownership -> chmod, chown, chgrp
  • Networking – > ping, wget, curl, ssh, scp, ftp
  • Compression and Archiving – > tar, gzip, gunzip, zip, unzip
  • Package Management – > dnf, yum, apt-get
  • Process Management -> kill, killall, bg, killall, kill

Basic Shell Commands for File and Directory Management

Command Description Example
ls Lists files and directories ls
cd Changes the current directory cd /home/user/Documents
pwd Displays the current directory path pwd
mkdir Creates a new directory mkdir new_directory
rm Removes files or directories rm file.txt
cp Copies files or directories cp file1.txt file2.txt
mv Moves or renames files and directories mv old_name new_name
touch Creates an empty file or updates file timestamps touch newfile.txt

Examples:

1. List files in a directory:

ls

2. Change directory:

cd/home/user

3. Create a new directory:

mkdir new_directory

4. Copy a file from one location to another:

cp source.txt destination.txt

5. Remove a file:

rm file.txt

Text Processing Commands in Linux

Command Description Example
cat Displays the contents of a file cat file.txt
grep Searches for a pattern in a file grep "error" log.txt
sort Sorts the contents of a file sort file.txt
head Displays the first few lines of a file head file.txt
tail Displays the last few lines of a file tail file.txt
wc Counts the lines, words, and characters in a file wc file.txt

Examples:

1. Display the contents of a file:

cat file.txt

2. Search for a pattern in a file:

grep "error" file.txt

3. Sort the contents of a file:

sort file.txt

4. Display the first 10 lines of a file:

head file.txt

5. Display the last 10 lines of a file:

tail file.txt

File Permissions and Ownership Commands

Command Description Example
chmod Changes file permissions chmod 755 file.txt
chown Changes file owner and group chown user:group file.txt
chgrp Changes file group ownership chgrp group file.txt

Examples:

1. Change permissions of a file:

chmod 755 file.txt

2. Change the owner of a file:

chown user:group file.txt

System Monitoring and Process Management Commands

Command Description Example
top Displays real-time system information (CPU, memory) top
ps Displays the list of running processes ps aux
kill Terminates a process by its ID kill 1234
df Displays disk space usage df -h

Examples:

1. View running processes:

ps aux

2. Display real-time system statistics:

top

3. Kill a process by its ID:

kill 1234

4. Check disk space usage:

df -h

Networking Shell Commands

Command Description Example
ping Checks the network connection to a server ping example.com
wget Retrieves files from the web wget http://example.com/file.zip
curl Transfers data from or to a server curl http://example.com
ssh Opens SSH client (remote login program) ssh user@example.com
scp Securely copies files between hosts scp file.txt user@example.com:/path/
ftp Transfers files using the File Transfer Protocol ftp ftp.example.com

Examples

1. Check the network connection to a server:

  • Command: ping
  • Example: ping example.com

2. Retrieve files from the web:

  • Command: wget
  • Example: wget http://example.com/file.zip

3. Transfer data from or to a server:

  • Command: curl
  • Example: curl http://example.com

4. Open SSH client (remote login program):

  • Command: ssh
  • Example: ssh user@example.com

5. Securely copy files between hosts:

  • Command: scp
  • Example: scp file.txt user@example.com:/path/

6. Transfer files using the File Transfer Protocol:

  • Command: ftp
  • Example: ftp ftp.example.com

Advanced Shell Commands

Command Description Example
find Searches for files and directories find /home/user -name "*.txt"
tar Archives files into a tarball (.tar) or extracts them tar -cvf archive.tar file1.txt file2.txt
ssh Connects to a remote machine via SSH ssh user@remote_host

Examples:

1. Find files in a directory:

find /home/user -name "*.txt"

2. Create a tarball archive:

tar -cvf archive.tar file1.txt file2.txt

3. Connect to a remote machine using SSH:

ssh user@remote_host

Using Shell Command Piping

You can combine multiple commands by piping their output. In short, it allows the output of one command to be used as the input for another command.

Examples:

1. View the top 10 processes:

ps aux | head -n 10

2. Search and sort a log file:

grep "error" log.txt | sort

Conclusion

Mastering the basic shell commands in Linuxis among the essential things to know so that you can perform a seamless system navigation, learn how to manage files efficiently, and perform other operations. By learning these commands, you can easily enhance your Linux skills and get a better insight over the system.

Basic Shell Commands in Linux – FAQ’s

What is the ls command in Linux?

It is used to list all files and directories in the current directory.

How do I copy files using the cp command?

Use the following syntax to copy using cp command:

cp source_file destination_file

How can I check disk space usage using df?

You can use the df command to check the disk space, here’s the syntax below:

df -h

How do I move files with the mv command?

To move or rename files, use the mv command:

mv old_name new_name


Next Article

Similar Reads

three90RightbarBannerImg