Cmder

Comder is a powerful command line tool that eliminates the need to install Git once you use cmder

shortcuts

  1. CTRL +T opens a new label
  2. Alt + D split screen
  3. CTRL + W closes the current label

Add cmder to the right mouse click

Run CMD as an administrator and execute the following command if you need to add cmder.exe to the environment variable

Cmder.exe /REGISTER ALL
Copy the code

Use cmder in vscode

Add these three lines of configuration in settings.json

"git.enabled": true,
"git.path": "D:\\Y\\Software\\cmder\\vendor\\git-for-windows\\cmd\\git.exe",
"terminal.integrated.shell.windows": "D:\\Y\\Software\\cmder\\vendor\\git-for-windows\\bin\\bash.exe",
Copy the code

Cmder common commands

Path to the operation

  1. PWD Displays the current path
  2. Ls Displays the files in the current path
  3. Ls Displays the contents of the corresponding files in the current directory
  4. Ls -l Displays the file and the file update time
  5. CD Changing paths

Add, delete, change and check files

  1. The touch file is created if it does not exist, and updated when the file changed if it does
  2. Echo > *.txt(one arrow will overwrite two arrows will append)
  3. Run the -p command to create a subfolder mkdir -p a/b/c; Create multiple folders using Spaces mkdir a b c
  4. Cp Copy the file cp 1. TXT 21.txtCopy to2.txt; Cp -r a b Recursively copies directory A to directory B
  5. Rm Delete rm 1.txt Delete a file rm -r a Recursively delete all files in folder A
  6. Open uses the default way to open a file
  7. Echo “” > 1.txt Clear a file (overwrite the file with an empty string)
  8. Mv move a file mv1. TXT; You can also use mv to rename a file ‘mv 1.txt 2. TXT //
  9. Cat views all the contents of the file
  10. Head to view the first ten lines of file content (use -n < number of lines > to view the first n lines)
  11. Tail View the last ten lines of the file (same thing)
  12. Less allows you to view file contents one segment at a time
  13. Alt +. Copy the arguments entered last time and rename 1.txt to 2.txt ‘

Operation success or failure

Run the following command to view the code returned by the operation. Return 0 as failure, and return other values as success

echo $?
Copy the code

Using operators

“&&” executes subsequent commands after a command succeeds, and not if it fails

touch 2.txt && echo '222' >> 2.txt && head 2.txt
Copy the code

TXT file. If the file is successfully created, print ‘222’ to the 2.txt file. If the file is successfully created, view the contents in the 2.txt file.

“;” Subsequent commands are executed regardless of whether the first command succeeds

Creating a script File

Execution mode: Two methods are used to execute the script file

/< file > sh< file >Copy the code

The file stores all the commands you need. You can use $1 instead of the file name to pass parameters on the command line

#! /usr/bin/env sh mkdir $1 cd $1 touch index.html touch style.css touch main.js echo -e "<! DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, Initial-scale =1.0"> <title>Document</title> </head> <body> </body> </ HTML >" >> index.htmlCopy the code

#! /usr/bin/env sh shebang The first line indicates the language used

This code implements a bashscript file whose syntax is the bashScript syntax

Add the created command line file to the environment variable and use the command in the next directory just as you would with ls CD.

tool

Too many commands hard to remember how to do?

Install TLDR tool named too Long Didn’t read

yarn global add tldr  
Copy the code

Check the usage of a command using TLDR

tldr ls 
tldr touch
tldr cd
Copy the code

conclusion

The script file

Run the script file using chmod +x

on all systems except Windows

If you want to create a command line file that can be executed without any commands, just add the path to the file to the environment variable.

q

Why can commands on the cli be executed?

The essence of the command line is to put a bunch of command code into an executable file and then add the path to that file to the environment variable. When you enter a file name in the command line, the system looks for a file with the same name in the path of the configuration environment variable and displays an error if the file name is not found.

What happens if two or more paths in an environment variable have files with the same name?

If it is.exe, the.exe will be executed first. If they are both then what will be executed is the files that are higher up in the order of the environment variables.