CentOS Archives - TEKSpace Blog https://blog.tekspace.io/tag/centos/ Tech tutorials for Linux, Kubernetes, PowerShell, and Azure Tue, 26 Sep 2023 14:59:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://blog.tekspace.io/wp-content/uploads/2023/09/cropped-Tekspace-logo-icon-32x32.png CentOS Archives - TEKSpace Blog https://blog.tekspace.io/tag/centos/ 32 32 Configure PHP-FPM for Multiline WordPress Sites With Nginx https://blog.tekspace.io/configure-php-fpm-for-multiline-wordpress-sites-with-nginx/ https://blog.tekspace.io/configure-php-fpm-for-multiline-wordpress-sites-with-nginx/#respond Mon, 25 Sep 2023 20:50:44 +0000 https://blog.tekspace.io/?p=1754 In this tutorial, I am going to show you how you can create a pool to segregate php process for each wordpress website. This totorial is setup using PHP-FPM8.1. This may not work if you are using older version of PHP. Install PHP-FPM Install the latest version of PHP FPM. If there is a new

The post Configure PHP-FPM for Multiline WordPress Sites With Nginx appeared first on TEKSpace Blog.

]]>
In this tutorial, I am going to show you how you can create a pool to segregate php process for each wordpress website. This totorial is setup using PHP-FPM8.1. This may not work if you are using older version of PHP.

Install PHP-FPM

Install the latest version of PHP FPM. If there is a new version, select that version for installation.

sudo apt-get install php8-1-fpm

Check Service Status:

sudo systemctl status php8-1-fpm.service

Output:

rahil@localhost:$ sudo systemctl status php8.1-fpm.service
 php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-09-25 18:28:47 UTC; 23min ago
       Docs: man:php-fpm8.1(8)
    Process: 14322 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.1/fpm/pool.d/www.conf 81 (code=exited, status=0/SUCCESS)
   Main PID: 14319 (php-fpm8.1)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 1013)
     Memory: 11.1M
        CPU: 83ms
     CGroup: /system.slice/php8.1-fpm.service
             ├─14319 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─14320 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             └─14321 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

Sep 25 18:28:47 localhost systemd[1]: Starting The PHP 8.1 FastCGI Process Manager...
Sep 25 18:28:47 localhost systemd[1]: Started The PHP 8.1 FastCGI Process Manager.

Configuring PHP-FPM Pool

Create group for WordPress site:

sudo groupadd wordpress_demo

sudo useradd -g wordpress_demo wordpress_demo

Next, let’s navigate to the PHP-FPM folder path to create a new configuration file:

cd /etc/php/8.1/fpm/pool.d/

Inside this folder create a new configuration file called wordpress_demo_pool.conf

sudo vi wordpress_demo_pool.conf

[wordpress_demo_site]
user = wordpress_demo
group = wordpress_demo
listen = /var/run/php/php8.1-fpm-wordpress-demo-site.sock
listen.owner = www-data
listen.group = www-data
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
; Choose how the process manager will control the number of child processes. 
pm = dynamic 
pm.max_children = 75 
pm.start_servers = 10 
pm.min_spare_servers = 5 
pm.max_spare_servers = 20 
pm.process_idle_timeout = 10s
env[HOSTNAME] = $HOSTNAME
env[TMP] = /tmp

Insert the below command. Definition of each item is provided below:

  • [wordpress_demo_site]: This is a unique identifier for the pool, ensuring no two pools share the same name.
  • user and group: Specifies which user and group the pool operates under.
  • listen: Defines the socket file’s name associated with this pool.
  • listen.owner and listen.group: These should align with the user and group that NGINX operates under. For this scenario, it’s www-data.
  • php_admin_value: Enables the setting of specific PHP configuration parameters.
  • php_admin_flag: Used to define PHP boolean settings.
    pm: Manages processes, with the “Dynamic” value indicating that child process numbers adjust based on subsequent directives.
  • pm.max_children: Indicates the peak number of concurrently active child processes.
  • pm.start_servers: Represents the count of child processes initiated upon startup.
  • pm.min_spare_servers: Denotes the least number of idle child processes. If idle processes drop below this, new ones are spawned.
  • pm.max_spare_servers: Represents the upper limit for idle child processes. If this number is exceeded, some processes will be terminated.
  • pm.process_idle_timeout: Specifies the ideal maximum for idle server processes. This is relevant only when the pm setting is “dynamic”. Beyond these configurations, it’s feasible to relay certain system environment variables to the php-fpm service, like using env[‘PHP_FOO’] = $bar. For instance, integrating the subsequent options in the mentioned configuration will assign the hostname and temporary directory path to the PHP environment.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites with high traffic. One of the key features of PHP-FPM is its ability to manage PHP processes. The process manager (pm) is responsible for controlling the number of child processes, which in turn handle the PHP requests.

