DEV Community

Cover image for ๐Ÿง Linux Command Line Basics: A Comprehensive Guide to Essential Commands, File Operations, and System Navigation
ibeh Joseph
ibeh Joseph

Posted on

๐Ÿง Linux Command Line Basics: A Comprehensive Guide to Essential Commands, File Operations, and System Navigation

Introduction
Welcome to the world of Linux command line! ๐ŸŒ In this guide, youโ€™ll learn essential Linux commands, file operations, and how to navigate the Linux system using the terminal. Whether you're new to Linux or just brushing up, this guide has you covered.

Remember, if you ever need more detailed information on a command, you can use man to access its manual page (for example, man ls for the ls command). Letโ€™s get started! ๐Ÿš€

  1. Navigating the File System ๐Ÿ—‚๏ธ

The first step in mastering the Linux command line is learning to navigate the file system.

  • pwd: Prints the current working directory.

    • Example: Run pwd in any directory. Output might be /home/username/Documents.
  • ls: Lists the contents of a directory.

    • Example: ls -l /home/username displays detailed contents of the username directory.
    • Extra: ls -a shows hidden files starting with ..
  • cd <directory>: Changes the current directory.

    • Example: cd /home/username/Documents takes you to the Documents directory.
    • Tip: cd .. moves up one directory level.
  1. Managing Files and Directories ๐Ÿ“

Get hands-on with creating, moving, and deleting files and directories.

  • touch <filename>: Creates a new empty file.

    • Example: touch notes.txt creates an empty file named notes.txt in the current directory.
  • mkdir <directory>: Creates a new directory.

    • Example: mkdir Projects creates a new directory called Projects.
  • cp <source> <destination>: Copies files or directories.

    • Example: cp notes.txt Projects/ copies notes.txt into the Projects folder.
    • Extra: cp -r Documents/ Archives/ copies the entire Documents directory to Archives.
  • mv <source> <destination>: Moves or renames files or directories.

    • Example: mv notes.txt ideas.txt renames notes.txt to ideas.txt.
  • rm <filename>: Deletes files.

    • Example: rm ideas.txt removes ideas.txt.
    • Extra: rm -r OldProjects deletes the OldProjects directory.
  1. Viewing and Editing Files ๐Ÿ“„

Quickly view or edit file contents directly in the terminal.

  • cat <filename>: Displays the content of a file.

    • Example: cat notes.txt shows the contents of notes.txt.
  • nano <filename>: Opens a file in the Nano text editor.

    • Example: nano ideas.txt opens ideas.txt for editing.
  • less <filename>: Views a file page-by-page without editing.

    • Example: less bigfile.txt lets you scroll through bigfile.txt one page at a time.
  1. System Information and Management ๐Ÿ–ฅ๏ธ

Check system information, view processes, and manage users.

  • uname -a: Displays system information.

    • Example: uname -a might output details like Linux mypc 5.4.0-42-generic ....
  • top: Shows a list of running processes, updated in real time.

    • Example: Run top to monitor CPU and memory usage. Press q to quit.
  • ps aux: Displays a snapshot of currently running processes.

    • Example: ps aux | grep firefox shows if firefox is running.
  • whoami: Prints the current username.

    • Example: Run whoami, and you might see username.
  1. Managing Permissions ๐Ÿ”

Set secure access by managing file permissions.

  • chmod <permissions> <filename>: Changes the permissions of a file.

    • Example: chmod 755 script.sh gives read, write, and execute permissions to the user.
  • chown <user>:<group> <filename>: Changes the ownership of a file.

    • Example: chown newuser:staff document.txt changes the owner to newuser and group to staff.
  1. Finding Files and Directories ๐Ÿ”

Quickly locate files or directories on Linux.

  • find <directory> -name <filename>: Searches for a file by name in a specified directory.

    • Example: find /home -name notes.txt searches for notes.txt in /home.
  • grep <text> <filename>: Searches for specific text within a file.

    • Example: grep "error" /var/log/syslog finds lines with "error" in the system log.
  1. Working with Package Managers ๐Ÿ“ฆ

Easily install, update, or remove software packages.

  • Debian/Ubuntu: sudo apt update and sudo apt install <package-name>

    • Example: sudo apt install vim installs the Vim editor.
  • Fedora/CentOS: sudo dnf install <package-name>

    • Example: sudo dnf install nano installs the Nano editor.
  • Arch Linux: sudo pacman -S <package-name>

    • Example: sudo pacman -S git installs Git on Arch.
  1. Basic Network Commands ๐ŸŒ

Test network connections and configure network settings.

  • ping <hostname/IP>: Tests network connectivity.

    • Example: ping google.com checks if Googleโ€™s server is reachable.
  • ifconfig (or ip a): Displays network interface configurations.

    • Example: Run ifconfig to view IP addresses and network details for each interface.
  • netstat: Shows network statistics and active connections.

    • Example: netstat -an displays all open ports and connections.
  • curl <URL>: Transfers data from or to a server.

    • Example: curl http://example.com fetches data from example.com.

Conclusion ๐ŸŽ‰

Mastering these Linux commands will set a strong foundation for your journey into the Linux world. Keep practicing, try out new commands, and remember that the terminal is your friend! If youโ€™d like to dive deeper into more advanced Linux skills, keep exploring and experimenting. Happy coding! ๐Ÿง

Image description

Top comments (0)