# Simple Guide for Beginners to Use Linux Command Line

**Linux Directory :**

1. root : Main root user home
    
2. bin (Binaries) : Contain essential system binaries required for basic system operation.
    
    Ex . ls, cp, mv, cat, echo, sudo.
    
3. sbin (system binaries) : Stores essential binaries for system Administration.
    
    Ex . fdisk, ifconfig, reboot, shutdown.
    
4. etc (configuration file) : Contain system wide configuration files and scripts.
    
    Ex . /etc/passwd (user account)
    
    /etc/fstab (disk mount points)
    
5. var (variable data) : Stores log files, database and dynamically changing data.
    
    Ex . /var/log (system logs)
    
    /var/www (web server files)
    
6. usr ( user system resource) : Contains user installed programs, libraries and documation.
    
    Ex. /usr/bin/ (Non-essential user binaries)
    
    /usr/sbin/ (Non-essential system binaries)
    
7. home (user home directories) : Each user has a separate home directory.
    
    /home/username
    
8. opt (optional software) : Used for installing third party software manually.
    
    Ex . /opt/google/ (for google chrome)
    
9. dev (device file) : Contains device files.
    
    Ex . /dev/sda (for hard drives)
    
10. proc (process information) : A virtual filesystem that provide process and system information.
    
11. sys (Kernel and hardware info) : Contains system related information, similar to /proc.
    
12. media (removable media mount points) : Auto-mount location for USB drivers CDs, etc.
    
13. boot (boot loader files) : Stores boot-related files, including the Linux kernel and GRUB.
    
14. lib (libraries) : Shared libraries required by /bin and /sbin binaries.
    
15. tmp (temporary files) : Stores temporary files, usually deleted on reboot.
    
16. run (runtime data) : Stores runtime data
    
    EX . process IDs, sockets
    

$ : for Normal User

\# : For Root User

Easy Linux Command Guide for New Users :

The most frequently used command in Linux to List directories

```plaintext
ls
```

Linux command to navigate through directories

```plaintext
cd (directory name)
```

Linux command for close the current directory

```plaintext
cd ..
```

Command used to create directories in Linux

```plaintext
mkdir (directory name)
```

Move or rename files in Linux

```plaintext
mv (file name) (give path)
```

Similar usage as mv but for copying files in Linux

```plaintext
cp (file name) (give path)
```

Delete files or directories

```plaintext
rm (files or directories)
```

Create blank/empty files

```plaintext
touch (files name)
```

Clear the terminal display

```plaintext
clear
```

Display file content on the terminal

```plaintext
cat > (file name)
```

Print any text that follows the command

```plaintext
echo "Write a text"
```

Linux command to display paged outputs in the terminal

```plaintext
cat /(file name)|less
```

Access manual pages for all Linux commands

```plaintext
man (command name)
```

For long listing

```plaintext
ls -l
```

For remove empty directory

```plaintext
rmdir (directory name)
```

How to delete folder directory is not empty

```plaintext
rm -rf (directory name)
```

Remove all directory

```plaintext
rmdir*
```

Display the user logged in to the system

```plaintext
who
```

Display the name currently logged user

```plaintext
whoami
```

Currently running processes

```plaintext
ps
```

How to terminate processes manually

```plaintext
kill (processes id)
```

To check process id

```plaintext
top
```

Create symbolic links (shortcuts) to other files.

```plaintext
ln
```

To create a link to another file

types : **soft** and **hard link**

**Hard link** : Is a mirror copy of an original file with the exact same contents. if you edit the contents of the original file, those change will be reflected in the hard link. If you delete the original file though, the hard link will still work and you can view and edit it as you would a normal copy of the original file.

How to create **Hard link** :

```plaintext
ln (file name) (hard link name for save)
```

**Soft link** : It points to the path of another file. If the original file is deleted, the soft link become broken.

How to create a Soft link :

```plaintext
ln -s (file name) (soft link name for save)
```

To display a file’s contents page by page

```plaintext
cat (give path)|less
ESC:q   (for exit)
```

`Spacebar for see data page by page`

`enter key for see data line by line`

To see information about the system kernel

```plaintext
uname 
uname -a
```

File zip and unzip command :

```plaintext
zip (file name)
unzip (file name)
```

Service command : is used to manage system services.

```plaintext
systemctl status (service name)     for the check the status
systemctl start (service name)      for start the service
systemctl stop (service name)       for stop the service
systemctl restart (service name)    for restart the service 
systemctl enable (service name)     for enable the service
```

Head and Tail command

```plaintext
head (file name)         for see first top ten line 
tail (file name)         for see bottom ten line
```

Sort command : Can be used to sort lines in ascending or descending order

```plaintext
sort (file name)
```

Grep command : Is a powerful and versatile text search tool in Linux and unix based operating system.

```plaintext
(any command with output) > |grep " text"
```

Tar command : In Linux is used to create and extract archived files. We can extract multiple different archive file.

```plaintext
tar -cvf  (archive name).tar  filename 
tar -xvf filename
```

Export command : The export command in Linux and unix based operating system is used to set environment variable.

```plaintext
 export (variable name) = value
```

How to install service ?

For Ubuntu

```plaintext
sudo apt-get update -y  or sudoapt-get install (service name)
```

For CentOS

```plaintext
sudo yum install yum -y or Sudo yum update -y or sudo yum install (service name) -y
```

How to add new hard Disk ?

* First add a new hard disk.(physically)
    
* First switch off the machine.
    
* Go and select Hard disk. Select Add. select Next. Select SCSI. Select Next.
    
* Create a new virtual disk Select Next.
    
* Store Virtual disk as a single file.
    
* Select Disk size Select Next.
    
* Start the machine.
    
    After that , Go to terminal. Super login user.
    
    ```plaintext
    fdisk -l
    ```
    
    You will see
    
    ```plaintext
     Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    ```
    
    Partition the Disk
    
    ```plaintext
    sudo fdisk /dev/sdb
    ```
    
    * Press `n` → New partition
        
    * Press `p` → Primary
        
    * Press `1` → Partition number
        
    * Press `Enter` to accept default values
        
    * Press `w` to save changes
        

Format the Partition

```plaintext
sudo mkfs.ext4 /dev/sdb1
```

Create a Mount Point

```plaintext
sudo mkdir /mnt/newdisk      (create a newfolder)
sudo mount /dev/sdb1 /mnt/newdisk    (to mount folder)
```

conclusion :

In conclusion, understanding and utilizing the Linux command line is an essential skill for beginners and experienced users alike. This guide provides a foundational overview of the Linux directory structure and essential commands, enabling users to navigate, manage files, and perform system administration tasks effectively. By mastering these basics, users can enhance their productivity and gain greater control over their Linux systems. As you continue to explore and practice, you'll discover the full potential and flexibility that Linux offers, empowering you to tackle more complex tasks and customize your computing environment to suit your needs.