Here’s a breakdown of the PHP-FPM process manager for more details:

  1. Types of Process Managers:
    PHP-FPM offers several ways to manage PHP processes:
  • Static (pm = static): A fixed number of child processes are created. The number is specified by the pm.max_children directive. This mode is straightforward and can be efficient if you know the exact number of processes you need. However, it lacks flexibility.
  • Dynamic (pm = dynamic): The number of child processes is set dynamically based on the following directives: pm.max_children, pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers. This mode offers more flexibility and can adjust based on the demand.
  • On-demand (pm = ondemand): Processes are spawned as needed. No child processes are created at startup, but they’re created on demand when there’s a request. This mode is the most flexible and can be efficient for sites with fluctuating traffic.

Benefits:

  • Adaptability: PHP-FPM can adjust the number of child processes based on the traffic, ensuring efficient resource usage.
  • Performance: By managing processes effectively, PHP-FPM can handle a large number of requests without overloading the server.
  • Isolation: Each PHP request can be processed in a separate child process, providing isolation and security.
  • Custom Configuration: PHP-FPM allows for pool-specific configurations, enabling fine-tuned settings for different websites or applications on the same server.

In summary, the PHP-FPM process manager provides a way to efficiently handle PHP requests by managing child processes. Depending on the configuration and the type of process manager chosen, PHP-FPM can offer a balance between performance and flexibility.

Restart fpm service to apply new changes:

sudo systemctl restart php8.1-fpm && sudo systemctl status php8.1-fpm --no-pager

Configure Nginx for PHP-FPM

server {
            listen 80;
            root /var/www/html/wordpress_blog/public_html;
            index index.php index.html;
            server_name blog.wordpress.xyz;

            access_log /var/log/nginx/wordpress_blog.access.log;
            error_log /var/log/nginx/wordpress_blog.error.log;

            location / {
                         try_files $uri $uri/ /index.php?$args;
            }

            location ~ \.php$ {
                         include snippets/fastcgi-php.conf;
                         fastcgi_pass unix:/run/php/php8.1-fpm-wordpress-demo-site.sock;
            }

            location ~ /\.ht {
                         deny all;
            }

            location = /favicon.ico {
                         log_not_found off;
                         access_log off;
            }

            location = /robots.txt {
                         allow all;
                         log_not_found off;
                         access_log off;
           }

            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                         expires max;
                         log_not_found off;
           }
}

Next, test Nginx configuration.

sudo nginx -t

Restart Nginx Service:

sudo systemctl restart nginx

Testing PHP-FPM Nginx Configuration

To verify that the aforementioned NGINX configuration file is utilizing the newly established FPM pool, generate a PHP info file within the web root. In the above NGINX configuration file, I have designated /var/www/html/wordpress_blog/public_html as the web root. Modify this value to suit your setup.

echo "<?php echo phpinfo();?>" > info.php

Setting Permissions For WordPress

How we have set up PHP-FPM, it is crucial to set permissions to public_html folder. Execute the below commands:

sudo chmod -R 755 *
sudo chmod -R 664 *.php *.txt *.html
sudo chown -R wordpress_demo:www-data *

The post Configure PHP-FPM for Multiline WordPress Sites With Nginx appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/configure-php-fpm-for-multiline-wordpress-sites-with-nginx/feed/ 0
How To Use Standard Redirection to Input or Output Commands https://blog.tekspace.io/how-to-use-standard-redirection-to-input-or-output-commands/ https://blog.tekspace.io/how-to-use-standard-redirection-to-input-or-output-commands/#respond Mon, 25 Sep 2023 16:44:07 +0000 https://blog.tekspace.io/?p=1747 In Linux and other Unix-like systems, you can use standard redirection to control the input and output of commands. Here’s a brief overview of how to use these redirections: The output of command1 is used as the input to command2. This will use inputfile as the input to command. This discards both standard output and

The post How To Use Standard Redirection to Input or Output Commands appeared first on TEKSpace Blog.

]]>
In Linux and other Unix-like systems, you can use standard redirection to control the input and output of commands. Here’s a brief overview of how to use these redirections:

  1. Standard Output (stdout) Redirection: The standard output (usually the terminal) can be redirected to a file. This means that instead of seeing the output on your screen, it’ll be saved to a file.
  • Overwrite a file: command > filename This will overwrite the filename with the output of the command.
  • Append to a file:
    bash command >> filename
    This will append the output of command to filename without overwriting its current content.
  1. Standard Error (stderr) Redirection: Sometimes commands generate errors, and these errors are sent to stderr.
  • Overwrite a file: command 2> errorfile This will overwrite errorfile with the error messages from command.
  • Append to a file:
    bash command 2>> errorfile
    This will append the error messages from command to errorfile.
  1. Redirect Both stdout and stderr: If you want to redirect both standard output and standard error to the same file:
  • Overwrite a file: command > filename 2>&1
  • Append to a file: command >> filename 2>&1 The 2>&1 syntax tells the shell to redirect the standard error (file descriptor 2) to the same location as the standard output (file descriptor 1).
  1. Pipes (|): The pipe operator allows you to use the output of one command as the input of another. This is very useful for chaining commands together.
   command1 | command2

