Day 2: Basic Linux Commands - A Beginner's Guide

Saurabh PatilSaurabh Patil
3 min read

Essential Linux commands that every beginner should know. These commands are categorized for better understanding and ease of use.

Listing Commands

1. ls - List Directory Contents

The ls command lists files and directories within the current directory.

$ ls
Desktop  Documents  Downloads  Music  Pictures  Videos

2. ls -l - Long Listing Format

Displays detailed information about files and directories.

$ ls -l
total 0
drwxr-xr-x  2 user  user  64 Jun  1 12:34 Desktop
drwxr-xr-x  2 user  user  64 Jun  1 12:34 Documents

3. ls -a - List All Files Including Hidden Files

Displays all files, including hidden ones.

$ ls -a
.  ..  .bashrc  Desktop  Documents  Downloads

Directory Commands

1. pwd - Print Working Directory

Displays the current directory you are working in.

$ pwd
/home/user

2. cd - Change Directory

Changes the current directory.

$ cd Documents
$ pwd
/home/user/Documents

3. mkdir - MakeDirectory

Creates a new directory.

$ mkdir new_directory
$ ls
Desktop  Documents  Downloads  Music  new_directory  Pictures  Videos

4. rmdir - Remove Empty Directory

Removes an empty directory.

$ rmdir empty_directory
$ ls
Desktop  Documents  Downloads  Music  Pictures  Videos

File Commands

1. touch - Create an Empty File

Creates an empty file or updates the timestamp of an existing file.

$ touch newfile.txt
$ ls
Desktop  Documents  Downloads  Music  newfile.txt  Pictures  Videos

2. rm - Remove Files or Directories

Removes files or directories.

$ rm filename
$ rm -r directory_name  # For removing a directory

3. cp - Copy Files or Directories

Copies files or directories from one location to another.

$ cp source_file destination_file
$ cp -r source_directory destination_directory

4. mv - Move or Rename Files or Directories

Moves or renames files or directories.

$ mv old_name new_name  # For renaming
$ mv file_name /new/location  # For moving

Viewing and Editing Files

1. cat - Concatenate and Display Files

Displays the contents of a file.

$ cat filename.txt
This is the content of the file.

2. echo - Display a Line of Text

Prints text to the terminal.

$ echo "Hello, World!"
Hello, World!

3. nano - Text Editor

A simple text editor.

$ nano filename.txt

4. vim - Text Editor

A powerful text editor.

$ vim filename.txt

System Information

1. uname - Print System Information

Displays system information.

$ uname -a
Linux user-PC 5.4.0-74-generic #83-Ubuntu SMP Tue Jun 1 09:27:20 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

2. df - Disk Space Usage

Displays disk space usage.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           395M  1.2M  394M   1% /run

3. top - Display Linux Tasks

Displays real-time system information, including tasks.

$ top

4. ps - Report a Snapshot of Current Processes

Displays currently running processes.

$ ps aux

Conclusion

These basic commands are fundamental to working in Linux. Mastering them will give you a solid foundation to build upon as you dive deeper into the world of DevOps. Stay tuned for more updates as I continue my 90-day challenge!

0
Subscribe to my newsletter

Read articles from Saurabh Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Saurabh Patil
Saurabh Patil