Skip to main content

Basic Linux Commands: A Comprehensive Guide.

Linux System Commands: A Comprehensive Guide

Aim :

Gain knowledge about Linux system commands.

Linux System Commands: A Comprehensive Guide

Understanding and mastering Linux system commands is crucial for effective system administration and development. This guide will walk you through some fundamental Linux commands to enhance your command-line skills.

Guidance on How to Use:

Prerequisite:

Ensure that your system has the necessary permissions to execute commands.

  1. Update the package list using the following command:
    sudo apt update

Explore these fundamental Linux commands to improve your command-line proficiency:

  • User Management

    1. Add a new user :
      sudo useradd -m username

      Creates a new user with the specified username and home directory.

    2. Change password for a specific user:
      sudo passwd username

      Changes the password for the specified user.

    3. Delete a user :
      sudo userdel -r username

      Deletes the specified user and removes the home directory and mail spool.

    4. List all users:
      cat /etc/passwd

      Displays a list of all users on the system.

    5. Change user:
      su username

      Switches to the specified user account.

    6. Change user and open a new shell:
      su - username

      Switches to the specified user and opens a new login shell.

  • File Manipulation

    1. Create an empty file:
      touch new_file.txt

      Creates a new, empty file with the specified name.

    2. Edit a file using the Nano text editor:
      nano file.txt

      Opens the Nano text editor for editing the content of the specified file.

    3. Display the first 10 lines of a file:
      head file.txt

      Shows the first 10 lines of the specified file.

    4. Display the last 10 lines of a file:
      tail file.txt

      Shows the last 10 lines of the specified file.

    5. Compress a file using gzip:
      gzip file.txt

      Compresses the specified file using gzip.

    6. Extract files from a tar archive:
      tar -xvf archive.tar

      Extracts files from a tar archive.

    7. List files with human-readable sizes and sort by size and date:

      ll -h --sort=size,date
  • Directory Manipulation

    1. Create a new directory:
      mkdir new_directory

      Creates a new directory with the specified name.

    2. Remove an empty directory:
      rmdir empty_directory

      Removes an empty directory.

    3. List files in the current directory and subdirectories:
      ls -R

      Lists files and directories recursively.

    4. Copy a directory and its contents:
      cp -r source_directory destination

      Copies the source_directory and its contents to the specified destination.

    5. Move or rename a directory:
      mv old_directory new_directory

      Moves or renames the specified directory.

    6. Show directory size:
      du -sh /path/to/directory
      du -sh *| sort -h

      Displays the size of the specified directory.

  • System Level Commands

    1. Show available memory and swap space:
      free -m

      Displays information about the system's memory and swap space in megabytes.

    2. Display disk space usage by directories:
      du -h --max-depth=1 /

      Shows disk space usage for top-level directories in the root filesystem.

    3. Display system information:
      uname -a

      Shows detailed information about the system.

    4. Display and update sorted information about system processes:
      top

      Displays real-time information about system processes.

    5. Display information about running processes:
      ps aux

      Lists all running processes on the system.

    6. Show disk space usage for each partition:
      df -h

      Displays disk space usage information for each partition.

  • Network Related Commands

    1. Show network interface information:
      ifconfig

      Displays information about all network interfaces on the system.

    2. Display routing table:
      route -n

      Shows the kernel routing table, including destination, gateway, and interface information.

    3. Search for files with a specific name:
      find /path/to/search -name filename.txt

      Searches for files with the specified name in the specified directory and its subdirectories.

      Find the file named "restore_database.sh" in the entire filesystem:

      sudo find / -name restore_database.sh 2>/dev/null
    4. Filter and transform text with awk:
      awk '{print $2}' file.txt

      Prints the second column of a space-separated file.

    5. Replace text in a file using sed:
      sed 's/old_text/new_text/' file.txt

      Replaces occurrences of "old_text" with "new_text" in the file.

Verification:

Verify your Linux distribution information:

lsb_release -a

Written by: A.M.Rinas

Contact: mohomadrinas00@gmail.com

Comments

Popular posts from this blog

MySQL 8.0 Binary Installation: A Step-by-Step Guide

MySQL 8.0 Installation: A Comprehensive Guide Aim : Install MySQL 8.0 using the binary distribution on a Linux system. MySQL 8.0 Installation Steps Step 1: Prepare System and User Create a MySQL group: groupadd mysql Create a MySQL user with restricted shell access: useradd -r -g mysql -s /bin/false mysql Step 2: Download and Extract MySQL Navigate to the installation directory(Not compulsory): cd /usr/local Extract the MySQL tarball: tar xvf /path/to/mysql-VERSION-OS.tar.xz Create a symbolic link: ln -s full-path-to-mysql-VERSION-OS mysql Navigate to the MySQL directory: cd mysql Create a directory for MySQL files: mkdir mysql-files Set ownership and permissio...

Grafana Installation on Ubuntu using Docker

Grafana Installation on Ubuntu using Docker Aim : Install Grafana OSS (open-source version) on Ubuntu using Docker. Grafana Installation Steps Step 1: Pull and Run the Grafana Container Pull and start the Grafana container: sudo docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss -d : Detaches the container and runs it in the background. -p 3000:3000 : Maps port 3000 on your host machine to port 3000 inside the container, enabling access to Grafana's web interface. --name=grafana : Specifies the name of the container as grafana . Step 2: Access Grafana Once the container is running, access Grafana by opening a web browser and navigating to: http://localhost:3000 If Grafana is running on a remote serv...

Apache HTTP Server 2.4.x Installation and Configuration

Apache HTTP Server 2.4.x Installation and Configuration | By A.M.Rinas Aim: Install Apache HTTP Server 2.4.x using the binary distribution and configure it for various purposes. Installation Steps Step 1: Download and Extract Apache HTTP Server Download the Apache HTTP Server 2.4.x binary distribution from the official website. Extract the downloaded tarball: tar xvf httpd-2.4.x.tar.gz Step 2: Configure and Install Apache HTTP Server Navigate to the extracted directory: cd httpd-2.4.x Configure Apache with necessary modules and options: ./configure --enable-proxy --enable-proxy-http --enable-ssl --enable-rewrite Compile and install Apac...