Tag Archivio per: Command


This article explains how to find all files containing specific text on Linux. For this we’ll use grep, a standard Unix program.

grep is a command-line utility which prints lines that match a given pattern, and should be installed by default.

Let’s start simple. Say you want to search for the word text (case-sensitive!) in all the files in the current directory and its subdirectories. To do this, you need to open the terminal, navigate to the folder where you want to perform the search, and run:

grep -r 'text'

This lists all the files in the current folder and subfolders containing text. This includes strings like texting for example, because it contains our search pattern, text. -r stands for recursive, reading all the files in the directory and its subdirectories. If you require following all symbolic links, use -R instead of -r.

If you only want to list the filenames containing the exact whole word text (as opposed to the default partial word matching), and not things like texting, 123text, and so on, you’d need to append the -w (whole words) command line option, like this:

grep -rw 'text'

If you don’t want to search in the current folder, but in a specific folder, you can specify the path in which grep should look into, by adding it at the end of the command, like this:

grep -rw 'text' /path/to/search/into

You might also be interested in: How To Repeat A Command Every X Seconds On Linux

Grep has many options, but below I’ll only list a few that you might find especially useful when trying to find all files containing specific text on Linux (besides those already mentioned above):

  • -n shows the line numbers. When a match is found, besides the file path in which it was found, grep will also display the line number on which the pattern was found
  • -i performs the search case-insensitive (it’s case-sensitive by default). Depending on the number of files, this can slow down the search, so take this into consideration when using it
  • --include=GLOB / --exclude=GLOB includes or excludes certain files
  • --exclude-dir=GLOB is used to exclude folders from being searched

Let’s take a look at an example which combines these command line flags. Let’s say you want to find all files containing the case-insensitive (-i) text in the ~/Documents folder and its subfolders except for the Private e Personal subfolders (--exclude-dir), and only search in the files that have the .txt e .js extensions (--include). Also, you want to show the line numbers (-n), search recursively and also follow all symbolic links (-R). In that case, the command you’d need to use would be (this is a single command):

grep -Rni --exclude-dir={Private,Personal} --include={*.txt,*.js} 'text' ~/Documents

Example output:

/home/logix/Documents/test/folder/file1.js:7:text
/home/logix/Documents/test/folder/file2.txt:7:text

Here, 7 is the line number on which the pattern we’ve searched for (text) was found.

For more information and advanced usage, see the grep man page.

You may also want to check out ripgrep, a line-oriented search tool that recursively searches the current directory for a regex pattern that comes with some extra features, and is very fast.

You  might also like: rga: Search Text In PDF, Ebooks, Office Documents, Archives And More (ripgrep Wrapper) e How To Find Files Modified In The Last N Days Or Minutes Using find


how to run a command after the previous one has finished on Linux

This article explains how to run a command after the previous command has finished running. Using this, you can run not just 2 commands, but any number of commands, after the previous one has finished. This will work with Sh, Bash, Zsh and other shells.

You can run a command after the previous one has finished, depending on the previous command’s exit status (if it failed or not) or regardless of this. So there are 3 possible situations:

  • run a command if the previous command exited successfully,
  • run a command if the previous command failed (if it has an exit status other than 0), or
  • run a command regardless of the exit status of the previous command (it doesn’t matter if it failed or not)

Let’s take a look at each of these cases below.

You might also like: How To Repeat A Command Every X Seconds On Linux

To run multiple commands successively (wait for the previous one to finish) only if the previous command exited successfully, use the && operator between the commands. For example (you can have any number of commands):

command1 && command2

If you don’t care about the exit status of the previous command, and you just want to run a command after the previous one has finished, use the ; separator. Example (you can have any number of commands):

command1; command2; command3

What if you want to run a command after the previous one has finished running, but only if this previous command has failed (if it returns an exit status other than 0). In that case, use the || separator. For example (merienda again, you can have any number of commands):

command1 || command2

You might also be interested in: How To Find Files Modified In The Last N Days Or Minutes Using find

You can also mix these operators. In that case, you can group the commands using { e }. For this to work, you need to make sure you add a semicolon (;) before } and a space after {. For example:

command1 || { command2; command3; }

In this example:

  • run command1 and wait for it to finish
  • if command1 fails, proceed to the next commands (||):
    • run command2 and wait for it to finish
    • regardless of command2‘s exit status, run command3 (;)

Another example:

{ command1 && command2; }; { command3 && command4; }

In this example:

  • run command1 and wait for it to finish
  • if command1 is successful, run command2 and wait for it to finish (&&)
  • regardless if command2 was successful or not, or if it even ran or not, run command3 and wait for it to finish (the ; after the first })
  • if command3 is successful, run command4 (&&)

As a reminder, the ; before each } is required when using {}, and does not affect the way the commands are run.

[[Edit]] The article initially used parentheses (()) for mixing the operators; but that has some drawbacks (like running the commands in a subshell) compared to using braces ({}), as pointed out by Laurent in a comment below. So I have updated the article to use {} for this.

You might like: How To Change The Default Shell In Linux


Linux run command or script as root (sudo) on startup / boot

This article explains how to run a command or script at startup / boot as root on Linux, in two ways: using systemd or a cron job.

How to use systemd to run a command or script as root on boot

To use systemd to run a command or script as root when your computer boots, create a file (as root) called mycommand.service (replace mycommand with whatever you want to call it) in /etc/systemd/system/.

We can use Nano command line text editor to open / create this file:

sudo nano /etc/systemd/system/mycommand.service

In this file, paste the following:

[Unit]

Description=your description

[Service]

ExecStart=/path/to/command/or/script

[Install]
WantedBy=multi-user.target

Here, change the Description value to describe what this does, and the ExecStart value to the command or path of the script you want to run as root on startup. Don’t add sudo at the beginning of the command or script, because it runs as root anyway.

Now save the file and exit Nano. In case you’re not allegado with Nano text editor, you can save the file by pressing Ctrl + o, then Enter. Exit by pressing Ctrl + x.

Next, you need to enable the systemd service to run on boot, using the following command:

sudo systemctl enable mycommand.service

Remember to replace mycommand.service with the presente filename you’ve used for this systemd service file. There’s no need to run the systemd service right now, since this is about running it on boot.

If you use this to run a script, make sure to make the script executable (chmod +x /path/to/script) or else it won’t run.

This is a very simple systemd unit file that runs only merienda. These can be a lot more complex, depending on what you need. For example, you could use a command that runs before ExecStart, have it start only after another unit becomes active, have the command run only after another service, e.g. the network service has been started (After=network.target, while also declaring a dependency to this service using Wants= or Requires=), and more. Check out the systemd.service e systemd.unit man pages for more details.

You might also like: How To Launch Startup Applications With A Delay

How to use a cron job to run a command or script as root on startup / boot

To use a cron job to run a command or script as root when the system boots, edit the root user crontab using:

sudo crontab -e

And at the bottom of the file (it may also be empty), use the following:

@reboot /path/to/command/or/script

Now save the crontab and exit. If you’ve used Nano command line editor to edit it (should be default in most cases), you can save the file by pressing Ctrl + o, then Enter. Exit Nano by pressing Ctrl + x. Don’t add sudo before command or script, because it runs as root anyway, since it’s added to the root crontab.

In case you want to use a particular editor to edit the root crontab, run it like this: sudo EDITOR=editor crontab -e, e.g. for Vim: sudo EDITOR=vim crontab -e, or for Nano: sudo EDITOR=nano crontab -e.

A few notes about this:

  • If you use this to run a script, make sure to make the script executable (chmod +x /path/to/script) or else it won’t run
  • Use the full path to the command or script, or else it may fail to run (this depends on the Linux distribution you’re using, e.g. you don’t need to use the full path on Ubuntu 20.04 for example)
  • If the script ran by cron also includes commands without the full path, you can avoid having to rewrite the script by adding this at the top of the crontab file: PATH=/usr/nave/sbin:/usr/nave/bin:/usr/sbin:/usr/bin:/sbin:/bin
  • If you need to delay the start of the command / script, you can make use of the sleep command, e.g.: @reboot /usr/bin/sleep 60; /path/to/command/or/script to run the command or script 60 seconds after the system boots

You might also like: How To Run A Command After The Previous One Has Finished On Linux

Which to choose between systemd or a cron job to run a command or script as root on startup / boot, if you have a choice? When in doubt, pick systemd (if it’s available on your system) because it should be more reliable and easier to use.

