git basic commands
1. ls use
"Ls" can view those files in the current directory
Create a new "git-demo-1" directory on the desktop, and create files "css, images, index.html, js" in the directory
$cd ~/Desktop
$cd git-demo-1
$ls
After typing "ls" in the terminal, I get the following result
css images index.html js
"ls -a" can view all files in the current directory including hidden files
Type "ls -a" in the terminal to get the following results
. .DS_Store css index.html
.. .git images js
"ls -l" can view the permissions and last modification time of all files in the current directory
Type "ls -l" in the terminal to get the following results
total 0
drwxr-xr-x 3 tianqiang staff 96 5 22 17:18 css
drwxr-xr-x 3 tianqiang staff 96 5 22 17:49 images
-rw-r--r-- 1 tianqiang staff 0 5 22 17:09 index.html
drwxr-xr-x 3 tianqiang staff 96 5 22 17:25 js
"ls -al" can view the permissions and last modification time of all files including hidden files
Type "ls -al" in the terminal to get the following results
total 16
drwxr-xr-x 8 tianqiang staff 256 5 22 17:58 .
drwx------@ 10 tianqiang staff 320 5 23 11:05 ..
-rw-r--r--@ 1 tianqiang staff 6148 5 22 17:48 .DS_Store
drwxr-xr-x 15 tianqiang staff 480 5 22 17:58 .git
drwxr-xr-x 3 tianqiang staff 96 5 22 17:18 css
drwxr-xr-x 3 tianqiang staff 96 5 22 17:49 images
-rw-r--r-- 1 tianqiang staff 0 5 22 17:09 index.html
drwxr-xr-x 3 tianqiang staff 96 5 22 17:25 js
2. cat application
"cat filename" shows the contents of the file
Create a new cat-demo1.txt file on the desktop, enter the content "hello" in it, and enter cat cat-demo1.txt in the terminal to get the following results
cd ~/Desktop
cat cat-demo1.txt
hello
"cat> filename" creates a new file
Enter cat> cat-demo2.txt << EOF in the terminal, create a new cat-demo2.txt file, and enter "world"
cat > cat-demo2.txt << EOF
> world
> EOF
"cat file1 file2 >>file3" assigns the contents of file1 and file2 to file3
Create a new file "cat-demo3.txt" in the terminal, and assign the contents of demo1 and demo2 to demo3
cd ~/Desktop
touch cat-demo3.txt
cat cat-demo1.txt cat-demo2.txt >> cat-demo3.txt
hello world
3. mv use
"mv" to move files or rename files
Rename "cat-demo3.txt" to "mv-demo.txt"
cd ~/Desktop
mv cat-demo3.txt mv-demo.txt
Create a new "mv-demo" directory and move "mov-demo.txt" to "mv-demo"
mkdir mov-demo
mv mv-demo.txt mv-demo
cd mv-demo
ls
mv-demo.txt
4. touch application
"touch" modify the time of the file or directory, if the file does not exist, a new file will be created
File modification time
cd mv-demo
touch mv-demo.txt
ls -l
total 8
-rw-r--r--@ 1 tianqiang staff 17 5 23 14:50 mv-demo.txt
touch mv-demo.txt
total 8
-rw-r--r--@ 1 tianqiang staff 17 5 23 14:53 mv-demo.txt
Create a file
touch touch-demo
ls -l
total 8
-rw-r--r--@ 1 tianqiang staff 17 5 23 14:53 mv-demo.txt
-rw-r--r-- 1 tianqiang staff 0 5 23 14:55 touch-demo
5. common built-in commands
operating | command |
---|---|
Enter the catalog | cd |
Show current directory | pwd |
Create a directory | mkdir directory name |
Create a directory | mkdir -p directory path |
who am I | whoami |
- | - |
View path | ls path |
View path | ls -a path |
View path | ls -l path |
View path | ls -al path |
- | - |
Create a file | echo '1'> file path |
Force file creation | echo '1' >! File path |
Append file content | echo '1' >> file path |
Create a file | touch file name |
Change file update time | touch file name |
- | - |
Copy files | cp source path target path |
Copy directory | cp -r source path target path |
- | - |
Mobile node | mv source path target path |
- | - |
Delete Files | rm file path |
Force deletion of files | rm -f file path |
Delete directory | rm -r directory path |
Forcibly delete a directory | rm -rf directory path |
- | - |
View directory structure | tree Let Windows support tree |
Establish soft link | ln -s real file link |
- | - |
download file | curl -L www.baidu.com > |
Copy webpage | wget -p -H -e robots=off |
Disk usage | df -kh |
Current directory size | du -sh. |
Each file size | du -h |
6. alias abbreviation
Use alias to abbreviate commands, which can make daily operations more convenient and faster
~/.bashrc
alias la='ls -a'
alias ll='ls -l'
alias gst='git status -sb'
alias ga='git add'
alias ga.='git add .'
alias gc='git commit'
alias gc.='git commit .'
alias open='start'
source ~/.bashrc
7. Use of explainshell.com website
If you don t have an order, you can check it out on this website