DEV Community

Cover image for Essential Linux Terminal Commands and Examples
orioninsist
orioninsist

Posted on • Updated on

Essential Linux Terminal Commands and Examples

Master essential Linux terminal commands with explanations and practical examples. Learn how to navigate, copy, delete files, and more. Enhance your command-line skills now!
Table of Contents

  1. tar - Archiving and Compression
  2. rm - Removing Files and Directories
  3. ls - Listing Files and Directories
  4. history - Command History
  5. whoami - Current User
  6. uname - System Information
  7. ping - Network Connectivity
  8. date - Current Date and Time
  9. cp - Copying Files and Directories
  10. mkdir - Creating Directories
  11. pwd - Present Working Directory
  12. cd - Changing Directories
  13. file - File Type Information
  14. head and tail - Viewing File Content
  15. echo - Printing to the Terminal
  16. more and cat - File Content Display
  17. mv - Moving and Renaming Files
  18. wc - Word Count and Line Count
  19. sort - Sorting Lines in Files
  20. grep - Searching for Text Conclusion GitHub Thank you

The Linux terminal is a powerful tool that allows users to interact with their system through text-based commands. Whether you're a beginner or an experienced user, having a grasp of basic terminal commands is crucial. In this guide, we'll explore some essential Linux terminal commands along with explanations and practical examples.

1. tar - Archiving and Compression

The tar command is used for archiving and compressing files and folders.

  • Create a compressed archive of a file:
tar -zcvf archive.tar filename
Enter fullscreen mode Exit fullscreen mode
  • Create an archive of multiple files:
tar -zcvf archive2.tar filename1 filename2 filename3
Enter fullscreen mode Exit fullscreen mode
  • Create an archive of a folder:
tar -zcvf folder.tar folder/
Enter fullscreen mode Exit fullscreen mode

2. rm - Removing Files and Directories

The rm command is used to remove files and directories.

  • Remove a directory and its contents:
rm -r folder/
Enter fullscreen mode Exit fullscreen mode
  • Remove multiple files:
rm filename1 filename2 filename3
Enter fullscreen mode Exit fullscreen mode

3. ls - Listing Files and Directories

The ls command lists the contents of a directory.

  • List all files and directories in long format:
ls -al
Enter fullscreen mode Exit fullscreen mode

4. history - Command History

The history command displays previously executed commands.

  • Display command history:
history
Enter fullscreen mode Exit fullscreen mode
  • Clear command history:
history -c
Enter fullscreen mode Exit fullscreen mode

5. whoami - Current User

The whoami command displays the current user.

  • Display current user:
whoami
Enter fullscreen mode Exit fullscreen mode

6. uname - System Information

The uname command provides system information.

  • Display system and kernel information:
uname -a
Enter fullscreen mode Exit fullscreen mode
  • Display kernel release information:
uname -r
Enter fullscreen mode Exit fullscreen mode

7. ping - Network Connectivity

The ping command checks network connectivity to a host.

  • Ping a host four times:
ping -c4 orioninsist.org
Enter fullscreen mode Exit fullscreen mode

8. date - Current Date and Time

The date command displays the current date and time.

  • Display current date and time:
date
Enter fullscreen mode Exit fullscreen mode

9. cp - Copying Files and Directories

The cp command is used to copy files and directories.

  • Copy a file with a new name:
cp filename newfilename
Enter fullscreen mode Exit fullscreen mode
  • Copy a file to a specific directory:
cp filename /home/orion/
Enter fullscreen mode Exit fullscreen mode
  • Copy a directory and its contents recursively:
cp -r /home/orion/newfolder /tmp/newfolder
Enter fullscreen mode Exit fullscreen mode

10. mkdir - Creating Directories

The mkdir command creates directories.

  • Create a new directory:
mkdir newfolder
Enter fullscreen mode Exit fullscreen mode

11. pwd - Present Working Directory

The pwd command displays the present working directory.

  • Display current directory path:
pwd
Enter fullscreen mode Exit fullscreen mode

12. cd - Changing Directories

The cd command is used to change directories.

  • Change to the Desktop directory:
cd Desktop
Enter fullscreen mode Exit fullscreen mode
  • Move up one directory level:
cd ..
Enter fullscreen mode Exit fullscreen mode

13. file - File Type Information

The file command provides information about file types.

  • Determine file type:
file filename.txt
Enter fullscreen mode Exit fullscreen mode

14. head and tail - Viewing File Content

The head and tail commands display the beginning and end of files.

  • Display the first lines of a file:
head filename.txt
Enter fullscreen mode Exit fullscreen mode
  • Display the last lines of a file:
tail filename.txt
Enter fullscreen mode Exit fullscreen mode

15. echo - Printing to the Terminal

The echo command prints text to the terminal.

  • Append new content to a file:
echo "new content" >> filename.txt
Enter fullscreen mode Exit fullscreen mode

16. more and cat - File Content Display

The more and cat commands display file content.

  • Display file content with paging:
more filename.txt
Enter fullscreen mode Exit fullscreen mode
  • Concatenate and display multiple files:
cat filename.txt filename2.txt
Enter fullscreen mode Exit fullscreen mode

17. mv - Moving and Renaming Files

The mv command moves or renames files and directories.

  • Move a file to a new directory:
mv filename newfolder/
Enter fullscreen mode Exit fullscreen mode

18. wc - Word Count and Line Count

The wc command counts words, lines, and characters in a file.

  • Count words in a file:
wc -w filename.txt
Enter fullscreen mode Exit fullscreen mode
  • Count lines in a file:
wc -l filename.txt
Enter fullscreen mode Exit fullscreen mode

19. sort - Sorting Lines in Files

The sort command sorts lines in files.

  • Sort lines in a file:
sort filename.txt
Enter fullscreen mode Exit fullscreen mode
  • Sort lines based on the second field:
sort -k 2 filename.txt
Enter fullscreen mode Exit fullscreen mode

20. grep - Searching for Text

The grep command searches for text in files.

  • Search for a specific pattern:
grep "orion" filename.txt
Enter fullscreen mode Exit fullscreen mode
  • Search for a pattern and exclude matches:
grep -v "orion" filename.txt
Enter fullscreen mode Exit fullscreen mode

Conclusion

These are just a few of the fundamental Linux terminal commands that can empower you to navigate and interact with your system efficiently. As you continue to explore the Linux terminal, you'll discover even more commands and functionalities that can help you streamline your workflow and manage your system effectively. So, dive in, experiment, and become a master of the Linux command line!

GitHub

⭐ GitHub: https://github.com/orioninsist/linux-basic

Thank you

Thank you for your continued support, and I’m excited to have you on this enriching journey!

Sincerely, Founder of orioninsist

Follow the white rabbit

Thank you for your support! Hello friends! I want to express my gratitude for your support. Your interest and encouragement mean a lot to me. To keep our connection strong and to provide you with more valuable content, I encourage you to stay connected with me on my social media platforms.

I am excited to share more content with you through these platforms and I value your engagement and feedback. Thank you once again for your support. Let’s stay connected and keep the conversation going!

Your feedback and engagement mean the world to me. Thank you once again for your unwavering support.

Let’s continue to “follow the white rabbit” and discover new horizons together!

Best regards,

Murat Kurkoglu

Founder of orioninsist

Google Survey Forms

Top comments (1)

Collapse
 
respect17 profile image
Kudzai Murimi

Useful!