Author Archives: admin

View list USB devices on Linux Ubuntu

On Ubuntu, you may (for one reason or another) wish to view information about all USB devices connected to the system. Unfortunately, Ubuntu doesn’t come with an official GUI USB tool that users can use to view this information efficiently.

Ubuntu list USB devices – Lsusb

The number one way an Ubuntu user can view all connected USB devices is with the lsusb command. This command literally means “list USB,” and it does exactly that — it lists all of your USB devices, their IDs, names, etc.

To get started, open up a terminal window on the Ubuntu desktop. To open up a terminal window on Ubuntu, press Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu and launch it that way.

With the terminal window open and ready to use, execute the lsusb command in the terminal window. Once you enter it, it will print out detailed information about the USB devices connected to the system.

lsusb

In the lsusb output, you’ll see “Bus,” followed by numbers, “Device,” more numbers, “ID,” some hex code (that’s your device’s ID code), and the name of the device. To locate any USB device, find the name at the end.

If you’d like to save this output to a text file for later reading, research, or easier viewing via your favorite text editor, pipe the output to a file using the > command-line modifier.

lsusb > ~/my-usb-devices.txt

At any time, you can view the “my-usb-devices.txt” file in the terminal with the cat command below.

cat ~/my-usb-devices.txt

Ubuntu list USB devices – Dmesg

Another way to view USB devices on Ubuntu is with the dmesg command. The dmesg tool is used primarily to view kernel logs on your system. As USB devices interact with your Ubuntu system, they’re talking to the Ubuntu Linux kernel, which means their information is in these logs.

To use dmesg, you must first open up a terminal window. To do this, press Ctrl + Alt + T on the Ubuntu desktop. Alternatively, search for “Terminal” in the app menu and launch it that way.

When the terminal window is open and ready to use, enter the dmesg command below with sudo privileges. Sadly, the Ubuntu Linux kernel logs cannot be viewed without root access, as dmesg interacts with system-level stuff.

sudo dmesg | grep usb

You’ll see an output of all USB-related information that has interacted with the Ubuntu kernel by entering this command. From here, use the output to find information on your USB devices.

Want to save the dmesg output to a text file for later reading, or to view it better in your favorite GUI text editor? Using the command below, redirect the output to a text file.

sudo dmesg | grep usb > ~/dmesg-usb-info.txt

With it redirected, you can view the text file using the cat command below. Or by opening up “dmesg-usb-info.txt” in your favorite text editor.

cat ~/dmesg-usb-info.txt

Ubuntu list USB devices – Usb-devices

A third way you can view USB device information on the Ubuntu desktop is with the usb-devices command. It is similar to the lsusb tool. However, it is a bit more intricate and provides a lot more information in a much more organized way.

To start, you must have a terminal window open up on the Ubuntu desktop. To open up a terminal window on the desktop, press Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu and launch it.

With the terminal window open and ready to go, execute the usb-devices command. The output is long and prints out in detail, every single USB device connected to Ubuntu in a vertical list.

In this list, you’ll see several columns. T, D, P, S, S, S, C, and I. Each of these letters has tons of information about your devices. For example, to find out the vendor info of a connected USB, go to “P” and read the vendor and product info, etc.

To save the output of the usb-devices command to your Ubuntu system for later reading, or to access via your favorite GUI text editor, you can pipe the output using >.

usb-devices > ~/my-usb-devices-output.txt

At any time, if you want to view the “my-usb-devices-output.txt” file on your computer, execute the cat command below. Alternatively, double-click on “my-usb-devices-output.txt” in the Ubuntu file manager to view it in your favorite text editor.

Sửa lỗi khi yum trên CentOS 8 – Failed to download metadata for repo ‘AppStream’

Khi gõ lệnh YUM trên Cenos8 lỗi như sau

[root@vps~]# yum update
CentOS-8 – AppStream 70 B/s | 38 B 00:00
Error: Failed to download metadata for repo ‘AppStream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist

Bước 1: Đi tới thư mục /etc/yum.repos.d/

[root@vps~]# cd /etc/yum.repos.d/

Bước 2: Thực hiện command sau để điều chỉnh file cấu hình

[root@vps~]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@vps~]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

Bước 3: Thực hiện thao tác yum update

[root@vps~]# yum update -y

