Nat  Grady

Nat Grady

1678977916

Take a Screenshot from the Command Line on Linux

Linux is a highly customizable and flexible operating system, offering users a variety of tools and commands to perform tasks. One of these tasks is taking screenshots, which can be easily done through the command line, furthur read this article as it is all about how to take screenshots from the command line in Linux.

How to Take a Screenshot from the Command Line on Linux

There are several command line interface applications available for taking screenshots in Linux, the two of the most used easy to use are:

  • Using scrot
  • Using import

Let’s take a closer look at each of these tools.

Method 1: Using scrot on Linux

To install scrot on Debian, Ubuntu or Linux Mint use the Apt package manager as this tool is by default present in it:

$ sudo apt install scrot

Taking Screenshots with scrot Tool

Now we will cover different ways of taking a screenshot using the scrot:

1. Take Entire Desktop Screenshot

To take the entire desktop screenshot simply run the scrot command. This will capture everything on desktop and save it in the current directory with a file format of .png:

$ scrot

Here we can see the screenshot is saved in the current directory that is the home directory in our case.

To specify the directory to save the screenshot run below command, using this we can also change screenshot name:

$ scrot ~/Pictures/image.png

Now we can see the screenshot is captured and saved inside the picture directory with the name image.png.

2. Take Screenshot of Specific Region

Using the scrot we can take a custom screenshot by dragging the mouse cursor and it also allows taking a screenshot of a specific window.

$ scrot -s

Once the command is entered, click over any window which you want to capture or draw a rectangle with the mouse over the region which needs to be captured.

Note: If any window is blocking the rectangular screenshot, first clear the region by minimizing extra windows and clear the area before taking the screenshot. You can also use the delay command to take a screenshot after a certain time.

3. Adjusting Screenshot Size

The scrot command also allows you to adjust the screenshot size between 1 to 100. For example, to reduce size to 10% of the original use following command:

$ scrot -t 10

4. Taking a Screenshot with Delay

Using scrot we can also take a screenshot with some delay which allows us to highlight or mention windows before taking a screenshot or to show a certain event (e.g., notification) inside the screenshot. Using -d N command we can delay any screenshot with N seconds.

$ scrot -s -d 5

5. Use a scrot Screenshot in Other Commands

One of the very useful features of scrot command is that it allows you to capture and use the same screenshot for image processing such as editing or removing background. Using scrot any of the captured screenshot from scrot can be given as an input to other commands, the screenshot path is stored as a $f string.

$ scrot -e 'mv $f ~/screenshots'

6. Adjusting Quality of a Screenshot

By default, scrot takes screenshots in quality at 75. We can improve this by defining it somewhere between 1 to 100 (higher quality means better screenshot).

$ scrot -q 50

Method 2: Using import Command on Linux

The import is another command line tool for taking screenshots in Linux. This tool is part of the ImageMagick package, which provides a suite of image manipulation tools.

The ImageMagick can be installed using:

$ sudo apt install imagemagick

Once installed, you can take a screenshot by running the following command:

$ import screenshot.png

This will take a screenshot of the entire screen and save it as “screenshot.png” in your current working directory, you can also specify the region to be captured by using the -crop option:

$ import -crop WxH+X+Y screenshot.png

Where W is the width, H is the height, X is the X-coordinate, and Y is the Y-coordinate of the region to be captured.

Conclusion

Taking screenshots from the command line in Linux is a straightforward and easy process, thanks to the availability of several powerful tools such as scrot, and import. Whether you’re a beginner or an advanced Linux user, these tools provide a flexible and convenient way to capture screenshots in Linux.

Original article source at: https://linuxhint.com/

#linux #screenshot #command #line 

What is GEEK

Buddha Community

Take a Screenshot from the Command Line on Linux

How to Bash Read Command

Bash has no built-in function to take the user’s input from the terminal. The read command of Bash is used to take the user’s input from the terminal. This command has different options to take an input from the user in different ways. Multiple inputs can be taken using the single read command. Different ways of using this command in the Bash script are described in this tutorial.

Syntax

read [options] [var1, var2, var3…]

The read command can be used without any argument or option. Many types of options can be used with this command to take the input of the particular data type. It can take more input from the user by defining the multiple variables with this command.

Some Useful Options of the Read Command

Some options of the read command require an additional parameter to use. The most commonly used options of the read command are mentioned in the following:

OptionPurpose
-d <delimiter>It is used to take the input until the delimiter value is provided.
-n <number>It is used to take the input of a particular number of characters from the terminal and stop taking the input earlier based on the delimiter.
-N <number>It is used to take the input of the particular number of characters from the terminal, ignoring the delimiter.
-p <prompt>It is used to print the output of the prompt message before taking the input.
-sIt is used to take the input without an echo. This option is mainly used to take the input for the password input.
-aIt is used to take the input for the indexed array.
-t <time>It is used to set a time limit for taking the input.
-u <file descriptor>It is used to take the input from the file.
-rIt is used to disable the backslashes.

 

Different Examples of the Read Command

The uses of read command with different options are shown in this part of this tutorial.

Example 1: Using Read Command without Any Option and variable

Create a Bash file with the following script that takes the input from the terminal using the read command without any option and variable. If no variable is used with the read command, the input value is stored in the $REPLY variable. The value of this variable is printed later after taking the input.

#!/bin/bash  
#Print the prompt message
echo "Enter your favorite color: "  
#Take the input
read  
#Print the input value
echo "Your favorite color is $REPLY"

Output:

The following output appears if the “Blue” value is taken as an input:

Example 2: Using Read Command with a Variable

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable. The method of taking the single or multiple variables using a read command is shown in this example. The values of all variables are printed later.

#!/bin/bash  
#Print the prompt message
echo "Enter the product name: "  
#Take the input with a single variable
read item

#Print the prompt message
echo "Enter the color variations of the product: "  
#Take three input values in three variables
read color1 color2 color3

#Print the input value
echo "The product name is $item."  
#Print the input values
echo "Available colors are $color1, $color2, and $color3."

Output:

The following output appears after taking a single input first and three inputs later:

Example 3: Using Read Command with -p Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -p option. The input value is printed later.

#!/bin/bash  
#Take the input with the prompt message
read -p "Enter the book name: " book
#Print the input value
echo "Book name: $book"

Output:

The following output appears after taking the input:

Example 4: Using Read Command with -s Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -s option. The input value of the password will not be displayed for the -s option. The input values are checked later for authentication. A success or failure message is also printed.

#!/bin/bash  
#Take the input with the prompt message
read -p "Enter your email: " email
#Take the secret input with the prompt message
read -sp "Enter your password: " password

#Add newline
echo ""

#Check the email and password for authentication
if [[ $email == "admin@example.com" && $password == "secret" ]]
then
   #Print the success message
   echo "Authenticated."
else
   #Print the failure message
   echo "Not authenticated."
fi

Output:

The following output appears after taking the valid and invalid input values:

Example 5: Using Read Command with -a Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -a option. The array values are printed later after taking the input values from the terminal.

#!/bin/bash  
echo "Enter the country names: "  
#Take multiple inputs using an array  
read -a countries

echo "Country names are:"
#Read the array values
for country in ${countries[@]}
do
    echo $country
done

Output:

The following output appears after taking the array values:

Example 6: Using Read Command with -n Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -n option.

#!/bin/bash  
#Print the prompt message
echo "Enter the product code: "  
#Take the input of five characters
read -n 5 code
#Add newline
echo ""
#Print the input value
echo "The product code is $code"

Output:

The following output appears if the “78342” value is taken as input:

Example 7: Using Read Command with -t Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -t option.

#!/bin/bash  
#Print the prompt message
echo -n "Write the result of 10-6: "  
#Take the input of five characters
read -t 3 answer

#Check the input value
if [[ $answer == "4" ]]
then
   echo "Correct answer."
else
   echo "Incorrect answer."
fi

Output:

The following output appears after taking the correct and incorrect input values:

Conclusion

The uses of some useful options of the read command are explained in this tutorial using multiple examples to know the basic uses of the read command.

Original article source at: https://linuxhint.com/

#bash #command 

Nat  Grady

Nat Grady

1678977916

Take a Screenshot from the Command Line on Linux

Linux is a highly customizable and flexible operating system, offering users a variety of tools and commands to perform tasks. One of these tasks is taking screenshots, which can be easily done through the command line, furthur read this article as it is all about how to take screenshots from the command line in Linux.

How to Take a Screenshot from the Command Line on Linux

There are several command line interface applications available for taking screenshots in Linux, the two of the most used easy to use are:

  • Using scrot
  • Using import

Let’s take a closer look at each of these tools.

Method 1: Using scrot on Linux

To install scrot on Debian, Ubuntu or Linux Mint use the Apt package manager as this tool is by default present in it:

$ sudo apt install scrot

Taking Screenshots with scrot Tool

Now we will cover different ways of taking a screenshot using the scrot:

1. Take Entire Desktop Screenshot

To take the entire desktop screenshot simply run the scrot command. This will capture everything on desktop and save it in the current directory with a file format of .png:

$ scrot

Here we can see the screenshot is saved in the current directory that is the home directory in our case.

To specify the directory to save the screenshot run below command, using this we can also change screenshot name:

$ scrot ~/Pictures/image.png

Now we can see the screenshot is captured and saved inside the picture directory with the name image.png.

2. Take Screenshot of Specific Region

Using the scrot we can take a custom screenshot by dragging the mouse cursor and it also allows taking a screenshot of a specific window.

$ scrot -s

Once the command is entered, click over any window which you want to capture or draw a rectangle with the mouse over the region which needs to be captured.

Note: If any window is blocking the rectangular screenshot, first clear the region by minimizing extra windows and clear the area before taking the screenshot. You can also use the delay command to take a screenshot after a certain time.

3. Adjusting Screenshot Size

The scrot command also allows you to adjust the screenshot size between 1 to 100. For example, to reduce size to 10% of the original use following command:

$ scrot -t 10

4. Taking a Screenshot with Delay

Using scrot we can also take a screenshot with some delay which allows us to highlight or mention windows before taking a screenshot or to show a certain event (e.g., notification) inside the screenshot. Using -d N command we can delay any screenshot with N seconds.

$ scrot -s -d 5

5. Use a scrot Screenshot in Other Commands

One of the very useful features of scrot command is that it allows you to capture and use the same screenshot for image processing such as editing or removing background. Using scrot any of the captured screenshot from scrot can be given as an input to other commands, the screenshot path is stored as a $f string.

$ scrot -e 'mv $f ~/screenshots'

6. Adjusting Quality of a Screenshot

By default, scrot takes screenshots in quality at 75. We can improve this by defining it somewhere between 1 to 100 (higher quality means better screenshot).

$ scrot -q 50

Method 2: Using import Command on Linux

The import is another command line tool for taking screenshots in Linux. This tool is part of the ImageMagick package, which provides a suite of image manipulation tools.

The ImageMagick can be installed using:

$ sudo apt install imagemagick

Once installed, you can take a screenshot by running the following command:

$ import screenshot.png

This will take a screenshot of the entire screen and save it as “screenshot.png” in your current working directory, you can also specify the region to be captured by using the -crop option:

$ import -crop WxH+X+Y screenshot.png

Where W is the width, H is the height, X is the X-coordinate, and Y is the Y-coordinate of the region to be captured.

Conclusion

Taking screenshots from the command line in Linux is a straightforward and easy process, thanks to the availability of several powerful tools such as scrot, and import. Whether you’re a beginner or an advanced Linux user, these tools provide a flexible and convenient way to capture screenshots in Linux.

Original article source at: https://linuxhint.com/

#linux #screenshot #command #line 

CODE VN

CODE VN

1637563159

Tìm kiếm tuyến tính bằng Python

Trong bài đăng python này, bạn sẽ tìm hiểu những điều sau:

  • Tìm kiếm tuyến tính là gì?
  • Thuật toán tìm kiếm tuyến tính
  • Viết chương trình Python để tìm kiếm tuyến tính bằng While Loop
  • Viết chương trình Python để tìm kiếm tuyến tính bằng For Loop
  • Tìm kiếm tuyến tính trong Chương trình Python sử dụng Đệ quy

Tìm kiếm tuyến tính là gì?

Trước hết, Tìm kiếm tuyến tính, còn được gọi là tìm kiếm tuần tự, phương pháp này được sử dụng để tìm một phần tử trong danh sách hoặc mảng. Nó kiểm tra từng phần tử của danh sách một / tuần tự cho đến khi tìm thấy một kết quả phù hợp hoặc toàn bộ danh sách đã được tìm kiếm.

Thuật toán tìm kiếm tuyến tính

Triển khai tìm kiếm tuyến tính theo các bước sau:

  • Duyệt qua danh sách / mảng bằng cách sử dụng một vòng lặp.
  • Trong mỗi lần lặp, hãy liên kết  target giá trị với giá trị đã cho của danh sách / mảng.
    • Nếu các giá trị khớp, trả về chỉ mục hiện tại của danh sách / mảng.
    • Nếu không, hãy chuyển sang phần tử mảng / danh sách tiếp theo.
  • Nếu không tìm thấy kết quả phù hợp, hãy quay lại  -1.

