Linux | Red Hat Certified | IT Technology | Operations Engineer
👇 Join our technical exchange QQ group with the note [Public Account] for faster access
1. ls Command
Syntax: ls [options] [directory or file]
Function: For directories, this command lists all subdirectories and files within that directory. For files, it lists the file names along with other information.
Common Options:
-a List all files in the directory, including hidden files that start with a dot. -d Display the directory as a file, rather than showing its contents. For example: ls -d specified_directory -i Output the inode index information of the file. For example, ls -ai specified_file -k Display the file size in kilobytes. For example, ls -alk specified_file -l List detailed information about the file. -n Use numeric UID and GID instead of names. (Introduction to UID, GID) -F Append a character to each file name to indicate the file type: "*" indicates an executable file; "/" indicates a directory; "@" indicates a symbolic link; "|" indicates FIFOs; "=" indicates sockets. (Directory type identification) -r Reverse sort the directory. -t Sort by time. -s Output the file size after the file name. (Size sorting, how to find the largest file in a directory) -R List files in all subdirectories. (Recursive) -1 Output one file per line
2. pwd Command
Syntax: pwd
Function: Display the current directory of the user
3. cd Command
In the Linux system, files and directories on the disk form a directory tree, where each node is a directory or file.
Syntax::cd directory_name
Function: Change the working directory. Change the current working directory to the specified directory.
Examples:
cd .. : Return to the parent directory cd /home/litao/linux/ : Absolute path cd ../day02/ : Relative path cd ~ : Enter the user's home directory cd - : Return to the most recently accessed directory
4. touch Command
Syntax: touch [options]… file…
Function: The touch command can change the date and time of a document or directory, including access time and modification time, or create a new file if it does not exist.
Common Options:
-a or --time=atime or --time=access or --time=use only change the access time. -c or --no-create do not create any documents. -d use the specified date and time instead of the current time. -f this option is ignored and only serves to resolve compatibility issues with the BSD version of the touch command. -m or --time=mtime or --time=modify only change the modification time. -r set the date and time of the specified document or directory to be the same as that of the reference document or directory. -t use the specified date and time instead of the current time
5. mkdir Command (Important):
Syntax: mkdir [options] dirname…
Function: Create a directory named “dirname” in the current directory
Common Options:
-p, --parents can be a path name. If some directories in the path do not exist, adding this option will automatically create them.
It can create multiple directories at once, including those that do not exist;
6. rmdir Command && rm Command (Important)
rmdir is a command corresponding to mkdir. mkdir creates directories, while rmdir deletes them.
Syntax: rmdir [-p] [dirName]
Applicable to: All users with permissions to operate in the current directory
Function: Delete empty directories
Common Options:
-p when a subdirectory is deleted, if the parent directory also becomes empty, it will be deleted as well.
The rm command can delete files or directories simultaneously
Syntax: rm [-f -i -r -v] [dirName/dir]
Applicable to: All users
Function: Delete files or directories
Common Options:
-f forcefully delete files or directories, regardless of whether the file attributes are read-only (i.e., write-protected) -i ask for confirmation before deleting each file -r delete directories and all files within them
7. man Command (Important)
There are many parameters for Linux commands, and we cannot remember them all. We can get help by viewing the online manual. The command to access the Linux manual page is
man Syntax: man [options] command
Common Options:
-k search online help by keyword num only search in chapter num -a display all chapters, for example, man printf defaults to searching from the first chapter and stops when found, but with the -a option, it continues to search until all chapters are searched after pressing q to exit.
Explanation of the manual divided into 8 chapters
1 is for ordinary commands
2 is for system calls, such as open, write, etc.(With this, you can easily find out what headers are needed to call this function)
3 is for library functions, such as printf, fread 4 is for special files, which are various device files under /dev
5 is for file formats, for example, passwd, which explains the meaning of each field in this file
6 is reserved for games, defined by each game
7 is for attachments and some variables, such as global variables like environ are explained here
8 is for system management commands, which can only be used by root, such as ifconfig
8. cp Command (Important)
Syntax: cp [options] source_file_or_directory target_file_or_directory
Function: Copy files or directories
Description: The cp command is used to copy files or directories. If two or more files or directories are specified and the last destination is an existing directory, it will copy all specified files or directories into that directory. If multiple files or directories are specified and the last destination is not an existing directory, an error message will occur.
Common Options:
-f or --force forcefully copy files or directories, regardless of whether the destination file or directory already exists -i or --interactive ask the user before overwriting files -r recursively process, handling files and subdirectories within the specified directory. If the source file or directory is not a directory or symbolic link, it is treated as a regular file -R or --recursive recursively process, handling files and subdirectories within the specified directory
9. mv Command (Important)
The mv command is short for move, and it can be used to move files or rename files (move (rename) files). It is a commonly used command in the Linux system, often used for backing up files or directories.
Syntax: mv [options] source_file_or_directory target_file_or_directory
Function:
Depending on the type of the second parameter in the mv command (whether it is a target file or target directory), the mv command will rename the file or move it to a new directory.
When the second parameter is a file, the mv command completes the renaming of the file. At this time, the source file can only have one (it can also be the source directory name), and it will rename the given source file or directory to the specified target file name.
When the second parameter is an existing directory name, the source file or directory parameters can have multiple, and the mv command will move all specified source files to the target directory.
Common Options:
-f : force means if the target file already exists, it will not ask and will directly overwrite -i : if the target file (destination) already exists, it will ask whether to overwrite
10. cat Command
Syntax: cat [options] [file]
Function: View the contents of the target file
Common Options:
-b number non-empty output lines -n number all output lines -s do not output multiple empty lines
11. more Command
Syntax: more [options] [file]
Function: The more command functions similarly to cat
Common Options:
-n number all output lines q exit more
12. less Command (Important)
The less tool is also a tool for paginating the display of files or other outputs, and it is considered the standard tool for viewing file contents in Linux, with extremely powerful functionality.
The usage of less is more flexible than more. When using more, we cannot scroll back, we can only look forward.
However, when using less, we can use keys like [pageup] [pagedown] to scroll back and forth, making it easier to view the contents of a file!
In addition, less has more search functions, allowing us to search downwards and upwards.
Syntax: less [options] file
Function:
less is similar to more, but using less allows for free browsing of the file, while more can only move forward and cannot move backward, and less does not load the entire file before viewing.
Common Options:
-i ignore case when searching -N display line numbers /string: search down for "string" ?string: search up for "string" n: repeat the previous search (related to / or ?) N: reverse repeat the previous search (related to / or ?) q: quit
13. head Command
head and tail are as straightforward as their names suggest; they are used to display a certain number of text blocks from the beginning or end. head is used to display the beginning of a file to standard output, while tail is used to view the end of a file.
Syntax: head [options]… [file]…
Function:
head is used to display the beginning of a file to standard output, and by default, the head command prints the first 10 lines of the corresponding file.
Common Options:
-n<number> number of lines to display
14. tail Command
tail command writes the file to standard output starting from a specified point. Using the -f option with the tail command allows for easy viewing of changing log files; tail -f filename will display the latest content in filename on the screen and refresh to show the latest file content.
Syntax: tail [required parameters] [optional parameters] [file]
Function: Used to display the end content of a specified file; if no file is specified, it processes input information. Commonly used to view log files.
Common Options:
-f loop read -n<number> number of lines
15. Time-related Commands
date display
date display time in specified format: date +%Y:%m:%d
date usage: date [OPTION]… [+FORMAT]
1. In terms of display, users can set the desired display format, which is set as a plus sign followed by several markers, with the following commonly used marker list:
%H : hour (00...23) %M : minute (00...59) %S : second (00...61) %X : equivalent to %H:%M:%S %d : day (01...31) %m : month (01...12) %Y : full year (0000...9999) %F : equivalent to %Y-%m-%d
2. In terms of setting time
date -s // set the current time, only root permissions can set it, others can only view. date -s 20080523 // set to 20080523, this will set the specific time to 00:00:00 date -s 01:01:01 // set specific time, will not change the date date -s "01:01:01 2008-05-23" // this can set all time date -s "01:01:01 20080523" // this can set all time date -s "2008-05-23 01:01:01" // this can set all time date -s "20080523 01:01:01" // this can set all time
3. Timestamps
Time -> Timestamp: date +%s
Timestamp -> Time: date -d@1508749502
Unix timestamp (in English: Unix epoch, Unix time, POSIX time, or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds
16. cal Command
The cal command can be used to display the Gregorian (solar) calendar. The Gregorian calendar is the internationally used calendar, also known as the Gregorian calendar, commonly referred to as the solar calendar. The “solar calendar” is named because it is based on the Earth’s orbit around the sun for one year, and is used by Western countries, hence also called the Western calendar.
Command Format: cal [options] [month] [year]
Function: Used to view calendar and other time information. If only one parameter is provided, it indicates the year (1-9999). If there are two parameters, it indicates the month and year
Common Options:
-3 display the calendar for the previous month, current month, and next month -j display the day of the year (the day of the year calculated from January 1, default displays the current month in the day of the year) -y display the calendar for the current year
17. find Command: (Very Important) -name
The find command in Linux searches for files in the directory structure and performs specified operations.
The find command in Linux provides a considerable number of search conditions and is very powerful. Due to its powerful functionality, it has many options, most of which are worth our time to understand.
Even if the system contains a network file system (NFS), the find command is still effective in that file system as long as you have the appropriate permissions.
When running a very resource-intensive find command, many people tend to run it in the background because traversing a large file system can take a long time (referring to file systems over 30GB).
Syntax: find pathname -options
Function: Used to find files in the file tree and perform corresponding processing (may access the disk)
Common Options:
-name find files by file name
For course inquiries, add: HCIE666CCIE
↑ Or scan the QR code above ↑
What technical points and content would you like to see?
You can leave a message below to let us know!