DEV Community

Cover image for Mastering the Shell: Essential Commands and their Uses
Christiana
Christiana

Posted on

Mastering the Shell: Essential Commands and their Uses

Introduction

Hey there, fellow devs! If you're working with Linux or macOS, mastering shell commands is a must. Here's a list of essential shell commands and their uses to get you started:

Navigation

  • pwd: Print working directory. Shows the current directory you're in.
  • cd: Change directory. Navigate to a different directory.
  • cd ~: Takes you to your home directory.
  • cd ..: Takes you to the parent directory.

File Management

  • ls: List files and directories. Use -l for detailed information and -a for hidden files.
  • ls -ltr: list out all the directories/ files/folders in your VM
  • mkdir: Make a new directory.
  • rm: Remove files or directories. Use -r for recursive deletion.
  • cp: Copy files or directories.
  • mv: Move or rename files and directories.

File Editing

  • vi: Open a file in the Vim editor.
  • cat: Display the contents of a file.

System Information

  • free: Display memory and disk usage information. Use - g for gigabytes.
  • df: Display disk usage information.
  • top: Display system resource usage information.
  • nproc: Display the number of processing units available.

Miscellaneous

  • echo: Output text to the screen.
  • touch: Create a new empty file.
  • chmod: Change file permissions. -chmod 777: Grant permission to a file for every users. E.g chmod 777 then the name of the file, then do ./ or sh the name of the file
  • chmod 444: Grant access to you, your group, and everyone to read
  • chmod 222: granting access for you, your group and everyone to write the file
  • chmod 111: granting access to you, your group and everyone to execute the file

Tips and Tricks

  • Use man command to display manual pages for a specific command.
  • Use ./ to execute a script or program in the current directory.

Hope this helps...

Top comments (0)