There are indeed many commands in Linux, so I have summarized some of them for easier reference in the future. Without further ado, here are the Linux commands I use most often.
1. cd command
This is a very basic command that everyone frequently needs to use. It is used to switch the current directory. Its parameter is the path of the directory to switch to, which can be an absolute path or a relative path. For example:
-
cd /root/Documents # Switch to the directory /root/Documents
-
cd ./path # Switch to the path directory under the current directory, where “.” indicates the current directory
-
cd ../path # Switch to the path directory in the upper directory, where “..” indicates the parent directory
2. ls command
This is a very useful command for viewing files and directories, meaning list. It has many parameters, and here are some of the ones I commonly use:
-
-l: List in long format, including file attributes and permission data, etc.
-
-a: List all files, including hidden files (those starting with a dot) (commonly used)
-
-d: Only list the directory itself, not the files within the directory
-
-h: Display file sizes in a more readable format (GB, kB, etc.)
-
-R: List contents of subdirectories as well (recursively), meaning all files under that directory will be displayed
Note: These parameters can also be combined. Here are two examples:
-
ls -l # List the data files and directories in the current directory in long format
-
ls -lR # List all files in the current directory in long format
3. grep command
This command is commonly used to analyze a line of information. If it contains the information we need, that line will be displayed. This command is usually used with pipe commands to filter or process the output of some commands, etc. Its simple syntax is:
-
grep [-acinv] [–color=auto] ‘search string’ filename
Its common parameters are as follows:
-
-a: Search data in binary files as if they were text files
-
-c: Count the number of occurrences of ‘search string’
-
-i: Ignore case distinctions, treating uppercase and lowercase as the same
-
-v: Invert selection, displaying lines that do not contain the ‘search string’
-
# For example:
-
# Extract lines from the file /etc/man.config that contain MANPATH, highlighting the found keywords
-
grep –color=auto ‘MANPATH’ /etc/man.config
-
# Output lines from ls -l that contain the letter file (case insensitive)
-
ls -l | grep -i file
4. find command
find is a very powerful command based on search functionality. Relatively speaking, its use is also relatively complex, with many parameters, so I will categorize them here. Its basic syntax is as follows:
-
find [PATH] [option] [action]
-
-
# Parameters related to time:
-
-mtime n: n is a number, meaning files modified within