DEV Community

Harsh Pandhe
Harsh Pandhe

Posted on

21 1

Day 02: Basic Linux Commands

Welcome to Day 2 of our Linux series! Yesterday, we dipped our toes into the Linux world. Today, we’re getting hands-on and learning some essential commands. Think of this as learning the language of Linux—simple, powerful, and oddly satisfying.

Linux


What Is the Terminal?

Imagine the terminal as a magic window where you can tell Linux what to do. It’s a bit like texting, but instead of a friend, you’re chatting with your computer. Cool, right?

To open the terminal:

  • Ubuntu: Press Ctrl + Alt + T.
  • Fedora: Search for “Terminal” in the app menu.

Now, let’s dive into some commands that will make you feel like a tech wizard.


Basic Navigation Commands

These commands help you move around the Linux filesystem. Think of it as learning to walk before you run.

1. Where Am I?

pwd
Enter fullscreen mode Exit fullscreen mode

pwd

  • Prints the current directory (your location in the filesystem).
  • Example: "/home/username"

2. What’s Around Me?

ls
Enter fullscreen mode Exit fullscreen mode

ls

  • Lists files and directories in your current location.
  • Add -l for detailed info or -a to see hidden files.
  • Example:
  ls -la
Enter fullscreen mode Exit fullscreen mode

3. Take Me Somewhere Else

cd <directory_name>
Enter fullscreen mode Exit fullscreen mode
  • Changes your current directory.
  • Example:
  cd Documents
Enter fullscreen mode Exit fullscreen mode

Go back to the previous directory with:

  cd ..
Enter fullscreen mode Exit fullscreen mode

cd


File Management Commands

4. Show Me the File Content

cat <file_name>
Enter fullscreen mode Exit fullscreen mode
  • Displays the contents of a file.
  • Example:
  cat hello.txt
Enter fullscreen mode Exit fullscreen mode

5. Create a New File

touch <file_name>
Enter fullscreen mode Exit fullscreen mode
  • Creates an empty file.
  • Example:
  touch my_file.txt
Enter fullscreen mode Exit fullscreen mode

6. Move or Rename a File

mv <source> <destination>
Enter fullscreen mode Exit fullscreen mode

mv

  • Moves or renames files.
  • Example (rename):
  mv old_name.txt new_name.txt
Enter fullscreen mode Exit fullscreen mode

Example (move):

  mv my_file.txt /home/username/Documents
Enter fullscreen mode Exit fullscreen mode

7. Copy a File

cp <source> <destination>
Enter fullscreen mode Exit fullscreen mode
  • Copies files or directories.
  • Example:
  cp hello.txt backup_hello.txt
Enter fullscreen mode Exit fullscreen mode

8. Delete a File

rm <file_name>
Enter fullscreen mode Exit fullscreen mode
  • Deletes a file.
  • Example:
  rm old_file.txt
Enter fullscreen mode Exit fullscreen mode
  • Be careful—there’s no trash bin here!

Permissions: The Linux Security Guard

Linux files have permissions that determine who can read, write, or execute them.

9. Check File Permissions

ls -l
Enter fullscreen mode Exit fullscreen mode

ls -l

  • Shows detailed file info, including permissions.
  • Example output:
  -rw-r--r-- 1 user group  123 Jan 1 12:00 hello.txt
Enter fullscreen mode Exit fullscreen mode

Breakdown:

  • r = read, w = write, x = execute.

10. Change Permissions

chmod <permissions> <file_name>
Enter fullscreen mode Exit fullscreen mode
  • Changes file permissions.
  • Example:
  chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

This makes the file executable.

chmod


Other Handy Commands

11. Clear the Screen

clear
Enter fullscreen mode Exit fullscreen mode
  • Wipes the terminal screen clean, just like hitting refresh.

12. Who Am I?

whoami
Enter fullscreen mode Exit fullscreen mode

whoami

  • Prints your username. Great for existential crises.

13. What’s Running?

top
Enter fullscreen mode Exit fullscreen mode
  • Shows active processes and resource usage.
  • Use q to quit.

14. Need Help?

man <command>
Enter fullscreen mode Exit fullscreen mode
  • Opens the manual for a command.
  • Example:
  man ls
Enter fullscreen mode Exit fullscreen mode
  • Pro tip: Quit the manual with q.

Man


Fun Linux Fact

Did you know the Linux mascot, Tux the penguin, was inspired by a penguin bite Linus Torvalds got at a zoo? 🐧

Zoo


Conclusion

You now know how to navigate, manage files, and even wield the power of permissions. Linux isn’t so scary anymore, is it? Practice these commands, and soon, you’ll feel right at home in the terminal.

What’s Coming Next?

Tomorrow, we’ll explore the Linux File System and uncover its unique directory structure. Stay tuned for Day 3 of this series!

Top comments (2)

Collapse
 
madhurima_rawat profile image
Madhurima Rawat

This series is amazing! 🔥 This article was great—I loved the random fun fact, it made me laugh! 😆 I've been thinking about learning Linux for quite some time, and this is a fantastic resource. Keep it up!

Collapse
 
harshpandhe profile image
Harsh Pandhe

Thank you so much! I’m thrilled you’re enjoying the series and found the fun fact amusing! 😄 Learning Linux can be an exciting journey, and I’m glad you see it as a valuable resource. If you have any questions or specific topics you’d like to dive into, just let me know. Your support means a lot, and I’ll keep the content coming! 🔥🤓

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series