Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What commands should web developers know?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what commands web developers should know". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Alias

Everyone uses commands that are too long or too complex to fully remember. Fortunately, you can create an alias for the command so that you don't have to remember the entire command.

Aliasshort-command= "your custom and very long command here"

Although there is a problem with creating aliases in this way: aliases are temporary. If you create an alias in this way, it will be available only to the current terminal session.

To keep aliases between sessions, you can save them in the user's shell configuration file. If you use Bash or ZSH, the configuration file may be located in ~ / .bashrc or ~ / .zshrc.

2. Chmod

In Unix and Unix-like operating systems, chmod are commands and system calls that change access to file system objects (files and directories).

According to Wikipedia, this is the definition of the chmod command. We have all encountered situations where the server cannot access a file due to the misconfiguration of file permissions.

The chmod command itself is fairly simple, but granting the correct permissions to files and directories is another matter.

Chmod664 robots.txt chmod 775 public/images

The first example grants read and write permissions to users and groups for the robots.txt file. Read permission for this file has been granted to other users.

The second example grants read, write, and execute permissions to users and groups of the public/images folder. Others are granted read and execute permissions for this folder.

3. Tar

Linux tar stands for tape archiving. It is used to collect multiple files into one archive. Tar is the most widely used command for creating compressed archive files.

Let's start with how to create an archive for a specific directory:

Tar-cvfmy-archive.tar / path/to/directory

This command generates an archive file named my-archive. It contains all the files in the / path/to/ directory created in the current working directory.

Creating an archive is the first part. The second part includes extracting the archive file, because in some cases, we want to use the file in the tar file. You can extract the files to a specific directory with the following command:

Tar-xvfmy-archive.tar-C / home/myfolder/

4. Wget

On unix-like operating systems, the wget command downloads files provided by HTTP, HTTPS, or FTP over the network. By default, it is included in all major Linux distributions.

The easiest way to use wget is to provide a location to download files through HTTP. Download files using wget

Http://website.com/static/images/header.jpg can be done using the following instructions:

Wget http://website.com/static/images/header.jpg

One of the great advantages of wget is that it is not interactive, which means that it can run in the background when the user is not logged in. This allows you to start the search and disconnect from the system, allowing wget to get the job done.

5. Ssh-keygen

The ssh-keygen command is used to generate a new SSH key pair. The public SSH key generated by this command can be used to establish a secure connection in Gitlab or Bitbucket.

Once the SSH key is added to Gitlab or Bitbucket, you will not be prompted for a password every time you try to push the file to a remote branch.

To generate a SSH key pair, use the following command: ssh-keygen-t ed25519

Note that in the example above, we used the ED25519 signature algorithm. Although ED25519 is considered a best practice, you should always do some research on the different signature algorithms available.

It takes up to 10 minutes to generate a SSH key pair and set it correctly in Gitlab or Bitbucket (maybe closer to 3 minutes), but it's totally worth it!

6. Scp

Have you ever had the problem of getting files from a remote server on this machine? For example, getting files uploaded by users leads to some trouble.

Use the scp command to download the file from the command line. Scp is the abbreviation of secure copy. But more importantly, it is a remote secure copy. This command is similar to the cp command that you may already know, but the source or destination is on another system.

The following command copies the file foobar.txt from the remote server to the local directory.

Scpusername@remotehost.com:/path/to/foobar.txt / some/local/directory

However, scp can also be used to copy files from a local directory to a remote server.

Scp / some/local/directory/foobar.txtusername@remotehost.com:/destination/path/

You can do the same for the directory using the-r option, which copies the entire directory recursively.

Tip 1: combine commands

You can run two or more commands at a time. The semicolon (;) operator allows you to do this. You can execute multiple commands in succession, regardless of whether each previous command is successful or not.

Ls-al;pwd

If you want to run the second command only if the first command is successful, separate the command with logic and operator (&).

Mkdirimages & & cd images

If we successfully create that folder, we want to go to the images folder.

Sometimes, you may want to execute the second command only if the first command is unsuccessful. To do this, we use the logical OR operator, that is, |.

Tip 2: output orientation

The standard output device is the screen. But sometimes you don't want to output everything to the screen. In some cases, you may prefer to output the results of certain commands to a file. For example, for logging.

To redirect the output, use >. In the following command, the output of ls-al is redirected to the myfile file instead of to the screen.

Ls-al > myfile

I used ls in this example, but it can actually be any command with some output. To make sure this is valid, you can check the myfile file.

This is the end of catmyfile's "what commands web developers should know". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report