For example, not every version of cron supports the @reboot option, or the command / script may only run when the system is rebooted, and not when it’s shut down (this didn’t happen for me on Ubuntu 20.04, Fedora 24, Manjaro Linux and Debian 10, but it may happen on some Linux distributions).

It’s also worth noting that @reboot configures a job to run merienda when the daemon is started. cron is not usually restarted, so this usually corresponds to the machine being booted. For example, Debian (and Debian-based Linux distributions) enforces this, making cron not re-run @reboot jobs when the cron service is restarted. On some Linux distributions, though, restarting the cron service may re-run the @reboot commands.

Also, on Fedora, cron is not installed by default (install it using sudo dnf install cronie). On Manjaro, cron is installed by default, but not enabled by default (enable it using sudo systemctl enable --now cronie).

You might like: How To Find All Files Containing Specific Text On Linux From The Command Line


The “redo” term is used as the opposite of the “undo” term used in several fields of study, i.e., it will remove the changes made by “undo” and take you to the llamativo state. While doing any important task, have you ever encountered a situation where you have accidentally done something that you never wanted to do? If so, then you may have felt that the mistake that happened accidentally should be “undone” to get back to the llamativo status of the work. In Ubuntu 20.04, we came up with its Vim editor that uses the “undo” and “redo” commands in it to perform opposite functions. So, we will be discussing the use of “redo” command today.

Vim Editor Installation

To get started, you must ensure that the Vim editor utility has been fully configured on your end. For this, you need to check out its installed version by the use of a simple “version” command. The output has demonstrated that the “vim” editor is not found. Thus, it also displayed some of the useful “Apt” instructions to install it from scratch on your system.


Thus, we have been trying the very first “apt” package installation instruction to install the “vim” editor on the Ubuntu 20.04 Linux operating system as quickly as possible. Try to update your system before any installation to avoid any issues during the installation process. It is required to add the currently logged-in user’s password to continue this administrative task. Therefore, we have provided it with the password and hit the key “Enter,” i.e., the installation has started.


In a few seconds, it will show us some questions about the space concerns of our system, i.e., the installation may take up to 34.6 MB of space on our system, and if we want to install it or not. You have to press the “y” key to continue this process, as we did below.


Our system will start installing it at our end without any hindrance. So, sit calmly and wait until it’s completed, i.e., approaches 100 percent.


At the end of the installation of the Vim editor on the Ubuntu 20.04 Linux system, we may get some processing lines that are like those shown below. Now, it’s fully installed and functional in our system.

Create File

To perform a redo operation, we need some text files to be opened in the vim editor. While listing the home directory contents with the use of the “ls” command, we have found that there is no text file in it, i.e., we need to create one in this case. So, we have tried Ubuntu’s “touch” query at the console query area and created a new text file named “file.txt” as shown. After listing the contents of the current working directory again with the “ls” instruction, we find that the text file has been successfully created in it.


We have added five lines of text data to it using the text editor first. After trying the cat instruction along with the name of a file, we have displayed the data within the “file.txt” file on the console. You can see it has a total of 5 lines.

Open File in Vim

To perform the redo shortcut on the file, we will be opening it (file.txt) within the Vim editor using the “vim” instruction along with the file name as displayed in the small image.


After the execution of the vim instruction, we got the shown-below vim screen quickly opened in the console shell of the Ubuntu 20.04 system. It is giving us the attention message along with some quick shortcuts to be used in the vim editor, i.e., how to quit, how to edit, and many more. Press the Enter key, Esc key, or space until it opens your file.txt data in the editor.


Our 5-line text file “file.txt” has been successfully launched within the corriente mode of the vim editor as per the shown screen below. Within the corriente mode, you cannot insert the file contents, so you need to move within the insert mode of Vim by pressing the “I” key on the keyboard.

Vim Redo vs Undo Command

On pressing the “I” key, we got into the insert mode of the vim as shown from the last 2 displayed lines in the image. So, we have to press Enter and remove the 4th line from the file.


After this, we have also removed the 2nd line from the text file using the backspace button while we are in the Insert mode of the Vim editor. Now, you need to save it and move within the corriente mode by pressing the “Esc” key.