Viết chương trình Python để tìm kiếm tuyến tính bằng While Loop

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Viết chương trình Python để tìm kiếm tuyến tính bằng For Loop

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Tìm kiếm tuyến tính trong Chương trình Python sử dụng Đệ quy

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.

Búsqueda lineal en Python

En esta publicación de Python, aprenderá lo siguiente:

  • ¿Qué es una búsqueda lineal?
  • Algoritmo de búsqueda lineal
  • Escriba un programa Python para búsqueda lineal usando While Loop
  • Escriba un programa Python para búsqueda lineal usando For Loop
  • Búsqueda lineal en el programa Python usando recursividad

¿Qué es una búsqueda lineal?

En primer lugar, una búsqueda lineal, también conocida como búsqueda secuencial, este método se utiliza para encontrar un elemento dentro de una lista o matriz. Comprueba cada elemento de la lista uno por uno / secuencialmente hasta que se encuentra una coincidencia o se ha buscado en toda la lista.

Algoritmo de búsqueda lineal

Implemente la búsqueda lineal siguiendo los pasos a continuación:

  • Recorre la lista / matriz usando un bucle.
  • En cada iteración, asocie el  target valor con el valor dado de la lista / matriz.
    • Si los valores coinciden, devuelve el índice actual de la lista / matriz.
    • De lo contrario, continúe con el siguiente elemento de matriz / lista.
  • Si no se encuentra ninguna coincidencia, regrese  -1.

Escriba un programa Python para búsqueda lineal usando While Loop

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Después de ejecutar el programa, la salida será:

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Escriba un programa Python para búsqueda lineal usando For Loop

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Después de ejecutar el programa, la salida será:

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Búsqueda lineal en el programa Python usando recursividad

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

Después de ejecutar el programa, la salida será:

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.

 

藤本  結衣

藤本 結衣

1636296420

線形検索のためのPythonプログラム

このチュートリアルでは、Pythonで線形検索プログラムを作成する方法を学習します。

まず、線形検索(シーケンシャル検索とも呼ばれます)は、リストまたは配列内の要素を見つけるために使用されます。一致するものが見つかるか、リスト全体が検索されるまで、リストの各要素を1つずつ/順番にチェックします。

線形探索アルゴリズム

以下の手順に従って線形検索を実装します。

  • ループを使用してリスト/配列をトラバースします。
  • すべての反復で、target 値をリスト/配列の指定された値に関連付け ます。
    • 値が一致する場合は、リスト/配列の現在のインデックスを返します。
    • それ以外の場合は、次の配列/リスト要素に移動します。
  • 一致するものが見つからない場合は、を返し -1ます。

線形検索のためのPythonプログラム

  • whileループを使用した線形検索用のPythonプログラム
  • Forループを使用した線形検索用のPythonプログラム
  • 再帰を使用したPythonプログラムでの線形検索

whileループを使用した線形検索用のPythonプログラム

# python program for linear search using while loop
 
#define list
lst = []
 
#take input list size
num = int(input("Enter size of list :- "))
 
for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)
 
#take input number to be find in list   
x = int(input("Enter number to search in list :- "))
 
i = 0
flag = False
 
while i < len(lst):
    if lst[i] == x:
        flag = True
        break
  
    i = i + 1
  
if flag == 1:
    print('{} was found at index {}.'.format(x, i))
else:
    print('{} was not found.'.format(x))
    

プログラムの実行後、出力は次のようになります。

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Forループを使用した線形検索用のPythonプログラム

# python program for linear search using for loop
 
#define list
lst = []
 
#take input list size
num = int(input("Enter size of list :- "))
 
for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)
 
#take input number to be find in list   
x = int(input("Enter number to search in list :- "))
 
i = 0
flag = False
 
for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break
  
if flag == 1:
    print('{} was found at index {}.'.format(x, i))
else:
    print('{} was not found.'.format(x))
    

プログラムの実行後、出力は次のようになります。

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

再帰を使用したPythonプログラムでの線形検索

# python program for linear search using for loop
 
#define list
lst = []
 
#take input list size
num = int(input("Enter size of list :- "))
 
for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)
 
#take input number to be find in list   
x = int(input("Enter number to search in list :- "))
 
# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 
     
 
res = recLinearSearch(lst, 0, len(lst)-1, x) 
  
if res != -1:
    print('{} was found at index {}.'.format(x, res))
else:
    print('{} was not found.'.format(x))
    

プログラムの実行後、出力は次のようになります。

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.

リンク: https://www.tutsmake.com/linear-search-in-python/

#python