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 are the console commands that every developer in Linux should know

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is about console commands that every developer in Linux should know about. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Unix shell is a command-line interpreter or shell that provides a command-line user interface for operating systems like Unix. Shell program is both an interactive command language and a scripting language, and the operating system uses it to control the execution of the system.

By default, every Linux or Mac-based operating system has a command line program installed, usually with the name "Terminal". The command line (CLI) makes it easy to move and rename files, sort data, and browse on your computer.

Before it's too late, here are 11 command-line tips to make your life easier.

1. Grep

$grep "some string" file

The grep command searches for patterns in each file. It also looks for patterns separated by newline characters, and grep prints each line that matches the pattern.

Using the grep command to find all React keywords in a file

The-I option enables us to search for strings in a given file case-sensitive. It matches words like "REACT", "REact" and "react".

$grep-I "REact" file

We can use the-c (count) flag to find the number of lines that match a given string / pattern.

$grep-c "react" index.js

Counting the times the word "react" pops up in a life

This is an interesting and educational cartoon I found on the Internet about grep commands.

Source: Wizard Zines

In addition, the variant programs egrep and fgrep are the same as grep-E and grep-F, respectively. These variants are not recommended, but they are provided for backward compatibility.

There are many things you can do with grep-read the documentation here for further research.

2. Ls

$ls

Ls lists the files and directories in the currently active path. If the pathname is a file, ls displays information about the file based on the requested option. If the pathname is a directory, ls displays information about the file and its subdirectories.

Using the ls command to show all files in the current directory

You may have noticed that the file is gray and the folder is blue. This is to help us distinguish between folders and files.

3. Pwd

$pwd

Printing out the current working directory (pwd)

The pwd command is a command-line utility that prints the current working directory. The output prints the full system path of the current working directory to standard output. By default, the pwd command ignores symbolic links, although you can use the option to display the full physical path to the current directory.

4. Cat

$cat somefile.js

Displaying content of a file with cat

The cat command has three related functions related to text files:

Show them.

Merge copy

Create new ones

The most common use of cat is to read the contents of a file, and cat is usually the most convenient program for this purpose.

In the following example, the standard output of cat is redirected to file2 using the output redirection operator (represented by angle brackets pointing to the right):

$cat somefile > somefile2

Creating files with cat

5. Echo

$echo "some text"

The echo command in Linux is used to display a line of text / string passed as a parameter. Echo is a built-in command that is mainly used in shell scripts and batch files to output status text to a screen or file.

6. Touch

$touch somefile

The touch command is used to create a file that contains nothing. You can use the touch command when the user has no data to store when creating the file.

Creating a new file with touch

Notice how we create the file by touch and how we use cat to look inside the file. Because the newly created index2.js file is empty, cat returns nothing.

The following are the main differences between cat and touch:

Cat- is used to create files that contain content.

Touch-create a file without any content or empty files. Remember that the file created with the touch command is empty. This command is useful when the user does not have data to store when creating the file.

7. Mkdir

$mkdir some-directory

As you might expect, mkdir creates a new empty directory in the current active path. Instead of clicking in a text editor or GUI, use this command to create a new folder.

Creating a new directory with mkdir

Note: notice how we use the previous ls command to monitor the directory.

(1) rm

$rm someFile

Rm stands for remove, and it does exactly what it says. Delete, or in other words, delete the file.

Removing a file with the rm command

By default, the rm command does not delete directories. You need to pass the-rf flag to delete the directory.

$rm-rf some-directory

Removing a directory with the rm command (notice we're passing the flag to remove a directory)

Note: this deletes the directory unconditionally, regardless of whether the directory contains content or not.

(2) root mean square

$rmdir some-directory

If there is no content in the directory, the rmdir command deletes the directory.

Removing an empty directory with rmdir

8. Tail

$tail somefile

The tail command reads the file and outputs the last part of the file ("tail").

Output the last num lines, instead of the default (10)

The tail command is useful when viewing crash reports or previous history logs. This is a useful example when working with file logs.

# tail / var/log/messages Mar 20 12:42:22 hameda1d1c dhclient [4334]: DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x280436dd) Mar 20 12:42:24 hameda1d1c avahi-daemon [2027]: Registering new address record for fe80::4639:c4ff:fe53:4908 on eth0.*. Mar 20 12:42:28 hameda1d1c dhclient [4334]: DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x280436dd) Mar 20 12:42:28 hameda1d1c dhclient [4334]: DHCPACK from 10.76.198.1 (xid=0x280436dd) Mar 20 12:42:30 hameda1d1c avahi-daemon [2027]: Joining mDNS multicast group on interface eth0.IPv4 with address 10.76.199.87. Mar 20 12:42:30 hameda1d1c avahi-daemon [2027]: New relevant interface eth0.IPv4 for mDNS. Mar 20 12:42:30 hameda1d1c avahi-daemon [2027]: Registering new address record for 10.76.199.87 on eth0.IPv4. Mar 20 12:42:30 hameda1d1c NET [4385]: / sbin/dhclient-script: updated / etc/resolv.conf Mar 20 12:42:30 hameda1d1c dhclient [4334]: bound to 10.76.199.87-- renewal in 74685 seconds. Mar 20 12:45:39 hameda1d1c kernel: usb 3-7: USB disconnect, device number 2

9. Wget

$wget someurl

GNU Wget is a free software package that uses HTTP,HTTPS,FTP and FTPS, the most widely used Internet protocol, to retrieve files. This is a non-interactive command line tool, so it can be easily invoked from scripts, CRON jobs, terminals that do not support X-Windows, and so on.

Get to fetch information about a webpage

GNU Wget has many features that make it easy to retrieve large files or mirror an entire Web or FTP site, including:

You can use REST and RANGE to resume aborted downloads

You can use file name wildcards and recursively mirror directories

NLS-based message file, suitable for multiple languages

(optional) convert absolute links in downloaded documents to relative links so that downloaded documents can link to each other locally

Run on most UNIX-like operating systems as well as Microsoft Windows

Support for HTTP proxy

Support for HTTP cookie

Support for persistent HTTP connections

Unattended / background operation

Use the local file timestamp to determine whether the document needs to be re-downloaded when mirrored

GNU Wget is issued under the GNU General Public license.

10. Find

$find path-name filename

Use the find command to quickly find files or directories. This feature is useful when you are working on a large project with hundreds of files and multiple directories.

Finding all files with the name of index.js

Search for specific types of files

Using the find command, you can also search for files of the same type in directories (and their subdirectories). For example, the following command searches all .js files in the current working directory.

$find. -name "* .js"

Finding all .js files in the components directory

11. MV

$mv somefile / to/some/other/path

The mv command moves a file or directory from one location to another. The mv command supports moving a single file, multiple files, and directories.

Moving the some-directory from components to utils directory

Thank you for reading! This is the end of this article on "what console commands every developer should know in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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

Servers

Wechat

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

12
Report