To perform undo and redo changes, you must have been in the command mode of the vim. To open the command mode, press “:” on the keyboard. You can try any command in it to make changes to this file. To perform the redo command, we must use the undo command first on this file. So, we have tried the “undo” command within the command area of this Vim editor after the use of the “:” sign. Press Enter to execute the undo instruction as shown in the image.


The 4th line is back in the file as below.


Again, we used the “undo” command.


The 2nd line is also back in the file.


Now, while you are in corriente mode, press “Ctrl+R” to redo the undo command changes that we have just implemented. You can also try the “:redo” command in the command mode of vim.


Using the redo command, you will see that the second line is now deleted.


We have again used the redo “ctrl+R” or “:redo” command.


We are now at our last change made before the use of the “undo” instruction, i.e., 3 lines.

Conclusion:

This article has been an informative guide toward the use of “redo” and “undo” commands in the Vim editor. For this, we have explained the terms “undo” and “redo” quiebro well in the introduction. After that, we tried to install Vim and opened the newly created text file in it to perform “undo” and “Redo” commands to see the changes made by the “Redo” especially. The examples given above are very easy to do for every user, especially for learners.



Source link


The bottom command is an open-source command-line utility that enables Linux users to preceptor the performance of their systems, such as CPU resources, system temperature, memory information, network resources and much more. Since this tool supports both Linux and ARM-based architecture, thus you can install it on your Raspberry Pi to preceptor your device performance.

This article shows you the most straightforward approach to install the bottom command on Raspberry Pi to preceptor your system performance.

System Monitoring on Raspberry Pi Using the bottom Command

You cannot install the bottom command directly on your Raspberry Pi device; however, you can install a deb package for the GitHub website according to your system architecture using the following steps:

Step 1: Update Raspberry Pi Source List

Before installing the bottom utility on your Raspberry Pi device, you must update the current packages on your system through the following command:

$ sudo apt update && sudo apt upgrade

Step 2: Download bottom Utility Deb Package on Raspberry Pi

Next, you will need to download bottom utility deb package on Raspberry Pi for 64Bit Raspberry Pi OS and to do this apply the following command:

$ wget https://github.com/ClementTsang/bottom/releases/download/nightly/bottom_aarch64-unknown-linux-gnu.deb

You can also find a 32Bit version of the deb package for your Raspberry Pi from GitHub website and to download this version, you just need to replace the version in the above command.

Step 3: Install bottom Utility Deb Package

After successfully downloading the deb package, run the below-mentioned command to install the bottom utility on your Raspberry Pi device:

$ sudo apt install ./bottom_aarch64-unknown-linux-gnu.deb

Make sure to replace the version of the bottom in the above command as well.

After completing the installation, apply the following command to confirm the latest version of the bottom version installed on your Raspberry Pi.

Step 4: Run bottom Utility on Raspberry Pi

To get the information about your Raspberry Pi system’s resources, you have to apply the following command:

The above result shows the system resources on your Raspberry Pi terminal and if you want to have further information about your device resources, you can issue the following command for help:

From the help section, you will see several commands ranging from basic to complete and you can use these commands to get the overview of your device resources.

Remove bottom Utility From Raspberry Pi

In case you are not interested in using the bottom utility services on your Raspberry Pi device, you can easily remove it using the following command:

$ sudo apt remove bottom-arm64 -y

Conclusion

The bottom is a lightweight system monitoring tool that displays your Raspberry Pi device information onto the terminal window. You can install this application easily on your device by downloading the deb package and through an apt installer. The detailed step-by-step instructions are already provided in the above-given guidelines.



Source link


The sysctl is a helpful tool for any Linux administrator. It allows the reading and writing of sysctl variables. With it, you can modify the kernel parameters of your system at runtime. The Linux kernel is the operating system’s core, controlling different system services. The kernel parameters can be set at three instances, during the building of the kernel, at system boot, and at runtime.
The /proc/sys/ contains the kernel parameters. We will see how to use the sysctl command to modify the Linux kernel parameters

Using the sysctl Linux Command

The sysctl uses the files in the /proc/sys directory to modify kernel parameters. You can list the contents of the directory to see the different folders.

sysctl: Display Kernel Parameters

Use the “-a” or “-all” flag to view all the configured kernel parameters.

 
All the configurations will display in a long list showing the parameters and their values in each line.

