Hands-On with Linux Commands

Hands-On with Linux Commands

Let’s Get Our Hands Dirty!

Alright, folks, it’s time to roll up our sleeves and dive into the Linux terminal—the ultimate playground for tech enthusiasts. Imagine this: a blinking cursor, an empty canvas, and you—the artist. Every command is a stroke of genius, turning chaos into order. Today, we’re starting small but aiming big. From navigating directories to managing files like pros, we’re about to transform a plain black screen into a command-line masterpiece. Are you ready? Let’s make magic happen!


File and Directory Management :

  • Check present location:

    • pwd It shows the present location. Which is the /home/raga of my system.

  • List files and directories:

    • ls

  • List files sorted by time modification:

    • ls -ltr

  • Create a directory:

    • mkdir DevOps Let’s create a Directory of DevOps.

  • Change to the directory:

    • cd DevOps Let’s change our directory to DevOps.

  • Create or update a file:

    • touch example_1.txt Let’s create a file example_1.txt.

  • Display the entire content of a file:

    • cat example_1.txt to check any content present in example_1.txt. It’s empty and we don’t have anything inside the file.

  • Print on the display:

    • echo "Welcome to Raj's Blog on Linux commands" Let’s print “Welcome to Raj’s Blog on Linux commands”.

  • Create example_2.txt and add the “Welcome to Raj’s Blog on Linux commands” inside the file and display it:

    • echo "Welcome to Raj's Blog on Linux commands" > example_2.txt

  • Create a file myfile.txt and enter content interactively:

    • cat > myfile.txt

  • Change to the previous directory:

    • cd .. With this command, we can move outside from the DevOps directory to the previous raga directory.

  • Rename or Move file1 to file2 :

    • mv myfile.txt myblog.txt Let’s rename the myfile.txt to myblog.txt.

  • Copy file1 to file2:

    • cp myblogtxt devblogs/ With this command, we can copy myblog.txt inside devblogs directory.

  • Delete a file:

    • rm myblog.txt With this command, we can delete the file myblog.txt.

  • Delete a directory:

    • rmdir devbolgs/ With this command, we can delete the directory devblogs.

  • File or directory information:

    • du -h Disk usage of files and directories in human-readable format.

    • df -h Display disk space in human-readable format.

    • stat example_2.txt Display detailed file and directory status in human-readable format.


User Management :

  • Root user permission:

    • sudo allows permission for a user to execute a command as a superuser.
  • Switch user:

    • su is used to switch to another user account to execute commands as a root user.
  • Display the currently logged-in user:

    • whoami With this command, we can see the current user is raga.

  • Create a new user:

    • sudo useradd -m raj With this command, we can add a user raj. Which is located in the /home.

  • Change user password:

    • sudo passwd raj With this command, we can add a password to the user raj.

  • Switch user account:

    • su raj With this command, we can switch to the user raj.

  • Exit user account:

    • exit With this command, we can exit from the user raj and switch to the /home directory.

  • Delete user account:

    • sudo userdel raj With this command, we can delete the user raj.

  • Create a group:

    • sudo groupadd dc_comic With this command,d we can create a group called dc_comics.

  • Check the created group list:

    • cat /etc/group With this command, we can check the lists of groups.

  • Add user to the group:

    • sudo gpasswd -a superman dc_comics With this command, we can add a user superman to the dc_comics group.

  • Add multiple users to a group:

    • sudo gpasswd -M superman marvel With this command, we can add multiple users to a group.

  • Modify user accounts:

    • cat /etc/group With this command, we can check the lists of groups.

  • Delete a group:

    • sudo groupdel dc_comics With this command, we can delete the group dc_comics.

  • Modify user accounts:

    • cat /etc/group And the group is deleted.


System Information and Process Management :

  • Display the currently logged-in user:

    • uname allows permission for a user to execute a command as a superuser.

  • Show system uptime:

    • uptime outputs how long the system has been up.

  • Display memory usage:

    • free -h shows memory in human-readable form.

  • Show active processes:

    • ps aux shows all processes.

  • Monitor system processes in real-time:

    • top live view of processes.

  • Enhanced process viewer:

    • htop interactive process viewer.
  • Terminate a process by ID:

    • kill 1234 Ends process with ’PID 1234’.
  • Terminate a process by Name:

    • killall chrome kills all ‘chrome’ processes.

Hurray! Cheers to us for turning that plain black terminal into a canvas of meaningful work! We’ve rolled up our sleeves, typed our way through some cool commands, and made some serious progress. Sure, we didn’t cover every single command out there—Linux is like an ocean, and we’ve just dipped our toes in. But the ones we tackled? Absolute essentials for your day-to-day DevOps tasks.

Feeling curious? Go ahead and explore more commands—be the adventurer of your Linux terminal! And trust me, this was just the beginning. We’ve learned a ton, had some fun, and guess what’s next? In our upcoming blog, we’re diving into the magical world of the Linux Filesystem. 🗂️

So, keep practicing these commands until they’re second nature—you’ll need them as we continue our DevOps Voyage.

Until next time, keep coding, automating, and advancing in DevOps! 😁

Peace out ✌️