The output of command1 is used as the input to command2.

  1. Input Redirection: You can also redirect the input of a command:
   command < inputfile

This will use inputfile as the input to command.

  1. Discarding Output: If you want to discard the output (or errors) of a command, you can redirect it to the special file /dev/null:
   command > /dev/null 2>&1

This discards both standard output and standard error.

NOTE: the order of redirections matters. For example, command > filename 2>&1 is not the same as command 2>&1 > filename. The first command redirects both the standard output (stdout) and standard error (stderr) to a file named “filename”. The second command redirects the standard output to the “filename” file, while keeping the standard error in its original location, typically the terminal.

The post How To Use Standard Redirection to Input or Output Commands appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-use-standard-redirection-to-input-or-output-commands/feed/ 0
How to Setup CronJob On A Linux Server https://blog.tekspace.io/how-to-setup-cronjob-on-a-linux-server/ https://blog.tekspace.io/how-to-setup-cronjob-on-a-linux-server/#respond Mon, 25 Sep 2023 15:34:00 +0000 https://blog.tekspace.io/?p=1745 Setting up a cron job on Linux involves using the crontab command. Below is a step-by-step guide on how to set up a cron job: The five asterisks represent: Make sure that the script or command you schedule with cron has the right permissions to run. Also, use absolute paths for any paths inside the

The post How to Setup CronJob On A Linux Server appeared first on TEKSpace Blog.

]]>
Setting up a cron job on Linux involves using the crontab command. Below is a step-by-step guide on how to set up a cron job:

  1. Open the Crontab Editor:
    To edit the current user’s crontab, use the following command:
   crontab -e
  1. Understand the Cron Time Format:
    Each cron job has a specific format:
   * * * * * /path/to/command

The five asterisks represent:

  • Minute (0 – 59)
  • Hour (0 – 23)
  • Day of the month (1 – 31)
  • Month (1 – 12)
  • Day of the week (0 – 7, where both 0 and 7 represent Sunday)
  1. Add Your Cron Job:
    For example, if you want to run /path/to/script.sh every day at 3:30 AM, you would add the following line to the crontab:
   30 3 * * * /path/to/script.sh
  1. Save and Exit:
    After adding your cron job, save and exit the editor. The method to save and exit depends on the default editor set on your system:
  • For vi/vim: Press Esc, type :wq, and press Enter.
  • For nano: Press CTRL + O, press Enter, and then press CTRL + X.
  1. View Current Cron Jobs:
    To view the current user’s cron jobs, use:
   crontab -l
  1. Remove a Cron Job:
    If you want to remove a cron job, edit the crontab (crontab -e) and simply delete the line containing the job you want to remove. Then save and exit.
  2. Manage Other User’s Cron Jobs:
    If you have superuser privileges, you can view or edit the crontab of another user with:
   crontab -u username -l   # To view
   crontab -u username -e   # To edit
  1. Cron Job Output:
    By default, the output of the cron job will be mailed to the user the job runs as. If you want to redirect the output to a file or discard it, you can use standard redirection:
   30 3 * * * /path/to/script.sh > /path/to/logfile.log 2>&1
  1. Ensure the Cron Daemon is Running:
    The cron jobs rely on the cron daemon to be running. You can check its status (on systems using systemd) with:
   systemctl status cron
  1. Set Environment Variables:
    If your script relies on specific environment variables, you can set them at the top of the crontab file. For example:
   PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
   30 3 * * * /path/to/script.sh

Make sure that the script or command you schedule with cron has the right permissions to run. Also, use absolute paths for any paths inside the script, since cron jobs have a limited environment.

Using Standard Redirection to output cron job

Let’s explore some examples of using redirection with cron jobs. This will help you understand how to handle the output and errors generated by cron tasks.

  1. Redirecting Standard Output to a File:
    If you have a cron job that generates output and you want to save that output to a file:
   0 0 * * * /path/to/script.sh > /path/to/output.log

This will run script.sh every day at midnight and save its output to output.log.

  1. Redirecting Errors to a Separate File:
    If you want to save error messages to a separate file:
   0 0 * * * /path/to/script.sh > /path/to/output.log 2> /path/to/error.log