The previous list can be challenging to understand, but there is a way to narrow it down by checking the values of single parameters. You can pass the parameter’s name to the command and get its specific value. For instance, you can use the following commands to get the kernel hostname e swappiness, which defines how often the system uses the swap space.

$ sysctl kernel.hostname
$ sysctl vm.swappiness

 

The same output can be obtained by retrieving the contents of the file containing it. You only need to replace the “slash” with a “dot”.

For instance, use the following commands to get the same values previously shown:

Alternately, you can filter the output by grep-specific kernel parameters by providing matching words. For example, to filter all ipv4 output, you can use the following command:

sysctl: Modify Kernel Parameters

As an administrator, the sysctl allows you to permanently or temporarily modify the kernel parameters.

The syntax for temporarily modifying kernel parameters is:

$ sysctl -w [parameter=value]

 
Note that if the value contains special characters or spaces, you should enclose it in double quotes. Furthermore, the set parameters reset to the initial values after the next reboot.

Let’s take an example of the TCP Fast Open, which speeds up the loading of TCP connections between two devices. By default, it is enabled. To disable it, use the following command. You should have administrator privileges for it to work. Also, ensure no spaces are between the parameter and the value.

$ sudo sysctl -w net.ipv4.tcp_fastopen=0

 

We see that the values modify from “1” for enabled to “0” for disabled.

If you were to set the same parameters permanently, you need to modify the parameters either in the /etc/sysctl.conf or in the /etc/sysctl.d/99-custom.conf directory. You can open the files using an editor or directly add the configuration using echo.

$ echo 0 > /proc/sys/net/ipv4/tcp_fastopen=0

 
Executing the previous command will modify the parameters permanently.

You can also add the net.ipv4.tcp_fastopen in the configuration file.

$ sudo nano /etc/sysctl.d/99-systemctl.conf

 
Adding the parameter and its value will get loaded every time the system boots.

The system default loads the configurations in the /etc/sysctl.conf file. However, you can use the “-p” option to load another configuration file like the one we previously modified.

$ sysctl -p /etc/sysctl.d/99-systemctl.conf

 
Proceed with caution when making the permanent kernel changes to avoid rendering your kernel unstable. That said, any time you need to modify a parameter, use the syntax highlighted in the article or directly modify it from the configuration file.

Conclusion

The Linux kernel powers the Linux operating system. If you are a Linux system administrator, modifying the kernel parameters to suit various tasks is part of your job. Luckily, this post covers how you can achieve that using the sysctl Linux command.



Source link


To create a new user account for your Redshift cluster, the CREATE USER command is used. In order to use this command, you must be a superuser or you must have proper privileges to create the user. The purpose of creating multiple users in the Redshift cluster is to assign the limited permissions to each user depending upon the functionalities in which the user will perform.

In this blog, we will discuss about the CREATE USER function to create a user on the Redshift cluster on AWS.

CREATE USER Syntax

The following is the syntax to create a user in the Redshift cluster:

1
2
3

CREATE USER <user name> [ WITH ] PASSWORD ‘md5hash’

[ option [] ]

The CREATE USER function takes the following parameters:

  • Name
  • Password
    • Plain text
    • MD5 hashed
    • SHA256 hashed
  • Options

Name

This parameter is the name of a new user account which will be created on Redshift.

Password

In this parameter, you can set the password for the new user. You can disable the access for the user to change the password. But by default, new users can change their password. When you disable the user password, the user can only log on by using the AWS IAM (Identity and Access Management) credentials. New users cannot disable or change the superuser password. Only the superuser has this privilege.

We can set the passwords in three different ways, i.e, plain text, MD5 hash string and SHA256 hash string.

Plain Text

For the plain text, the password must fulfill the following conditions:

  • It must contain a minimum of 8 characters and maximum of 64 characters
  • It must contain both lower and upper case letters
  • It must contain at least one numeric number
  • It can also use the ASCII characters with codes ranging from 33 to 126 except the single quotation mark (‘), double quotation mark (“), forward slash (/), back slash (), or at the rate sign (@).

MD5 Hash String

The more secure way to set the password is the MD5 hash string as compared to the plain text password.

For MD5 hash string, you need to follow these steps:

  • The first step is to concatenate the username and password, which means joining the password and the username. For example, the username is admin and the password is 123, then the concatenate string is 123admin.
  • Convert the concatenate string into a 32-character MD5 hash string. There are many ways to convert it. We use the AWS Redshift concatenate function(||) to return the 32-character MD5 hash string.