Code đếm ngược sử dụng jQuery sau đó lấy kết qủa từ AJAX

Cách seo của mấy đồng chí PTU là bắt người tải dữ liệu về phải truy cập vào 1 trang nào đó để lấy mã giải nén.

Dưới đây mình xin show 1 đoạn code hoạt động tương tự như các trang web lấy mã đó

Mã HTML đơn giản như sau, kèm thư viện jQuery


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Countdown and AJAX</title>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

  <a href="#" id="startCountdown">Lấy mã</a>
  <div id="countdown"></div>
  <div id="ajaxResult"></div>

Code Javascript sử dụng jQuery


<script>
// thời gian đếm ngược
var seconds = 30;

function updateCountdown() {
    $('#countdown').text(seconds);
    if (seconds &gt; 0) {
    seconds--;
    setTimeout(updateCountdown, 1000);
} else {
// Sau 30 giây thì gửi POST AJAX
   $.ajax({
   type: 'POST',
   url: 'link-xử-lý-ajax',
   data: { key: 'value' }, // Thêm dữ liệu bạn muốn gửi
   dataType: 'json',
   success: function(response) {
      // Xử lý dữ liệu jSon trả về
      console.log('AJAX post successful:', response);
      // Hiển thị kết quả ra #ajaxResult 
      $('#ajaxResult').text('AJAX result: ' + JSON.stringify(response));
    },
    error: function(error) {
      $('#ajaxResult').text('AJAX result: Lỗi');
    }
  });
 }
}

// Xử lý khi bấm vào link
$('#startCountdown').on('click', function(event) {
    event.preventDefault(); // Prevent the default link behavior
// Bắt đầu đếm ngược khi người dùng bấm vào link
   updateCountdown();
});
</script>

Cách cài đặt PIP trên CentOS 7

I. Introduction

What is PIP?

PIP is a package management system that simplifies the installation and management of software packages written in Python, such as those found in the Python Package Index (PyPI). PIP isn’t installed by default on CentOS 7, but the installation is pretty straightforward.
Khuyến mãi Black Friday

In this tutorial, AZDIGI will walk you through the steps required to install PIP on CentOS 7 using the package manager and cover some basics on installing and managing Python packages using PIP.

When installing python modules, you should prefer installing the python modules provided by the distribution using yum as they are tested to work properly on CentOS 7. In most cases, you should just use using PIP in a virtual environment. Python Virtual Environments allows you to install Python modules in an isolated location for a specific project rather than being installed system-wide. This way, you don’t have to worry about affecting other Python projects.

So, please continue to see part II for details on how to install and use it.

II. Implementation Guide

You can install PIP on CentOS 7 with the following 2 steps.

Step 1: SSH into your VPS

First, you need to SSH into your VPS as root, if you don’t know how to SSH, you can see the instructions below:

How to log in to Linux VPS via SSH protocol

Step 2: Install PIP and use PIP

1. Enable the EPEL repository

By default, PIP is not available in the CentOS 7 repositories. To install PIP, we need to enable the EPEL repository with the command:

yum install epel-release

2. Install PIP

Once the EPEL repository is enabled, we can install PIP and all its packages with the following command:

yum install python-pip

3. Check PIP

After successful installation, you use the following command to check the version of PIP and Python installed:

pip --version

[root@template ~]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

So my VPS has installed PIP 8.1.2 and Python 2.7.

4. Install development tools

Development tools are required to build Python Modules, you can install them as follows:

yum install python-devel
yum groupinstall 'development tools'
Cách cài PIP trên Centos 7

Cách cài PIP trên Centos 7

5. Manage Python Packages with PIP

First, to be able to see some instructions on how to use PIP, you can use the command:pip help

How to install PIP on Centos 7

Next, we’ll learn a few useful basic PIP commands. With PIP, we can install packages from PyPI, version control, local projects and distribution files. Normally, you would install packages from PyPI.

Install package

For example, if we want to install a package named twisted, we can do that with the following command:

pip install twisted

twist is an asynchronous networking framework written in Python.

Uninstall package

To uninstall a run package, you can use the following command:

pip uninstall twisted

Upgrade package

To upgrade the package, then you can use the command below:

pip install --upgrade

Search for package

To search for packages from PyPI, you can use the following corresponding command:

pip search "twisted"

List installed packages

