Commonly Used Linux Commands
Learn the basic Linux commands
There is no secret, just practice.
1. cd Change Directory
# Switch to E drive
cd e:/
# Switch to MySQL directory on E drive
cd e:/MySQL
# Switch to /dev directory
mint@DESKTOP-04APDLN:/$ cd /dev
mint@DESKTOP-04APDLN:/dev$
2. cd .. Go back to the previous directory, directly cd to the default directory
# Enter the parent directory
cd ..
# Enter the parent directory of /dev
mint@DESKTOP-04APDLN:/dev$ cd ..
mint@DESKTOP-04APDLN:/$
3. pwd Display the current directory path
pwd
# Display the current directory path
mint@DESKTOP-04APDLN:/usr/games$ pwd
/usr/games
4. clear Clear the screen
# Clear the screen
clear
5. ls List all files in the current directory; ll lists all files in more detail
# List all files in the current directory
ls
# List all files in /usr/include directory
mint@DESKTOP-04APDLN:/usr/include$ ls
X11 gawkapi.h iproute2 sudo_plugin.h
# List all files in the current directory
ll
# List all files in /usr/include directory
@DESKTOP-04APDLN:/usr/include$ ll
total 72
drwxr-xr-x 4 root root 4096 Jul 20 20:49 ./
drwxr-xr-x 12 root root 4096 Feb 15 2025 ../
drwxr-xr-x 2 root root 4096 Apr 9 2024 X11/
-rw-r--r-- 1 root root 41697 Mar 31 2024 gawkapi.h
drwxr-xr-x 2 root root 4096 Feb 15 2025 iproute2/
-rw-r--r-- 1 root root 11959 Jun 25 20:42 sudo_plugin.h
6. touch Create a new file, e.g., touch index.js will create an index.js file in the current directory
# Create a new index.java file
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ touch index.java
7. rm Delete a file; rm index.java means delete the index.java file
# Delete the index.java file in /e/Git directory
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ rm index.java
8. mkdir Create a new directory, i.e., create a new folder
# Create a test directory/folder in /e/Git directory
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ mkdir test
9. rm -r src Delete a folder, i.e., delete the src directory
# Delete the test directory/folder in /e/Git directory
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ rm -r test
As a reminder: rm -rf / will delete all files on the computer. Do not attempt rm -rf / in Linux.
In Linux, everything is a file~
10. mv Move files
# mv the target file to which directory
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ touch index.html
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ mkdir test
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ mv index.html test
11. reset Reinitialize the terminal/Clear the screen
# Similar effect to clear
reset
12. history View command history
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ history
1 git config --global user.name "xxx"
2 git config --list
3 git config --global user.name "xxx"
4 git config --global user.name "xxx"
5 git config --list
6 git init
7 git config --global user.email [email protected]
8 git status
9 ls
10 cd e
11 cd e:/
12 cd e:/MySQL
13 cd ..
14 cd
15 cd
16 cd ..
17 cd
18 pwd
19 touch index.java
20 mkdir test
21 rm -r test
22 touch index.html
23 mkdir test
24 mv index.html test
25 reset
26 history
13. help View help
mint@DESKTOP-04APDLN MINGW64 /e/Git
$ help
GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
job_spec [&] history [-c] [-d offset] [n] or hist>
(( expression )) if COMMANDS; then COMMANDS; [ elif C>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
: kill [-s sigspec | -n signum | -sigs>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-d delim] [-n count] [-O or>
bind [-lpsvPSVX] [-m keymap] [-f file> popd [-n] [+N | -N]
break [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
caller [expr] pwd [-LPW]
case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [->
cd [-L|[-P [-e]] [-@]] [dir] readarray [-n count] [-O origin] [-s>
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] o>
compgen [-abcdefgjksuv] [-o option] [> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM>
compopt [-o|+o option] [-DE] [name ..> set [-abefhkmnptuvxBCHP] [-o option->
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilnrtux] [-p] [name[=v> source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ... | pid > test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [na> times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [argume> true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or ex> typeset [-aAfFgilnrtux] [-p] name[=v>
falseulimit [-SHabcdefiklmnpqrstuvxPT] [l>
fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [-n] [name ...]
for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name > variables - Names and meanings of so>
getopts optstring name [arg] wait [-n] [id ...]
hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
14. exit Exit
exit
15. # Indicates a comment, generally not typed directly
The basic Linux commands are roughly as above.