preface
Programmer: “I’m running away, so watch out for the guy who told me the command line was RM -rf /*.”
“rm -rf
“Caused by the bloody case in rookie programmers often appear, the beginning of the line before and after the end of the foundation is not solid.
Without a graphical user interface (GUI), you can’t even start deploying applications.
I think I’m familiar with itLinux
Under theVim
And common commands are required for every programmer.
And even Microsoft embraced Linux Terminal with Windows Terminal. Why don’t you learn?
1. grep
: Searches for keywords in files
$grep "string" [option] fileCopy the code
Use the grep command to find all React keywords in the file:
-i
Option to search a string in a file case insensitive. It matches”REACT
“,”REact
“And”react
“And so on.$ grep -i "REact" file Copy the code
-c (count)
Option to find the number of lines matching a given string/pattern$ grep -c "react" index.js Copy the code
For more options, see the following image:
2. ls
: Lists the files and directories in the current path.
$ ls
Copy the code
Ls Lists the files and directories in the current path.
- If it is a folder, it is blue.
- If it is a file, it is displayed in gray
3. pwd
: Displays the working directory
$ pwd
Copy the code
4. cat
: View the contents of the file
$ cat somefile.js
Copy the code
Cat has three main functions:
- Display the entire file at once.
$ cat filename
Copy the code
- Create a file and populate it with the output from the previous commands
$ cat > filename
Copy the code
You can only create new files, not edit existing files. 3. Merge several files into one file.
$cat file1 file2 > file
Copy the code
In the following example, willindex.js
Make a copy forindex2.js
5. echo
: Output of a string
$ echo "some text"
Copy the code
This is a built-in command used mostly in Shell scripts and batch files to output status text to screens or files.
6. touch
Create a file
$ touch somefile
Copy the code
The touch command is used to create a file without any content.
Notice that in the figure above, we usetouch
Create files andcat
Look inside the file. Due to the newly createdindex2.js
The file is empty, thereforecat
Nothing is returned.
Here are the main differences between Cat and Touch:
cat
Is used to create a file that contains content.touch
Create an empty file without any content.
7. mkdir
: Creates a new empty directory
$ mkdir some-directory
Copy the code
Mkdir Creates a new empty directory in the current path
8.rm
: Deletes a file or directory
$rm [option] someFileCopy the code
The rm command is used to delete a file or directory.
Options:
-i
Ask for confirmation before deleting.-f
Even if the original file property is set to read-only, it can be deleted directly without confirmation.-r
Delete the directory and the following files one by one.
8.1 rmdir
: Deletes an empty directory
$ rmdir some-directory
Copy the code
If there is no content in the directory, this command deletes the directory. Otherwise, XXX not empty is displayed:
9. tail
: View the contents of the document
$tail [option] someFileCopy the code
The last 10 lines of the document are displayed by default
A few common parameters:
-f
, loop read.tail -f notes.log Copy the code
This command displays
notes.log
The last 10 lines of the document. When certain lines are added tonotes.log
A file,tail
The command continues to display these lines. The display continues until you press (Ctrl-C
) key combination stops display.+
, from line XX to the endtail +20 notes.log Copy the code
According to the file
notes.log
From line 20 to the end of the file.-c
, and finally xx line.tail -c 10 notes.log Copy the code
According to the file
notes.log
The last 10 characters of:
The tail command is useful when viewing crash reports or previous history logs:
# tail /var/log/messages Mar 20 12:42:22 hameda1d1c dhclient[4334]: DHCPREQUEST on 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]: 3. Bound to 10.76.199.87 -- renewal in 74685 seconds. Mar 20 12:45:39 hameda1d1c kernel: USB disconnect, device number 2Copy the code
10. find
: Search files
$ find path -name filename
Copy the code
The find command allows you to quickly find files or directories. This is useful when you are working on large projects with hundreds of files and multiple directories.
Find all namesindex.js
The file:
Find a file of the specified type:
$ find . -name "*.js"
Copy the code
11. mv
: Move files
$ mv somefile /to/some/other/path
Copy the code
The mv command moves a file or directory from one location to another.
Support for moving single files, multiple files and directories.
12. wget
: a tool for downloading files
$ wget someurl
Copy the code
Wget is a free package for retrieving files using HTTP, HTTPS, FTP, and FTPS (the most widely used Internet protocol).
This is a non-interactive command line tool, so it can be easily called from scripts, CRON jobs, terminals that do not support X-Windows, etc.
Wget has a number of features that make it easy to retrieve large files or mirror entire Web or FTP sites, including:
- You can use
REST
andRANGE
Resume suspended downloads. - You can use filename wildcards and recursively mirror directories
- NLS based message files for multiple languages
- You can convert absolute links in downloaded documents into relative links so that downloaded documents can be linked locally.
- In most cases
UNIX
Operating system as wellMicrosoft Windows
Running on the - support
HTTP
The agent,cookie
And lastingHTTP
The connection. - Unattended/background operation.
13. tree
: Lists the contents of a directory in a tree
The tree command can help when you need to list the file directory structure when writing a document. The tree command does not exist on some Linux or macOS. You need to install the tree command:
- Make sure it’s installed
Homebrew
, if not, execute:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Copy the code
- The installation
tree
The command
brew install tree
Copy the code
Effect:
(base) XXX $tree. ├ ─ ─ djangoStudy │ ├ ─ ─ just set py │ ├ ─ ─ Settings. Py │ ├ ─ ─ urls. Py │ └ ─ ─ wsgi. Py └ ─ ─ the manage. Py 1 directory, 5 filesCopy the code
14. |
: pipe command
Normally, we can only execute one command on the terminal and then press Enter to execute it. How can we execute multiple commands?
- Execute multiple commands in sequence:
command1; command2; command3;
Simple sequential instructions can pass;
To implement. - Execute multiple commands conditionally:
which command1 && command2 || command3
&&
: If the previous command is successfully executed, the next command is executed, andJavaScript
Consistent with Chinese usage- | | : with
&&
On the contrary, if the command is not executed successfully, the next command is executed.
$?
: Stores the result of the last command
$which git>/dev/null && git --help $echo $?Copy the code
The pipe command can connect the output and input of various commands, making the interlocking operation simple.
A pipe is a communication mechanism commonly used for communication between processes (or over networks via sockets) in the form that the output of each previous process (STdout) is the input of the next process (stDIN)
$instructions 1 | 2 |...Copy the code
Considerations for pipeline commands:
- Can only handle the correct output of the previous instruction, not the error output;
- The latter instruction must be able to receive standard input stream commands to execute.
Example: 1, display detailed information about the contents of the /etc directory
$ ls -l /etc | more
Copy the code
2. Enter a string into a file
$ echo "Hello World" | cat > hello.txt
Copy the code
Postscript & citation
- Here Are 11 Console Commands Every Developer Should Know
- Linux pipe command (PIPE)
- Run the tree command on MacOS
It comes with a powerful Linux command table
❤️ Read three things
If you find this article inspiring, I’d like to invite you to do me three small favors:
- Like, so that more people can see this content (collection does not like, is a rogue -_-)
- Follow the public account “front end persuader” to share original knowledge from time to time.
- Look at other articles as well
- Chrome Devtools Advanced Debugging Guide (New)
- JavaScript Tools (new)
- React Hooks 120 lines of code implement a fully interactive drag-and-upload component
- React Hooks 160 lines of code for dynamic and cool visualizations – leaderboards
You can also get all the posts from my GitHub blog:
Front-end persuasion guide: github.com/roger-hiro/…