You can generate the MD5 hash of a string by executing the following query in the Redshift cluster:

1

select md5(‘123’ || ‘admin’);

Output: d829b843a6550a947e82f2f38ed6b7a7

You need to concatenate the md5 keyword with the 32-character MD5 hash string and apply this string to the MD5 hash argument.

In order to create a user with the MD5 hash password, you need to concatenate the md5 keyword before the MD5 hash password.

1

create user admin password ‘md5D829b843a6550a947e82f2f38ed6b7a7’;

Now, this username and password can be used to log in to the Redshift cluster.

SHA-256 Hash

This is another secure way to set the password. Following are the two parts of the SHA256 hash:

Digest: The output of the hashing function in SHA-256.

Salt: It is the data generated randomly to combine with the password to help securely encrypt the password.

Following is the query to create a new user in Redshift with SHA256 hashed password. In this query, AWS Redshift automatically generates and manages the salt.

1

CREATE USER admin PASSWORD ‘sha256|Mypassword1’;

Options

There are multiple options available that can be used while creating the user for the Redshift cluster. These options can define multiple parameters for the user. Following are some options that can be used while creating a new user:

Now, we will discuss all these options one by one.

CREATEDB | NOCREATEDB

CREATEDB option equips the new user to create a new database. By default, it is set to NOCREATEDB.

CREATEUSER | NOCREATEUSER:

CREATEUSER option provides the new user a full access to create a new user in the Redshift cluster. By default, this option is set to NOCREATEUSER and the newly created user cannot create another user in the Redshift cluster with the default value for this option.

SYSLOG ACCESS UNRESTRICTED

It defines the level of access that a new user has on the Redshift tables. If it is defined as restricted. The new user’s access is restricted to the rows generated by itself in the user-visible system tables and views. By default, it is set to restricted.

If it is defined as unrestricted, the new user can view all the rows even if it is included by the other users. But, it does not give the access of the superuser visible tables.

IN GROUP Groupname

This option defines the name of the group that the new user will belong to. For this option, multiple group names may also be listed.

VALID UNTIL ABSTIME

This option defines the absolute time after which a new user account password will no longer be valid. By default, the new user password has no time limit and is valid forever.

CONNECTION LIMIT  (LIMIT | UNLIMITED)

This option defines the maximum number of database connections that can be opened simultaneously by the user. By default, it is set to unlimited.

SESSION TIMEOUT LIMIT

This Option defines the maximum time in seconds that the session can remain inactive. The session timeout range for a Redshift user is from one minute to 20 days. By default, it is decided by the cluster.

EXTERNALID

The EXTERNALID option specifies the identifier for a new user that is linked with an external identity provider. The user is authorized by an external identity provider instead of password, so the password must be disabled if this option is specified.

CREATE USER Examples

In this section, let’s take the multiple examples to fully understand the concept of creating a new user account in a Redshift cluster.

Setting the Connection Limit on New User

In order to create a user with the name engineer and password Admin123 and having a maximum connection limit of 20, use the following query:

1

create user engineer with password ‘Admin123’ createdb connection limit 20;

Now, execute the following query to view the details about all the database users:

1

select * from pg_user_info;

Scroll right to the menu bar to view the column of useconnlimit. For the user engineer, the connection limit is 20.

Setting the Password Validation on New User

In this example, we will create a user account with the name developer and password Admin1234. We will also pass an option to set the password validation.

1

create user developer with password ‘Admin1234’ valid until ‘2022-06-10’;

Now, execute the following query to list all the users in the Redshift cluster.

1

select * from pg_user_info;

As you can see in the following screenshot, that password validation for the user is set to 2022-03-10.

Setting the User Password Including Special Characters

In this example, we will create a user with the case sensitive characters and special characters in the password.

1

CREATE USER awsadmin with password ‘&Admin1234!’;

Setting the Session Timeout for New User

In this example, we will create a user with the name newman and password abcD1234. And set the session timeout to 150 seconds.

1

CREATE USER newman with password ‘abcD1234’ SESSION TIMEOUT 150;

Setting the Namespace for New User

In this example, we will create a user with the name john and the namespace aws_user using the option EXTERNALID.

1

