DEV Community

Cover image for Getting Started with Linux: A Beginner's Guide to Basic Commands
Prakhar Singh
Prakhar Singh

Posted on

Getting Started with Linux: A Beginner's Guide to Basic Commands

Hello and welcome to the world of Linux! Whether you're a seasoned programmer or just starting your journey into the realm of operating systems, Linux offers a robust and versatile environment for all users. In this guide, we'll explore the basics of Linux, from understanding what it is to learning essential commands that will help you navigate and utilize this powerful OS.

What is Linux?

Linux is an open-source operating system that has become incredibly popular due to its flexibility, security, and the strong community of developers that support it. Linux is free to use and modify, making it an excellent choice for those who want to have more control over their computing environment.

Why Use Linux?

Linux is one of the most popular platforms on the planet. It has been around since the mid-1990s and has since reached a user-base that spans the globe. Even Android is powered by the Linux operating system.

Moreover, there are several compelling reasons to use Linux:

  • Security: Linux is known for its robust security features.
  • Customizability: You can tailor Linux to meet your specific needs.
  • Performance: Linux can run on a wide range of hardware, from powerful servers to old laptops.
  • Community Support: A vibrant community of users and developers who are ready to help.


Getting Started with Basic Commands :

One of the most empowering aspects of using Linux is mastering the command line. While the graphical user interface (GUI) provides a visual way to interact with the system, the command line offers unparalleled control and efficiency. Here are some fundamental commands to get you started:

NOTE : Linux is nothing more than a group of files.

1. Displaying Text with echo

The echo command is used to display a line of text. It's a simple yet powerful command that you'll use frequently.

echo Hello, World!
Enter fullscreen mode Exit fullscreen mode

This command outputs:

 Hello, World!
Enter fullscreen mode Exit fullscreen mode

2. Navigating the File System

  • pwd : Print Working Directory

Use this command to display your current directory.

 pwd

Enter fullscreen mode Exit fullscreen mode

Output example:

/home/username
Enter fullscreen mode Exit fullscreen mode
  • ls : List Directory Contents

This command lists all files and directories in the current directory.

 ls
Enter fullscreen mode Exit fullscreen mode

Output example:

Desktop  Documents  Downloads  Pictures
Enter fullscreen mode Exit fullscreen mode
  • ls -a : List All Files

This command lists all files, including hidden ones.

ls -a
Enter fullscreen mode Exit fullscreen mode

Output example:

.  ..  .bashrc  .profile  Documents  Downloads

Enter fullscreen mode Exit fullscreen mode
  • ls / : List Root Directory Contents

This command lists all files and directories in the root directory.

 ls /
Enter fullscreen mode Exit fullscreen mode

Output example:

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

Enter fullscreen mode Exit fullscreen mode
  • cd : Change Directory

Use cd to navigate to a different directory.

cd Documents
Enter fullscreen mode Exit fullscreen mode

This command moves you to the "Documents" directory.

  • cd / : Change to Root Directory

Use this command to move to the root directory.

 cd /
Enter fullscreen mode Exit fullscreen mode
  • cd .. : Move Up One Directory Level

This command moves you one level up in the directory hierarchy.

cd ..
Enter fullscreen mode Exit fullscreen mode
  • cd - : Move to Previous Directory

This command takes you back to the last directory you were in.

  cd -
Enter fullscreen mode Exit fullscreen mode
  • cd -- : Another way to move to the previous directory (less commonly used)
  cd --
Enter fullscreen mode Exit fullscreen mode

3. File and Directory Operations

  • mkdir : Create a New Directory
 mkdir new_directory
Enter fullscreen mode Exit fullscreen mode

This command creates a directory named new_directory.

  • touch : Create a New File
 touch newfile.txt
Enter fullscreen mode Exit fullscreen mode

This command creates an empty file named newfile.txt.

  • cp : Copy Files
  cp source.txt destination.txt

Enter fullscreen mode Exit fullscreen mode

This command copies source.txt to destination.txt.

  • cp -r : Copy Directories Recursively
 cp -r source_directory destination_directory
Enter fullscreen mode Exit fullscreen mode

This command copies source_directory and all its contents to destination_directory.

  • mv : Move or Rename Files
    mv oldname.txt newname.txt

Enter fullscreen mode Exit fullscreen mode

This command renames oldname.txt to newname.txt.

  • rm : Remove Files
rm file.txt
Enter fullscreen mode Exit fullscreen mode

This command deletes file.txt.

  • rm -r : Remove Directories Recursively
 rm -r directory_name
Enter fullscreen mode Exit fullscreen mode

This command deletes directory_name and all its contents.

4. Viewing and Editing Files

  • cat : Concatenate and Display Files
cat file.txt
Enter fullscreen mode Exit fullscreen mode

This command displays the content of file.txt.

  • less and more: View File Contents Page by Page
less file.txt
Enter fullscreen mode Exit fullscreen mode
 more file.txt
Enter fullscreen mode Exit fullscreen mode

These commands allow you to scroll through file.txt one page at a time.

  • vi : Text Editor
 vi file.txt
Enter fullscreen mode Exit fullscreen mode

This command opens file.txt in the vi text editor, a powerful tool for editing text files.

5. System Commands

  • clear : Clear the Terminal Screen
 clear
Enter fullscreen mode Exit fullscreen mode

This command clears the terminal screen.

  • find : Search for Files
find / -name filename
Enter fullscreen mode Exit fullscreen mode

This command searches the entire file system for filename.

  • history : Show Command History
  history
Enter fullscreen mode Exit fullscreen mode

This command displays a list of previously executed commands.

  • sudo su - : Switch to the Superuser
 sudo su -
Enter fullscreen mode Exit fullscreen mode

This command allows you to switch to the superuser account, giving you administrative privileges.

  • sudo apt update : Update Package Index
sudo apt update

Enter fullscreen mode Exit fullscreen mode

This command updates the package index on Debian-based systems, ensuring you have the latest information about available packages.


Conclusion

Congratulations! You've taken your first steps into the world of Linux. By learning and practicing these basic commands, you'll build a strong foundation that will allow you to explore more advanced features and capabilities of this powerful operating system. Stay curious, keep experimenting, and enjoy your journey with Linux!

Thanks for Reading! 🔖 Please Like, Share and Follow. Your support matters.🌟

Top comments (0)