To list installed packages, you can use the command:

pip list

List outdated packages

To list outdated packages, you can use the following corresponding command:

pip list --outdated

So you can grasp the basic commands to manage Python with PIP already.

III. Summary

I has shown you how to install PIP on a server using Centos 7 with just a few simple command lines. Installing PIP will help you easily manage Python and improve your VPS operation and use. Hopefully, this article will help you to install Let’s Encrypt SSL successfully!

Tạo javascript đếm ngược 10s, 30s, 90s

Code Html

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
  text-align: center;
  font-size: 60px;
  margin-top: 0px;
}
</style>
</head>
<body>

<p id="countdown"></p>

</body>
</html>

Code Javascripts

<script>
var timeleft = 100;
var downloadTimer = setInterval(function(){
  if(timeleft <= 0){
    clearInterval(downloadTimer);
    document.getElementById("countdown").innerHTML = "Finished";
  } else {
    document.getElementById("countdown").innerHTML = timeleft + " seconds remaining";
  }
  timeleft -= 1;
}, 1000);
</script>

Cài đặt Python 3 trên Centos 7 và set làm mặc định

I. Introduction

What is Python?

Python is a powerful, high-level, object-oriented programming language created by Guido van Rossum. It’s easy to learn and is emerging as one of the best introductory programming languages for newbies. Python is completely dynamically typed and uses automatic memory allocation. Python has powerful high-level data structures and a simple yet effective approach to object-oriented programming. Python’s command syntax is a huge plus, its clarity, ease of understanding, and flexible typing make it an ideal language for scripting and application development in various fields on most platforms.

You can learn more about Python through each version and the structure and operating principles here.

II. Implementation Guide

To install Python 3, you can follow the following 3 installation steps.

Step 1: SSH into your VPS

First, you need to SSH into your VPS as root, if you don’t know how to SSH, you can see the instructions below:

How to log in to Linux VPS via SSH protocol

Step 2: Check your Python version

By default Python installed on Centos 7 will be Python 2.7.x version, you use the following command to check the version:

python --version

So now my VPS is using Python version 2.7.

So to upgrade to Python 3 version, go to step 3.

Step 3: Update the Yum management tool

yum -y update                    (Cập nhật yum)
yum -y install yum-utils         (Cài đặt yum utils)
yum -y groupinstall development  (cài đặt các công cụ phát triển CentOS giúp xây dựng và biên dịch phần mềm từ mã nguồn.)

Step 4: Install Python 3
To check and download the latest Python versions, you can visit the homepage here.

Since the standard yum repos don’t have the latest Python release, we will install the IUM (Inline with Upstream Stable) which will have the latest packages by running the following command:

yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Now install Python 3, I will install Python 3.6 with the command:

yum -y install python36u

As shown above, I have successfully installed Python 3

As shown above, I have successfully installed Python 3

As shown above, I have successfully installed Python 3

.

Next, we will install PIP to manage software packages for Python.

yum -y install python36u-pip

Then we will install the Python development packages.

yum -y install python36u-devel

Finally, check the Python version you just installed.

python3.6 --version

Step 5: Set Python 3 as the default

Although we have successfully installed Python 3, the VPS will still use Python version 2.7.5 as default. To change the default version, do the following:

Check the location where Python 3 has just been installed, I previously installed Python 3.6 version, so I will use the following command:

which python3.6

The path will display as follows:

root@template bin]# which python3.6
/usr/bin/python3.6

Add the Alias in bash_profile.

This section means that we will add an Alias configuration so that when calling the python command, the system will load the specified path (here is Python version 3.6). You open and edit the bash_profile file with the command:

vi ~/.bash_profile

Insert the following navigation into the .bash_profile file.

Remember to replace /usr/bin/python3.6 with the path on your VPS.

alias python='/usr/bin/python3.6'

After editing, type :x to Save the configuration.

Reload .bash_profile

source ~/.bash_profile

Recheck the Python version .

python --version

As shown above, the default version has been changed to 3.6.8.

As shown above, the default version has been changed to 3.6.8.

III. Summary

So in this article, I showed you how to install Python 3 and set this new version of Python as the system default. With this upgrade, you will be able to use many new packages from Python because each new package is developed they have conditions attached to the supported version. Hope this article will help you to install it successfully!

If you find the article helpful, please share it widely.