CentOS Archives - TEKSpace Blog https://blog.tekspace.io/category/linux/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.7.1 https://blog.tekspace.io/wp-content/uploads/2023/09/cropped-Tekspace-logo-icon-32x32.png CentOS Archives - TEKSpace Blog https://blog.tekspace.io/category/linux/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
    Learn about rm command in Linux https://blog.tekspace.io/learn-about-rm-command-in-linux/ https://blog.tekspace.io/learn-about-rm-command-in-linux/#respond Wed, 30 Aug 2023 02:20:14 +0000 https://blog.tekspace.io/?p=1438 In the Linux command-line realm, mastering the art of file management is essential. The rm command, short for “remove,” is a powerful tool that allows you to delete files and directories from your system. However, this power comes with responsibility, as it can lead to irreversible data loss if not used carefully. In this guide, […]

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

    ]]>
    In the Linux command-line realm, mastering the art of file management is essential. The rm command, short for “remove,” is a powerful tool that allows you to delete files and directories from your system. However, this power comes with responsibility, as it can lead to irreversible data loss if not used carefully. In this guide, we will delve into the workings of the rm command, explore its various options, and provide real-world examples to demonstrate its usage.

    How the rm Command Works:
    The basic syntax of the rm command is rm [options] [file(s)/directory]. When executed, the command attempts to remove the specified files or directories. Here’s a breakdown of the process:

    1. File Deletion:
      When you use rm to delete a file, the file is marked as “unlinked” from the file system. This means that the space occupied by the file is now marked as available for reuse, but the data itself isn’t immediately wiped from the disk.
    2. Directory Deletion:
      Removing a directory requires additional flags, such as the -r or -rf options, to indicate that the directory and its contents should be removed recursively.

    Examples:

    1. Delete a File:
      To remove a file named “document.txt”:
       rm document.txt
    1. Delete Multiple Files:
      You can delete multiple files at once:
       rm file1.txt file2.txt
    1. Delete a Directory:
      To delete an empty directory named “folder”:
       rmdir folder
    1. Delete a Directory and its Contents:
      To remove a directory and all its files and subdirectories (use with caution):
       rm -r directory/
    1. Force Deletion:
      Use the -f option to force deletion without confirmation:
       rm -rf important_files/
    1. Interactive Deletion:
      You can use the -i option for interactive deletion, prompting you before each removal:
       rm -i file.txt

    The rm command is a potent tool for managing files and directories in Linux. Its ability to delete files and directories is crucial for system maintenance, but it should be used with caution to prevent accidental data loss. By understanding its options and practicing with examples, you can wield the rm command effectively and responsibly within the Linux command-line environment.

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

    ]]>
    https://blog.tekspace.io/learn-about-rm-command-in-linux/feed/ 0
    Learn about touch command in Linux https://blog.tekspace.io/learn-about-touch-command-in-linux/ https://blog.tekspace.io/learn-about-touch-command-in-linux/#respond Wed, 30 Aug 2023 02:15:33 +0000 https://blog.tekspace.io/?p=1435 The touch command in Linux is used to create empty files or update the access and modification timestamps of existing files. It’s a versatile command that is often used to indicate the presence of a file or update its timestamp without changing its content. Usage: Example: This creates a file with a timestamp in its […]

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

    ]]>
    The touch command in Linux is used to create empty files or update the access and modification timestamps of existing files. It’s a versatile command that is often used to indicate the presence of a file or update its timestamp without changing its content.

    Usage:

    touch [option] file_name

    Example:

    1. Creating a New File:
      To create a new empty file named “newfile.txt”:
       touch newfile.txt
    1. Updating Timestamps:
      To update the access and modification timestamps of an existing file named “existing.txt”:
       touch existing.txt
    1. Creating Multiple Files:
      You can create multiple files in a single command:
       touch file1.txt file2.txt file3.txt
    1. Creating Files in Specific Directory:
      To create a new file named “report.txt” in the “documents” directory:
       touch documents/report.txt
    1. Using with Variables:
      In a shell script, you can use the touch command to create files dynamically:
       file_name="dynamic_file.txt"
       touch "$file_name"
    1. Combining with Other Commands:
      You can use touch along with other commands to create and update files:
       touch "$(date +%Y-%m-%d)_log.txt"

    This creates a file with a timestamp in its name, such as “2023-08-29_log.txt”.

    The touch command is a handy tool for file management and timestamp manipulation. It’s commonly used in shell scripts, automation tasks, and scenarios where updating timestamps is necessary without altering file content.

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

    ]]>
    https://blog.tekspace.io/learn-about-touch-command-in-linux/feed/ 0
    Learn about pwd command in Linux https://blog.tekspace.io/lean-about-pwd-command-in-linux/ https://blog.tekspace.io/lean-about-pwd-command-in-linux/#respond Wed, 30 Aug 2023 02:08:33 +0000 https://blog.tekspace.io/?p=1429 The pwd command in Linux stands for “print working directory.” It is used to display the current directory you are in within the file system hierarchy. This command can be particularly helpful when navigating the command line interface and working with different directories. Usage: Example: Certainly, here are more examples of using the pwd command […]

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

    ]]>
    The pwd command in Linux stands for “print working directory.” It is used to display the current directory you are in within the file system hierarchy. This command can be particularly helpful when navigating the command line interface and working with different directories.

    Usage:

    pwd

    Example:

    Certainly, here are more examples of using the pwd command in different scenarios:

    1. Basic Usage:
      If you’re in the /home/user directory:
       pwd

    Output:

       /home/user
    1. Navigating to a Subdirectory:
      Suppose you’re in the /home/user directory and you navigate to a subdirectory named “projects”:
       cd projects
       pwd

    Output:

       /home/user/projects
    1. Using Full Path:
      You can use the pwd command along with other commands that require full paths. For example, creating a file in the current directory:
       touch $(pwd)/newfile.txt

    This will create a file named “newfile.txt” in the current directory.

    1. Symbolic Links:
      If you’re in a symbolic link directory that points to another location:
       pwd

    Output might show the path of the symbolic link, not the linked location.

    1. Subshell:
      If you use the pwd command within a subshell (enclosed in parentheses), it will give you the path of the current directory without affecting your current location in the main shell:
       (cd /tmp; pwd)

    Output:

       /tmp
    1. Using with Variables:
      You can assign the result of pwd to a variable in a shell script:
       current_dir=$(pwd)
       echo "Current directory: $current_dir"

    Output:

       Current directory: /home/user
    1. Using Tilde (~) Shortcut:
      When using pwd with the tilde symbol (~), it represents the home directory:
       cd ~
       pwd

    Output (assuming your home directory is /home/user):

       /home/user

    The pwd command is a simple yet essential tool that helps you keep track of your location within the file system, enabling efficient navigation and manipulation of directories and files.

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

    ]]>
    https://blog.tekspace.io/lean-about-pwd-command-in-linux/feed/ 0
    Learn about cd command in Linux https://blog.tekspace.io/learn-about-cd-command-in-linux/ https://blog.tekspace.io/learn-about-cd-command-in-linux/#respond Wed, 30 Aug 2023 01:58:15 +0000 https://blog.tekspace.io/?p=1424 The cd command in Linux is used to change the current working directory in the terminal. It allows you to navigate through different directories and access the files and subdirectories within them. The basic syntax of the cd command is: Here are a few examples to illustrate the usage of the cd command: This command […]

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

    ]]>
    The cd command in Linux is used to change the current working directory in the terminal. It allows you to navigate through different directories and access the files and subdirectories within them. The basic syntax of the cd command is:

    cd [directory_path]

    Here are a few examples to illustrate the usage of the cd command:

    1. Changing to a Specific Directory:
       cd /home/user/Documents

    This command changes the current directory to the “Documents” directory within the “user” directory.

    1. Moving Up One Directory Level:
       cd ..

    This command moves you up one level in the directory hierarchy. For example, if you were in “/home/user/Documents,” running this command would take you to “/home/user.”

    1. Moving to the Home Directory:
       cd ~

    This command takes you to your home directory, which is typically “/home/username.”

    1. Using Relative Paths:
       cd Pictures/Summer

    If you’re in the “Documents” directory and you want to navigate to the “Summer” subdirectory within the “Pictures” directory, you can use a relative path.

    1. Using Tab Completion:
       cd Downlo[TAB]

    Typing the first few characters of a directory name and then pressing the “Tab” key will autocomplete the directory name if it’s unique, making navigation faster.

    1. Using Variables:
       cd $HOME

    The $HOME variable refers to your home directory, so this command takes you to your home directory regardless of your current location.

    1. Using Absolute Paths:
       cd /var/log

    Absolute paths start from the root directory (“/”) and provide a direct way to navigate to a specific location.

    1. Using Special Directories:
       cd -

    This command takes you to the previous directory you were in. It’s useful for quickly toggling between two directories.

    Remember that Linux is case-sensitive, so directory names must be entered exactly as they appear. The cd command is an essential tool for navigating the file system and is an integral part of using the Linux command line effectively.

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

    ]]>
    https://blog.tekspace.io/learn-about-cd-command-in-linux/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