CREATE USER aws_user:john EXTERNALID «ADMIN123» PASSWORD DISABLE;

Conclusion

In this article, we discussed how we can use the CREATE USER command in the Redshift to create a user. We can use the multiple options while creating the new user to set the certain limits on the user. AWS Redshift creates a user command that is very useful and provides a wide range of options to create new users with the different levels of privilege for the database.



Source link


Often, you may need to convert or add the images to the PDF files, especially if you have an application and you want the users to download the images as PDF files.

There are different online tools that convert the images to PDF. But security is always a concern, and you can’t trust these online sites with your data. The best method is to convert the images on your machine. Linux offers various command-line utilities to aid you with that. The two common tools are Img2PDF and ImageMagick.

1. ImageMagick

ImageMagick stands out for the image conversion to PDF for its fast speed. The open-source Linux tool utilizes the multiple CPU threads to keep the conversion process fast. Whether converting one image or multiple images, ImageMagick gets the job done.

Let’s first install ImageMagick using the following command:

1
2
3

$ sudo apt update

$ sudo apt install -y imagemagick

For Fedora users, the command is as follows:

1

$ sudo dnf install imagemagick

With the ImageMagick already installed, navigate to the directory containing your pictures. We have different images in our example. We will see how we can convert them one by one and how to convert them all at merienda.

The syntax for conversion is as following:

1

$ convert image demo.pdf

Note that we are using convert, a utility for ImageMagick. Let’s start by converting one image.

If you run the previous convert command, it should work fine. However, you may end up with an error message like the one reflected in the following image:

In that case, all you need is to edit the policy.xml file using an editor like nano.

1

$ sudo nano /etc/ImageMagick-6/policy.xml

Look for the line in the following example:

1

<policy domain=«coder» rights=«none» pattern=«PDF» />

To fix the error, replace the rights from “none” to “read|write”

Save the file and rerun the command. You will now have a PDF file of the converted image.

To convert all the images in the current directory to PDF, you can add their names one by one or select the image format if they are the same. In our case, the image formats are in “.jpg”. In this case, our command is as follows:

That’s it! You now have all your images converted into one PDF.

ImageMagick is a great tool for converting the images to PDF on the command line. The only bad side of it is that the resolution for the images changes and the PDF file doesn’t have the full resolution, reducing the image quality.

 

2. Img2PDF

The ImageMagick converts the images to PDF, but the quality of the images reduces. The alternative is to use the Img2PDF to convert the same photos without losing the image quality. Besides, Img2PDF allows the specification of the image size when converting.

Start by installing Img2PDF using the following command:

1

$ sudo apt install img2pdf

You can verify the installation by checking the version.

Img2PDF can also be installed using pip in other distributions:

With the tool installed, let’s proceed to convert our images. We use the same pictures as we did with ImageMagick. First, navigate to the directory that contains your images. To convert a single file, use the following syntax:

1

$ img2pdf img -o converted.pdf

We now have a PDF version of the image. If you want to convert multiple images, you can list them all. Or if they have the same format, use the * shorthand like in the following example:

To specify the page size or the image size for the output, use the –imgsize or –pagesize.

For instance, to specify the image size to 30cm by 45cm, the command is:

1

$ img2pdf <image> –imgsize 30cmx45cm -o output.pdf

Conclusion

Converting the images of different formats to PDF shouldn’t trouble you when using Linux. There are command-line utilities at your disposal, and the syntax is easy. This guide has presented two utilities, Img2PDF and ImageMagick, that you can use to convert either one or multiple images to PDF.



Source link


NPM or Node Package Manager is a fantastic tool that helps JavaScript developers download, install, uninstall, and update packages.

NPM holds one of the largest JavaScript registries that helps you easily search and manage packages.

This tutorial will go over the solutions you can try when you encounter the “NPM command not found” error.

What causes this error?

In most cases, this type of error occurs when the system cannot find the path where npm or NodeJS is installed.

This could be because you don’t have npm or NodeJS installed on your system or haven’t configured the PATH to binaries.

Ensure npm is installed

The first step to resolving this type of error is to ensure that you have npm installed on your system.

You only need to install NodeJS as it comes packaged in most cases. To check if NodeJS is installed, run the command:

If NodeJS is installed on your system, the command above should produce the installed Node version.

If you get an error, you do not have it installed on your system.

Installing NodeJS and NPM on Windows

To install npm and NodeJS on your windows system, open your browser and navigate to the resource below:

https://nodejs.org/en/download/

Select the installer for your system and download it.

Launch the installer package merienda the download is complete and follow along with the setup wizard.

Under “Custom Setup,” select Add to PATH and set it to “Entire feature will be installed on the nave hard drive.”

Follow the following steps, click install a begin the installation process.

Check Node and NPM versions.

Merienda the installation is complete, open your terminal window and run the commands:

The command above should return the installed Node Version

The above should print the installed npm version.

Windows Manually Add Node and NPM to Path

On Windows, you may face the “npm command not found” error if the path to nodejs and npm are not added to your path variable.

To fix this, locate the path to nodejs and npm binaries.

By default, NodeJS is installed inC:Program Filesnodejs

Open the command prompt and run the command below to add it to your path

$ set PATH=%PATH%;«C:Program Filesnodejs»

The command above should add the specified directory to the path variable.

Installing NodeJS and NPM on Linux

On Linux, you can use your package manager to install nodejs and npm as shown:

$ sudo apt-get update
$ sudo apt-get install nodejs npm -y

Merienda completed, verify nodejs and npm are accessible by checking the versions.

Fix “npm command not found” error – Permissions

In some instances, you may face the “npm command not found” error due to directory permissions.

On Linux, you can fix it by running the commands:

$ sudo chown -R $(whoami):root $(npm root -g)

The command above should change the permissions of the npm mundial package location to the current user.

On macOS, you can run the command:

$ sudo chown -R $(whoami):admin $(npm root -g)

Conclusion

This article explored various possible causes of the “npm command not found” error. We also dove into details on different methods and techniques you can use to fix it.



Source link


“Homebrew, or brew for short, is a free and open-source package manager for Mac and Linux operating systems. The brew is a lightweight command-line utility built on top of the Ruby programming language.

It offers an easy-to-manage command-line interface that allows you to download, install, update, and uninstall packages. Brew uses a set of open-source repositories, and developers can add or remove packages.

For this tutorial, we will learn how to resolve the “brew command not found” error you may encounter when you run the brew command.”

What is “brew command not found”?

The “brew command not found” error occurs when your system cannot find the brew binary in its path. Unix systems have a list of directories in which to check for binaries of a command.

Therefore, when you run a command from your terminal, the system will search this list of directories for the binary with that name. If the system does not find a binary with such a name, it will return the “command not found” error.

The list of directories where the system will search is stored in the PATH environment variable.

You can view the list by running the command:

The command should print all the directories where your system will search for the target binaries.

If you have Homebrew installed and still getting the “brew command not found” error, it’s mainly because the path to the brew binary is missing from the path environment variable.

Let us discuss various ways to resolve it.

Install Homebrew

The first step is to ensure that Homebrew is installed correctly on your system. Run the command below to install Homebrew on your system.

1

/bin/bash -c «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)«

If you wish to re-install Homebrew, run the command below to uninstall Homebrew:

1

$ NONINTERACTIVE=1 /bin/bash -c «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)«

You can then run the command above to re-install it.

Adding Brew to Path

By default, the brew will automatically add the install directory to the path upon installation. However, this may sometimes fail and require you to add the directory manually.

You can do this by running the command:

Bash

1

$ echo ‘export PATH=»/usr/lugar/bin:$PATH»‘ >> ~/.bash_profile

If Homebrew is installed in a different directory, ensure to replace the /usr/lugar/bin with the target directory.

For example, in macOS, brew is installed in /opt/homebrew/bin.

ZSH

1

echo ‘export PATH=»/usr/lugar/bin:$PATH»‘ >> $HOME/.zshrc

Similarly, feel free to replace the /usr/lugar/bin with the target directory.

Merienda completed, you can confirm that the brew command is working properly by running the command:

1
2
3

$ brew –version
Homebrew 3.5.1
Homebrew/homebrew-core (git revision 9f9fcb8997c; last commit 2022-06-08)

And there you have it; Homebrew is successfully installed and accessible from your terminal session.

Closing

Through this tutorial, you learned the possible causes of the “brew command not found” error and various ways to fix it. We hope this article has helped you.

Thanks for reading!!



Source link