Mastering Linux Commands: A Beginner's Guide

Linux, with its powerful command-line interface, provides an array of commands to manage files and directories efficiently. If you're new to Linux or just starting out, mastering some basic commands is essential for navigating the system and performing routine tasks. Let's delve into some fundamental commands along with their options and arguments.

Navigating the File System

1.ls Command : The ls command is used to list files and directories in the current directory.

  • ls: Lists files and directories.

  • ls -l: Lists files and directories in long format, providing detailed information like permissions, owner, size, and modification date.

  • ls -a: Lists all files and directories, including hidden ones.

  • ls *.sh: Lists files with a ".sh" extension.

  • ls -i: Lists files and their inode numbers.

  • ls -d: Lists directories only, not their contents.

Directory Navigation

2.pwd Command : The pwd command stands for "print working directory" and displays the current directory's full path.

3.cd Command: The cd command is used to change directories.

  • cd path_to_directory: Changes the current directory to the specified path.

  • cd ~: Changes the current directory to the user's home directory.

  • cd -: Changes the current directory to the previous directory.

  • cd ..: Moves one directory up in the hierarchy.

  • cd ../..: Moves two directories up in the hierarchy.

Directory Manipulation

4.mkdir Command : The mkdir command is used to create directories.

  • mkdir directoryName: Creates a directory with the specified name.

  • mkdir newFolder: Creates a directory named "newFolder".

  • mkdir -p A/B/C/D: Creates nested directories in a single command (A/B/C/D).

  • mkdir /home/user/Mydirectory: Creates a directory "Mydirectory" in the specified path.

  • mkdir A B C D: Creates multiple directories (A, B, C, D) simultaneously.

mkdir .NewFolder: Creates a hidden directory named "NewFolder".

$ ls
file1.txt file2.txt folder1 folder2

$ ls -l
-rw-r--r-- 1 user user 1024 Apr 21 09:30 file1.txt
-rw-r--r-- 1 user user 2048 Apr 20 12:45 file2.txt
drwxr-xr-x 2 user user 4096 Apr 19 15:10 folder1
drwxr-xr-x 2 user user 4096 Apr 18 10:20 folder2

$ ls -a
. .. file1.txt file2.txt .hiddenFolder

$ ls *.txt
file1.txt file2.txt

$ ls -i
34567 file1.txt 45678 file2.txt 56789 folder1 67890 folder2

$ ls -d */
folder1/ folder2/

$ pwd
/home/user

$ cd folder1

$ pwd
/home/user/folder1

$ cd ..

$ pwd
/home/user

$ mkdir newFolder

$ ls
file1.txt file2.txt folder1 folder2 newFolder

$ mkdir A B C D

$ ls
A B C D file1.txt file2.txt folder1 folder2 newFolder

$ mkdir -p E/F/G/H

$ ls
A B C D E file1.txt file2.txt folder1 folder2 newFolder

$ mkdir .HiddenFolder

$ ls -a
. .. A B C D E file1.txt file2.txt folder1 folder2 newFolder .HiddenFolder

Conclusion

Understanding these basic Linux commands provides a solid foundation for navigating and manipulating files and directories in the Linux environment. With practice, you'll become more comfortable using the command line and be able to perform tasks efficiently. Explore further, experiment, and unlock the full potential of Linux command-line power!

Read more commands.............. Mastering Linux Commands: A Beginner's Guide

0
Subscribe to my newsletter

Read articles from Anil's DevOps Space directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anil's DevOps Space
Anil's DevOps Space