This will save standard output to output.log and errors to error.log.

  1. Appending Output and Errors to Existing Files:
    If you don’t want to overwrite the log files but instead want to append to them:
   0 0 * * * /path/to/script.sh >> /path/to/output.log 2>> /path/to/error.log
  1. Combining Output and Errors in a Single File:
    If you want both the standard output and errors in the same file:
   0 0 * * * /path/to/script.sh > /path/to/output_and_error.log 2>&1
  1. Discarding Output and Errors:
    If you’re not interested in the output or errors of a cron job:
   0 0 * * * /path/to/script.sh > /dev/null 2>&1
  1. Sending Output and Errors via Email:
    By default, cron will email the user with the output and errors of a job. If you want to explicitly set an email address to receive these messages, you can use the MAILTO variable:
   MAILTO="your_email@example.com"
   0 0 * * * /path/to/script.sh
  1. Using Pipes with Cron Jobs:
    Let’s say you want to filter the output of a script and save only lines containing the word “ERROR” to a log file:
   0 0 * * * /path/to/script.sh | grep ERROR > /path/to/error.log
  1. Running Multiple Commands:
    If you want to run multiple commands in a single cron job and redirect their output:
   0 0 * * * /path/to/first_script.sh && /path/to/second_script.sh > /path/to/output.log

NOTE: when working with cron jobs, always use absolute paths for commands, scripts, and files to avoid any ambiguity. Also, test your scripts manually before scheduling them with cron to ensure they work as expected.

How to Check CronJob Logs

Execute the below command to get all the execution logs from CronJobs.

sudo grep CRON /var/log/syslog

The post How to Setup CronJob On A Linux Server appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-setup-cronjob-on-a-linux-server/feed/ 0
How To Copy Permissions From One File to Another On Linux https://blog.tekspace.io/how-to-copy-permissions-from-one-file-to-another-on-linux/ https://blog.tekspace.io/how-to-copy-permissions-from-one-file-to-another-on-linux/#respond Mon, 25 Sep 2023 14:37:14 +0000 https://blog.tekspace.io/?p=1743 To copy permissions from one file to another in Linux, you can use the chmod command in combination with the stat command. Here’s how you can do it: Step 1: Using stat and chmod: First, get the permissions of the source file using stat: This will return the permissions of source_file in octal format. Then,

The post How To Copy Permissions From One File to Another On Linux appeared first on TEKSpace Blog.

]]>
To copy permissions from one file to another in Linux, you can use the chmod command in combination with the stat command. Here’s how you can do it:

Step 1: Using stat and chmod: First, get the permissions of the source file using stat:

stat -c "%a" source_file

    This will return the permissions of source_file in octal format.

    Then, apply these permissions to the target file using chmod:

    chmod $(stat -c "%a" source_file) target_file

    Using a one-liner: You can combine the above commands into a single one-liner:

    chmod --reference=source_file target_file

    The --reference option allows chmod to take the permissions from the file specified (in this case, source_file) and apply them to target_file.

    Remember to replace source_file with the name of the file from which you want to copy the permissions, and target_file with the name of the file to which you want to apply the permissions.

    The post How To Copy Permissions From One File to Another On Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/how-to-copy-permissions-from-one-file-to-another-on-linux/feed/ 0
    Essential Linux Commands Cheat Sheet: Your Ultimate Reference https://blog.tekspace.io/essential-linux-commands-cheat-sheet-your-ultimate-reference/ https://blog.tekspace.io/essential-linux-commands-cheat-sheet-your-ultimate-reference/#respond Mon, 28 Aug 2023 18:06:50 +0000 https://blog.tekspace.io/?p=1372 In the intricate landscape of Linux systems, a firm grasp of essential commands is a cornerstone for Linux administrators and engineers. The Linux command line serves as an indispensable tool, offering professionals the means to expertly navigate, administer, and manipulate their systems. These vital Linux commands stand as the bedrock for those seeking to harness

    The post Essential Linux Commands Cheat Sheet: Your Ultimate Reference appeared first on TEKSpace Blog.

    ]]>
    In the intricate landscape of Linux systems, a firm grasp of essential commands is a cornerstone for Linux administrators and engineers. The Linux command line serves as an indispensable tool, offering professionals the means to expertly navigate, administer, and manipulate their systems. These vital Linux commands stand as the bedrock for those seeking to harness the capabilities of this command line interface. Regardless of your proficiency level, whether you’re a seasoned pro or a newcomer, delving into and utilizing these commands will undoubtedly propel your skillset to greater heights.

    NumberCommandDescriptionExample
    1lsLists files and directories in the current location.ls -l
    2cdChanges the current working directory.cd /path/to/directory
    3pwdDisplays the current working directory path.pwd
    4mkdirCreates a new directory.mkdir newfolder
    5touchCreates an empty file or updates the timestamp.touch file.txt
    6cpCopies files or directories.cp file.txt destination/
    7mvMoves or renames files and directories.mv file.txt newname.txt
    8rmRemoves (deletes) files and directories.rm file.txt
    9catDisplays the content of a file.cat file.txt
    10grepSearches for a specific pattern in a text.grep "pattern" file.txt
    11nanoA simple terminal-based text editor.nano file.txt
    12vimA powerful terminal-based text editor.vim file.txt
    13chmodChanges file permissions.chmod 755 file.sh
    14chownChanges file ownership.chown user:group file.txt
    15psDisplays currently running processes.ps aux
    16topDisplays real-time system information.top
    17killTerminates processes using their IDs.kill -9 process_id
    18dfDisplays disk space usage.df -h
    19duShows the disk usage of files and directories.du -sh folder/
    20findSearches for files and directories.find /path/to/search -name "*.txt"
    21wgetDownloads files from the internet.wget URL
    22curlTransfers data with URLs.curl -O URL
    23tarArchives files and directories.tar -czvf archive.tar.gz folder/
    24gzipCompresses files.gzip file.txt
    25gunzipDecompresses files.gunzip file.txt.gz
    26sshSecurely connects to remote servers.ssh user@host
    27scpSecurely copies files between systems.scp file.txt user@host:/path/
    28pingTests network connectivity.ping google.com
    29ifconfigDisplays and configures network interfaces.ifconfig
    30netstatShows network statistics and connections.netstat -tuln
    31tracerouteTraces the route taken by packets over a network.traceroute google.com
    32historyDisplays the command history.history
    33aliasCreates shortcuts for commands.alias l="ls -l"
    34manDisplays the manual for commands.man ls
    35uptimeShows system uptime.uptime
    36dateDisplays the current date and time.date
    37calDisplays a calendar.cal
    38unameDisplays system information.uname -a
    39whoamiShows the current user.whoami
    40sudoExecutes commands as a superuser.sudo command
    41suSwitches to another user account.su username
    42aptPackage manager for Debian-based systems.apt install package
    43yumPackage manager for RPM-based systems.yum install package
    44tailDisplays the last lines of a file.tail -n 10 file.txt
    45headDisplays the first lines of a file.head -n 5 file.txt
    46echoPrints text to the console.echo "Hello, Linux!"
    47adduserAdds a new user account.adduser newuser
    48passwdChanges user password.passwd username
    49addgroupAdds a new group.addgroup newgroup
    50unzipExtracts files from a ZIP archive.unzip file.zip

    In the realm of Linux administration and engineering, proficiency in essential Linux commands transcends being an added benefit – it’s an imperative. These fundamental tools create the framework for streamlined system management, effective troubleshooting, and optimal performance. By engaging with the Linux command line, you equip yourself with a robust ability to interact deeply with your systems. For Linux administrators and engineers, mastering these crucial commands isn’t merely a suggestion – it’s a pathway to achieving competence and empowerment within the intricate world of Linux. So, seize the opportunity, dive into exploration, and unveil the boundless potential that the Linux command line has in store.

    The post Essential Linux Commands Cheat Sheet: Your Ultimate Reference appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/essential-linux-commands-cheat-sheet-your-ultimate-reference/feed/ 0
    Learn about df command in Linux https://blog.tekspace.io/learn-about-df-command-in-linux/ https://blog.tekspace.io/learn-about-df-command-in-linux/#respond Wed, 16 Aug 2023 19:31:55 +0000 https://blog.tekspace.io/?p=1140 The df command in Linux is used to display information about disk space usage on a file system. It shows how much disk space is used and available on file systems. This helps you see how much storage capacity your system’s devices have and how much is being used. Here’s a detailed explanation of how

    The post Learn about df command in Linux appeared first on TEKSpace Blog.

    ]]>
    The df command in Linux is used to display information about disk space usage on a file system. It shows how much disk space is used and available on file systems. This helps you see how much storage capacity your system’s devices have and how much is being used. Here’s a detailed explanation of how the df command works:

    Syntax:

    df [OPTION]... [FILE]...

    Options:

    • -h, --human-readable: Print sizes in a human-readable format (e.g., KB, MB, GB, etc.).
    • -H, --si: Use powers of 1000 instead of 1024 for human-readable output.
    • -T, --print-type: Print file system type as well.
    • -t, --type=TYPE: Limit listing to file systems of specified types (e.g., ext4, nfs, tmpfs, etc.).
    • -x, --exclude-type=TYPE: Exclude file systems of specified types.
    • --total: Display a total summary at the end.
    • --help: Display help message and exit.
    • --version: Display version information and exit.

    Usage:

    1. Basic Usage:
      Running df without any options or arguments will display disk space information for all mounted file systems in the default format (in 1 KB blocks):
       $ df
       Filesystem     1K-blocks    Used Available Use% Mounted on
       /dev/sda1       102384720 2298164  95296656   3% /
       tmpfs            1024564    3136   1021428   1% /dev/shm
       /dev/sdb1       51767268 2541260  46432892   6% /mnt/data
    1. Human-Readable Output:
      You can use the -h or --human-readable option to display sizes in a more human-readable format:
       $ df -h
       Filesystem      Size  Used Avail Use% Mounted on
       /dev/sda1        98G  2.2G   91G   3% /
       tmpfs           1000M  3.1M  997M   1% /dev/shm
       /dev/sdb1        49G  2.5G   44G   6% /mnt/data
    1. Total Disk Space:
      Adding the --total option will display a summary line at the end with the total disk space usage:
       $ df -h --total
       Filesystem      Size  Used Avail Use% Mounted on
       /dev/sda1        98G  2.2G   91G   3% /
       tmpfs           1000M  3.1M  997M   1% /dev/shm
       /dev/sdb1        49G  2.5G   44G   6% /mnt/data
       Total            148G  4.8G  135G   4%
    1. Limiting Display to Specific File System Types:
      You can use the -t option followed by a comma-separated list of file system types to limit the display to only specific types:
       $ df -h -t ext4
       Filesystem      Size  Used Avail Use% Mounted on
       /dev/sda1        98G  2.2G   91G   3% /
       /dev/sdb1        49G  2.5G   44G   6% /mnt/data
    1. Displaying File System Type:
      Use the -T option to display the file system type along with the other information:
       $ df -h -T
       Filesystem     Type      Size  Used Avail Use% Mounted on
       /dev/sda1      ext4       98G  2.2G   91G   3% /
       tmpfs          tmpfs    1000M  3.1M  997M   1% /dev/shm
       /dev/sdb1      ext4       49G  2.5G   44G   6% /mnt/data
    1. Excluding File System Types:
      The -x option followed by a comma-separated list of file system types allows you to exclude specific types from the display:
       $ df -h -x tmpfs
       Filesystem     Size  Used Avail Use% Mounted on
       /dev/sda1       98G  2.2G   91G   3% /
       /dev/sdb1       49G  2.5G   44G   6% /mnt/data
    1. Displaying Information for Specific Files or Directories:
      You can provide one or more file or directory paths as arguments to the df command to display information about the file system containing those paths:
       $ df -h /home/user /mnt/data
       Filesystem      Size  Used Avail Use% Mounted on
       /dev/sda1        98G  2.2G   91G   3% /
       /dev/sdb1        49G  2.5G   44G   6% /mnt/data

    These are some of the common use cases and options for the df command in Linux. It provides valuable information about disk space usage that can be helpful for system monitoring, capacity planning, and troubleshooting storage-related issues.

    The post Learn about df command in Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/learn-about-df-command-in-linux/feed/ 0
    Learn about tar command in Linux https://blog.tekspace.io/learn-about-tar-command-in-linux/ https://blog.tekspace.io/learn-about-tar-command-in-linux/#respond Wed, 16 Aug 2023 19:27:44 +0000 https://blog.tekspace.io/?p=1137 The tar command in Linux is used to create, view, and manipulate archive files. An archive is a collection of multiple files and directories bundled into a single file, which can be compressed or uncompressed. The name “tar” stands for “tape archive,” as the command was initially developed for creating backups on magnetic tape storage.

    The post Learn about tar command in Linux appeared first on TEKSpace Blog.

    ]]>
    The tar command in Linux is used to create, view, and manipulate archive files. An archive is a collection of multiple files and directories bundled into a single file, which can be compressed or uncompressed. The name “tar” stands for “tape archive,” as the command was initially developed for creating backups on magnetic tape storage. However, it is widely used for various purposes today.

    The basic syntax of the tar command is:

    tar [options] [archive-filename] [file(s) or directory]

    Here, options are various flags that modify the behavior of the tar command, archive-filename is the name of the archive file you want to create or operate on, and [file(s) or directory] is the list of files or directories you want to include in the archive.

    Commonly Used Options:

    1. -c (or –create): Create a new archive.
    2. -x (or –extract): Extract files from an archive.
    3. -v (or –verbose): Verbose mode. Print the names of the files being processed.
    4. -f (or –file): Specifies the filename of the archive to create or operate on.
    5. -z (or –gzip): Compress the archive using gzip.
    6. -j (or –bzip2): Compress the archive using bzip2.
    7. -r (or –append): Append files to an existing archive.
    8. -t (or –list): List the contents of an archive.
    9. -u (or –update): Only append files that are newer than the archive contents.
    10. -p (or –preserve-permissions): Preserve file permissions and ownership when extracting.
    11. -C (or –directory): Change to a specific directory before performing operations.

    Examples:

    1. Create a tar archive of a directory:
    tar -cvf archive.tar directory_name
    1. Create a tar archive and compress it using gzip:
    tar -czvf archive.tar.gz directory_name
    1. Extract files from a tar archive:
    tar -xvf archive.tar
    1. List the contents of a tar archive:
    tar -tvf archive.tar
    1. Append files to an existing tar archive:
    tar -rvf archive.tar new_file

    Note:

    • The sequence of options holds crucial significance. For example, if you’re creating a compressed archive, you should specify the compression option (e.g., -z or -j) before the -f option.
    • When extracting files from a compressed archive, the appropriate compression option (-z or -j) should be used along with the -x option.
    • tar does not provide encryption; it simply bundles files together. For secure storage or transmission, you might need to use additional tools like gpg for encryption.

    Remember that the tar command is quite versatile and can be used in various combinations to suit your needs. Always consult the manual (man tar) for more details and options.

    The post Learn about tar command in Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/learn-about-tar-command-in-linux/feed/ 0
    Learn about gzip command in Linux https://blog.tekspace.io/learn-about-gzip-command-in-linux/ https://blog.tekspace.io/learn-about-gzip-command-in-linux/#respond Wed, 16 Aug 2023 19:22:15 +0000 https://blog.tekspace.io/?p=1134 Certainly! The gzip command in Linux is used to compress and decompress files using the GNU zip (gzip) compression algorithm. It is commonly used to reduce the size of files to save disk space or to prepare files for efficient transfer over networks. The .gz extension is often appended to compressed files. Here’s a detailed

    The post Learn about gzip command in Linux appeared first on TEKSpace Blog.

    ]]>
    Certainly! The gzip command in Linux is used to compress and decompress files using the GNU zip (gzip) compression algorithm. It is commonly used to reduce the size of files to save disk space or to prepare files for efficient transfer over networks. The .gz extension is often appended to compressed files.

    Here’s a detailed explanation of how the gzip command works:

    1. Compression Process:
      When you use the gzip command to compress a file, it follows these steps: a. Deflation:
      The gzip algorithm uses a combination of the Deflate compression algorithm and other techniques to compress the file. Deflate is a lossless compression algorithm that replaces repeated sequences of data with shorter symbols, thus reducing the file size. b. Block Splitting:
      The input file is divided into blocks, typically 32KB in size. Each block is treated independently during the compression process. c. Huffman Coding:
      Huffman coding is used to build variable-length codes for the most common data values. This step helps to further reduce the size of the compressed data. d. Header and Trailer:
      The compressed file begins with a header that contains metadata about the original file, such as the filename and timestamp. The compressed data follows the header, and the file ends with a trailer that includes a checksum for data integrity verification during decompression.
    2. Decompression Process:
      When you use the gzip command to decompress a file, it follows these steps: a. Header Check:
      The decompression process starts by reading and verifying the header of the compressed file. This header contains information about the original file, such as the filename and timestamp. b. Inflation:
      The Deflate algorithm is used to reverse the compression process. It expands the compressed data, replacing the shorter symbols with the original sequences of data. c. Data Integrity Check:
      The trailer of the compressed file contains a checksum value. This checksum is used to verify the integrity of the decompressed data. If the checksum doesn’t match, it indicates data corruption. d. Original File Reconstruction:
      After the compressed data is decompressed, the original file is reconstructed with the same content and format it had before compression.
    3. Using the gzip Command:
      The basic usage of the gzip command is as follows: To compress a file:
    gzip filename

    This command compresses the filename and replaces it with a compressed version named filename.gz.

    To decompress a file:

    gzip -d filename.gz

    or

    gunzip filename.gz

    Both of these commands decompress the filename.gz and create a new file named filename.

    You can also use the -c option to write the compressed or decompressed data to the standard output, allowing you to chain commands together or redirect the output to another file.

    Keep in mind that the gzip command is just one of many compression tools available in Linux. Other tools like bzip2, xz, and zip provide different compression algorithms with varying levels of compression and decompression speed.

    The post Learn about gzip command in Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/learn-about-gzip-command-in-linux/feed/ 0
    Learn about grep command in Linux https://blog.tekspace.io/learn-about-grep-command-in-linux/ https://blog.tekspace.io/learn-about-grep-command-in-linux/#respond Wed, 16 Aug 2023 19:17:56 +0000 https://blog.tekspace.io/?p=1131 The grep command in Linux is a powerful utility used for searching and filtering text in files or input streams. It stands for “Global Regular Expression Print” and is primarily used to search for patterns (regular expressions) within text files. Here’s a detailed explanation of how the grep command works: Basic Syntax: Example Usage:Suppose you

    The post Learn about grep command in Linux appeared first on TEKSpace Blog.

    ]]>
    The grep command in Linux is a powerful utility used for searching and filtering text in files or input streams. It stands for “Global Regular Expression Print” and is primarily used to search for patterns (regular expressions) within text files. Here’s a detailed explanation of how the grep command works:

    Basic Syntax:

    grep [options] pattern [file...]
    • pattern: The regular expression or plain text string that you want to search for.
    • file: Optional argument specifying the name of the file(s) you want to search in. If not provided, grep searches through the standard input (e.g., output of another command or user input).

    Example Usage:
    Suppose you have a file named example.txt with the following content:

    This is an example
    of how grep works.
    It searches for patterns
    in text files.

    You can use the following grep command to search for the pattern “example” in the file:

    grep "example" example.txt

    How grep Works:

    Reading Input:

    • If you provide file names as arguments, grep reads the content of those files line by line.
    • If you didn’t provide file names, grep reads from the standard input (you can type or pipe text directly to it).

    Pattern Matching:

    • grep searches for the specified pattern (regular expression) in each line of the input.
    • Regular expressions (regex) are powerful patterns used to match strings. They can include characters, numbers, special symbols, and metacharacters that allow you to define complex patterns.

    Matching Lines:

    • If a line in the input matches the pattern, grep prints that line to the standard output (usually your terminal).
    • By default, grep prints the entire matching line.

    Options and Flags:

    • grep offers various options and flags to customize its behavior, such as:
      • -i or --ignore-case: Perform a case-insensitive search.
      • -v or --invert-match: Print lines that do not match the pattern.
      • -r or --recursive: Search recursively in directories.
      • -n or --line-number: Print line numbers along with matching lines.
      • And many more…

    Examples:

    1. Case-insensitive search for “example”:
    grep -i "example" example.txt
    1. Invert match: Print lines that do not contain “example”:
    grep -v "example" example.txt
    1. Recursive search in all files under a directory:
    grep -r "pattern" /path/to/directory
    1. Print line numbers along with matching lines:
    grep -n "example" example.txt
    1. Using regular expressions:
    grep "^[A-Za-z]*$" example.txt

    This searches for lines containing only alphabetical characters.

    Note: Regular expressions can be quite complex, and mastering them takes practice. You can find extensive documentation on regular expressions and grep by using the man command:

    man grep
    man regex

    This overview provides a detailed explanation of how the grep command works in Linux. It’s a versatile tool for searching and filtering text, making it an essential part of the Linux command-line toolkit.

    The post Learn about grep command in Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/learn-about-grep-command-in-linux/feed/ 0
    Learn about mkdir command in Linux https://blog.tekspace.io/learn-about-mkdir-command-in-linux/ https://blog.tekspace.io/learn-about-mkdir-command-in-linux/#respond Wed, 16 Aug 2023 19:12:55 +0000 https://blog.tekspace.io/?p=1128 The mkdir command in Linux is used to create directories (folders) in a file system. It stands for “make directory.” The command allows you to specify the name of the directory you want to create, and you can also provide various options and arguments to customize the behavior of the command. Here’s a detailed explanation

    The post Learn about mkdir command in Linux appeared first on TEKSpace Blog.

    ]]>
    The mkdir command in Linux is used to create directories (folders) in a file system. It stands for “make directory.” The command allows you to specify the name of the directory you want to create, and you can also provide various options and arguments to customize the behavior of the command.

    Here’s a detailed explanation of how the mkdir command works in Linux:

    Syntax:

    mkdir [options] directory_name

    Basic Usage:
    To create a new directory, you would typically use the mkdir command followed by the name of the directory you want to create. For example:

    mkdir my_directory

    This will create a new directory named my_directory in the current working directory.

    Options:

    -p or --parents: This option allows you to create parent directories as needed. If you want to create a directory along with its parent directories (if they don’t exist), you can use this option. For example:

    mkdir -p path/to/my_directory

    This will create the directory my_directory along with any necessary parent directories (path and to) if they don’t exist.

    -m or --mode: This option allows you to specify the permissions (mode) for the newly created directory using octal notation. For example:

    mkdir -m 755 my_directory

    This will create the directory my_directory with permissions set to 755.

    --help: Displays the help message for the mkdir command, showing its usage and available options.

    --version: Displays the version information for the mkdir command.

    Examples:

    Creating a directory with specific permissions:

    mkdir -m 700 private_data

    This will create a directory named private_data with permissions set to 700 (read, write, and execute for the owner only).

    Creating a directory with parent directories:

    mkdir -p documents/important/2023

    This will create the directory structure: documents/important/2023.

    Creating multiple directories:

    mkdir dir1 dir2 dir3

    This will create three directories named dir1, dir2, and dir3 in the current working directory.

    Creating directories with complex names:

    mkdir "My Documents" 'Work Files' 'Images and Videos'

    This will create three directories with spaces in their names.

    Remember that the mkdir command allows you to create directories in the specified path or current working directory. You can also provide an absolute path to create directories at a specific location in the file system.

    Always be cautious when using commands that modify the file system, especially with elevated privileges, as they can have significant consequences.

    The post Learn about mkdir command in Linux appeared first on TEKSpace Blog.

    ]]>
    https://blog.tekspace.io/learn-about-mkdir-command-in-linux/feed/ 0