1. Modify the command prompt
Environment variable: PS1:
\u: Current user name
\h: Host Name
\h:fqdn, host name in full format
\w: The base name of the current working directory
\w: The current working directory absolute path
\$: Prompt
\ t: Show time
View command: Echo $PS 1
Modify command: ps1= ' [\u\h \w]\$ '
2. Change the directory:
Cd:change Directory
CD ~ Switch to the current user's home directory
CD ~username switch to the home directory of the specified user
CD-: Repeatedly switch between the previous directory and the current directory
Two unique paths:
.: Current Directory
.. : Top level Directory
3. Command history:
History N: Displays the nearest n, including the current command itself;
History-c: Emptying command history
history-d Offset: Delete the command entry at the specified offset
History-a [/path/to/some_history_file]: Writes the history of a command in the current session to the specified file
Bash invokes commands in the command history list:
!#: Execute the # command in the history of the command
!: Executes the previous command
!string: Executes the last command in the command history that begins with string;
!$: Call the last parameter of the previous command
ESC,.: function Ibid.
Environment variables that change the way the history is recorded:
Histcontrol:
Ignoredups: Ignoring duplicate commands, successive identical commands will be duplicated
Ignorespace: Ignore commands that begin with whitespace characters
Ignoreboth: The above two counterparts enter into force;
4. Shutdown command:
Shutdown-h shut down the machine
-R Restart
-C Cancel shutdown operation
Time format
Now
+m
hh:mm
Reboot: Restart
Halt: Shut down the machine
Poweroff: Shut down the machine
5. Time setting:
Date: Day and Time
date [options] [+format]
%s: Timestamp timing, number of seconds from the beginning of Unix (1970-01-01 00:00:00) to this moment
%F,%d
%T
%Y
%m
%d
%H
%M
%s
Set Time:
Date [MMDDHHMM[[CC]YY][.SS]]
Linux has two clocks: system clock and hardware clock
Hardware clock:
System clock: Linux
Hwclock (Administrator privileges to view)
-S: Subject to Hardware
-W: System-based
6. Directory Management
Mkdir:make Directory
-P: When the parent directory of the specified target directory does not exist, it is created first
-V: Show more information
Rmdir:remove Directory
-P: Delete Directories in the only son directory path
One of the bash features: command line expansion
~: User Home Directory
~username: Specify the user's home directory
{}:
/tmp/{x,y}
/tmp/x,/tmp/y
/tmp/{x,y}/z
/tmp/x/z,/tmp/y/z
7. View commands
ls command: List shorthand
ls [option] [file]
Common options:
-l:long, long format displays detailed property information for a file
Drwxr-xr-x. 2 root root 4096 Feb 09:55 account
First from left: file type
The following 9-bit: permissions, often called mode
R: Reading, read
W: Writing, write
X: Execute, Excute
.: Indicates file has hidden properties
lsattr command to view
Number: Number of times this file has been hard-linked
Master: Owner, owner of File
Group: Group, groups to which the file belongs
4096: File size, Unit is byte
-h:human-readable, automatic unit conversion
The time the file was last modified
Filename
-A: Show All Files
-D: Typically used with-l to display only the directory's own properties
-r:reverse, Reverse display
-r:recursive, recursive display, displaying content in subdirectories
Stat: Displays metadata for a file
Timestamp information:
Access (Atime): Indicates the last time the file was accessed
Modify (Mtime): Indicates when the file content was last modified
Change (CTime): Indicates when the file metadata was last modified
If the mtime changes, CTime must follow the change.
CTime change, mtime not necessarily change.
Touch: Changing the file's Atime and Mtime,ctime is maintained by the file system itself.
Touch [option] ... FILE
If file does not exist, an empty file is created by default
-A: Change atime only
-M: Change Mtime only
-C: Do not create empty files
-T [[CC]YY]MMDDHHMM[.SS]
Cat: Connect and display text file contents
A text file is a stream of data: Stream streaming
-E: Display line terminator
for Linux, the line break is $, and for Windows the line break is two characters: newline character $+ carriage return, so the Linux text file is opened in Windows with TXT in a row without line breaks, But Linux can recognize Windows line breaks.
-N: Show line numbers
TAC: Displaying file contents in reverse order
7.5 echo Command
echo [-nee] [arg ...]
\ n
\ t
\v Vertical Tab
\033[
Single digit: Control font
3#: #是一个数字, 3 indicates control of its foreground color
4#: #是一个数字, 4 indicates control of its background color
To use in combination with one another; separate.
eg
The background is blue and the foreground is green:
Echo-e ' \033[32;44mhello\033[0m '
Bold:
Echo-e ' \033[32;1mhello\033[0m '
M: is a fixed format
\033[0m: The function of the controller ends here
7.6 Other display commands: More,less,head,tail,
8. Aliases: Alias
Alias Alias=command
When aliases have the same name as the command:
Absolute path
\command
Effective Scope: The alias of the command line definition, which takes effect from the current session; ******
Unalias [ALIAS]
-A: Undo all aliases
9. File Management class command:
Copy: CP
Mobile: MV
Delete: RM
Cp:
CP SRC DEST
SRC is a file:
If Dest does not exist: copy src to dest
If dest exists:
If Dest is a file: overwrite
If Dest is a directory: copy src into the dest and keep the original
CP SRC ... DEST
If there is more than one SRC, the dest must be a directory;
CP SRC DEST
SRC is the directory:
You can use the-r option:
Cp-r SRC ... DEST
-P: Copy the symbolic link file itself instead of the destination file it points to
--preserve[=attr_list]
Mode,ownership,timestamps
Mode: Permissions
owership: Belong to the master, genus Group
timestamps: Time stamp
-P: equivalent to--preserve=mode,ownership,timestamps
-A: equivalent to-DR--preserve=all
Archive: Archive
-i:interactive
-f:force
MV Command:
MV SRC ... DEST
-i:interactive
RM command:
-I: Interaction
-F: Force delete
Delete root:
--no-preserve-root
10. Text Processing Class command:
Wc:word Count
-L: Show only the number of rows
-W:
C:
Cut
-D: Specify delimiter
-F: Specify the fields to display
M: Column M
M,n: section m and N columns
M-n: section m to nth column
Sort
Sort [option] FILE ...
-F: Ignore character case
-T: Specify delimiter
-K: Specifies the field to be compared after separation
-N: Sorting by numeric size
-U: Go back after sorting
Uniq: deduplication (only two consecutive rows are considered duplicates)
-D: Show only duplicate rows
-U: Show only rows that have never been duplicated
-C: Count the number of rows that appear
11. Other:
Ntp:network time Protocol (no longer used after REDHAT7)
Synchronizing system time over a network
Ntpdate SERVER
Who: All users logged on to the current system
WHOAMI: User logged on at the current terminal
Which: Displays the full path of the specified command
--skip-alias: Passing Command aliases
Type of file content:
File/path/to/somefile
Command Call Cache:
Hash
-D: Clears cached content for the specified name
-R: Empty cache
This article is from "Snail flash" blog, please be sure to keep this source http://lcj930.blog.51cto.com/1138918/1588497
Linux Basic Command Summary