Home  >  Article  >  Computer Tutorials  >  Take stock of some practical Linux tips

Take stock of some practical Linux tips

WBOY
WBOYforward
2024-03-12 13:49:021167browse

Take stock of some practical Linux tips

Linux is a powerful operating system with many useful commands and tips to help you use it more efficiently.

1. Check the file check value

During the file copying or transmission process, the file may be damaged or modified. In this case, the check value can be used for verification.

Usually, we need to use some interface programs provided by other teams in our work. Whenever the running results of these programs are not as expected, we will compare the md5 check values ​​of both parties to confirm the consistency of the data.

There are many ways to generate the check value of a file. Commonly used ones include md5sum check, crc check, sum check, etc.

The

commands are:

md5sum file_name
cksum file_name
sum 算法参数 file_name

For example:

Let’s take a test.txt file as an example:

  • md5sum verification
md5sum test.txt
  • crccheck
cksum test.txt
  • sum verification

There are two algorithms for sum verification, which we can configure through parameters:

-r: Indicates using the system v algorithm. -s: Indicates using the BSD algorithm.

When we do not configure it, the system v algorithm is used by default.

sum -r test.txt
sum -s test.txt

2. Find the file location

(1)locate

Everyone is usually accustomed to using find to find files, but I think sometimes locate is faster, so I usually use locate first.

locate is different from find: find searches on the hard disk, while locate only searches in the /var/lib/slocate database. The speed of locate is faster than find. It does not really search, but checks the database.

Some systems may not have locate and you need to install it yourself. For example, Ubuntu can be installed by entering the following command:

apt-get update
apt-get install mlocate

locateThe command to find files is very simple:

lcoate file_name

(2)find

The find command can search by name, type, owner, size, etc.

Basic syntax for searching files:

find path -option file_name

If you use the name to search for the stdio.h file:

find / -name stdio.h

3. Command line editing skills

We mistakenly entered some relatively long content into the terminal:

it@weijishu:~$ dsfdsfdddddddddddddddddddddddddddddddddddfsgadgdsgasdgsdhfdkshfkjdshflksdhfkldshfkj

How to delete it faster? Frantically pressing the backspace key certainly does the trick. But there is a faster way:

Enter the shortcut key ctrl u to delete all the content in front of the cursor. In addition, there are several practical and commonly used shortcut keys as follows:

  • ctrl k: Delete all content behind the cursor.
  • ctrl a: Move the cursor to the beginning.
  • ctrl e: Move the cursor to the end.

In addition, the command line also has many practical and uncommon shortcuts. Interested friends can learn them by themselves.

4. Check the pid of a process

Order:

pidof process_name

5. Check the running status of certain processes

The top command can check some information about the process, but there are too many processes running in the system, which is not conducive to us checking the running status of some processes

At this time we can check the running status of the specified process through the following command, for example:

To view the status of the kcalc process, command:

top -p `pidof kcalc`

This is much simpler.

Notice:

The "` sign" here is not a single quotation mark! ! !

This symbol is to the left of the exclamation point! key on the keyboard.

View multiple processes, such as:

top -p `pidof kcalc` -p `pidof test_x86`

In addition to the above tips, there are also practical tips such as the following. They are briefly listed here and will be introduced in detail later.

  • View command history: You can use the history command to view recently used commands, and you can also use pipes and grep commands to filter commands starting with a certain string.
  • File synchronization: Use the rsync command to synchronize files between local and remote. It is more powerful and flexible than the cp or scp command.
  • View the contents of the file: Use the less or tail command to view the contents of the file. less can page forward, and tail can view the last few lines of the file.
  • View processes: Use the ps command to view the currently running processes. You can use the grep command to filter out processes starting with a certain string.
  • Port forwarding: Use the ssh command to do port forwarding, mapping a port on the remote host to a local port.
  • Data backup: You can use the tar command to package a directory or file into a tar package, and then use the cpio or dd command to back up the tar package to another location.
  • System monitoring: Use the top or htop command to view the system's CPU, memory, network, etc. usage in real time.
  • Network test: Use the ping and traceroute commands to test network connectivity and routing paths.
  • Text processing: Use awk, sed, grep and other commands to process text data and perform data filtering, replacement, sorting and other operations.
  • The above is the detailed content of Take stock of some practical Linux tips. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete