ls lists the contents of a directory
ls
The -a option means “all”, which lists all files (including hidden files/folders)
As you can see, ls -a lists more content compared to ls. The items starting with a dot (.) are hidden files/folders in the Linux system (any file starting with a dot is automatically hidden). Only with the -a option can you see these hidden files/folders.
The -l option means to display the content in a list (vertical arrangement) format and show more information.
Options in the syntax can be combined, for example, the -a and -l options can be used together.
ls -l -a
Is -la
ls -al
The -h option indicates that file sizes will be displayed in a human-readable format, such as K, M, G.
The -h option must be used together with -l.
cd Change Working Directory
When the Linux terminal (command line) is opened, it defaults to the user’s HOME directory as the current working directory. We can change the current working directory using the cd command.
cd file_path
The cd command does not require options, only parameters, indicating which directory to switch to.
If the cd command is executed without parameters, it returns to the user’s HOME directory.
pwd View Current Working Directory
Using ls to verify the current working directory is actually inappropriate.
We can use the pwd command to view the current working directory.
The pwd command has no options or parameters; just input pwd directly.
Relative and Absolute Paths
Absolute path: a way of describing a path starting from the root directory, which begins with a /.
Relative path: a way of describing a path starting from the current directory, which does not need to start with /.
Special Path Symbols
. represents the current directory, for example, cd ./Desktop means switching to the Desktop directory under the current directory, which is equivalent to cd Desktop.
.. represents the parent directory, for example: cd .. switches to the parent directory, cd ../.. switches to the grandparent directory.
~ represents the HOME directory, for example: cd ~ switches to the HOME directory or cd ~/Desktop switches to the Desktop directory within HOME.
mkdir Create New Directory (Folder)
You can create a new directory (folder) using the mkdir command.
mkdir [-p] Linux_path
The parameter is required, indicating the Linux path, which is the path of the folder to be created, and can be either relative or absolute.
The -p option is optional, indicating that non-existent parent directories will be created automatically, suitable for creating multiple levels of directories.
If you want to create multiple levels of directories at once, you can use the -p option to create the entire chain.
Note: Creating folders requires permission changes; please ensure operations are within the HOME directory, and do not operate outside HOME as it may involve permission issues, which will fail outside HOME.
touch Create File
You can create files using the touch command.
Syntax: touch Linux_path
The touch command has no options; the parameter is required, indicating the file path to be created, which can use relative, absolute, or special path symbols.
cat View File Content
Once you have a file, you can view its content using the cat command.
more View File Content
The more command can also view file content, but unlike cat:
- cat displays all content at once.
- more supports pagination; if the file content is too long, it can be displayed page by page.
Syntax: more Linux_path
It also has no options, only required parameters, indicating the file path to be viewed, which can use relative, absolute, or special path symbols.
The Linux system has a built-in file located at: /etc/services, which can be viewed using more /etc/services.
During viewing, use the spacebar to paginate.
Press q to exit viewing.
cp Copy Files/Folders
The cp command can be used to copy files/folders; cp comes from the English word: copy.
Syntax: cp [-r] parameter1 parameter2
- -r option, optional, used for copying folders, indicating recursion.
- parameter1, Linux path, indicates the file or folder to be copied.
- parameter2, Linux path, indicates where to copy to.
mv Move Files or Folders
The mv command can be used to move files/folders; mv comes from the English word: move.
Syntax: mv parameter1 parameter2
parameter1, Linux path, indicates the file or folder to be moved.
parameter2, Linux path, indicates where to move to; if the target does not exist, it will rename the file, so ensure the target exists.
rm Delete Files/Folders
The rm command can be used to delete files/folders; rm comes from the English word: remove.
Syntax: rm [-r -f] parameter1 parameter2…..
parameterNSimilar to the cp command, the -r option is used to delete folders.
-f indicates force, which deletes without prompting for confirmation. Ordinary users will not see prompts when deleting content, while only root administrator users will see prompts, so ordinary users generally do not use the -f option.
parameter1, parameter2, …, parameterN indicates the paths of the files or folders to be deleted, separated by spaces.
The rm command supports wildcards *, used for fuzzy matching.
The symbol * indicates a wildcard, matching any content (including empty), for example:
test*, matches anything starting with test.
*test, matches anything ending with test.
*test*, matches anything containing test.
You can switch to the root user temporarily by using su and entering the password (default is the same as the ordinary user).
To return to the ordinary user, enter the exit command.
Please do not execute the following commands as the root administrator user: rm -rf / rm -rf /*It is equivalent to formatting the C drive in Windows.
Delete all files in the current folder
rm -rf ./*
which View Where the Executable Files of Commands Are Stored
The Linux commands we learned earlier are actually binary executable files, similar to .exe files in Windows. We can use the which command to see where the executable files of the commands we use are stored.
Syntax: which command_to_find
Example:
which cd
find Command
– Find Files by Name
In a graphical interface, we can easily search for specified files using the system’s search function.
Similarly, in the Linux system, we can use the find command to search for specified files.
Syntax: find starting_path -name “file_name_to_find”
– Find Files by Size
Syntax: find starting_path -size +l-n[kMG]
- + and – indicate greater than and less than.
- n indicates the size number.
- kMG indicates size units, where k (lowercase) indicates kb, M indicates MB, G indicates GB.
grep Command Filter Lines from Files by Keywords
Syntax: grep [-n] keyword file_path
- -n option, optional, indicates to display the line numbers of matching lines in the results.
- parameter, keyword, required, indicates the filtering keyword; if it contains spaces or other special symbols, it is recommended to surround the keyword with “”.
- parameter, file_path, required, indicates the file path to filter content, which can also be used as a content input port.
wc Command for Counting Statistics
You can use the wc command to count the number of lines, words, etc., in a file.
Syntax: wc [-c -m -l -w] file_path
- -c, counts the number of bytes.
- -m, counts the number of characters.
- -l, counts the number of lines.
- -w, counts the number of words.
- parameter, file_path, the file to be counted, which can also be used as a content input port.
Upload
rz
Create Folder
mkdir folder_name
Find File
which file_name
Query Process
ps -ef | grep process_name
Kill Process
kill -9 86379
Run Java Jar Package (still running after closing)
nohup java -jar package_name &
Linux commands (continued) can be found here 👇
https://blog.csdn.net/m0_46702681/article/details/145530841?spm=1001.2014.3001.5501
Strive to meet a better self!!!