Article directory
Linux user creation and password setting
Log in to the server through Xshell, su/su -
enter the administrator mode through the command, and enter the password.
Enter the whoami
command and the above results appear, which means that the root mode has been successfully entered.
Step 1: adduser name (create new user)
Step 2: passwd name (set password)
Step 3: userdel name (delete user)
Basic related instructions
ls command
Syntax : ls [options] [directory or file]
Function : For a directory, list all subdirectories and files under the directory; for a file, list the file name and other information.
Common options :
- -a List all files in the directory, including implicit files starting with .
- -d Display the directory as a file instead of the files under it. For example: ls -d specify the directory
- -l List file details.
- -i output file's inode index information
- -k indicates the size of the file in k bytes
- -n use numeric UID, GID instead of name
- -r reverse sort directory
- -t sort by time
- -s output the size of the file after the filename
- -R list files in all subdirectories
- -1 output only one file per line
- -F appends a character to each filename to indicate the type of file
Note: ls -l filename=ll filename
pwd directive
Syntax : pwd
Function : Display the current directory of the user
cd command
Syntax : cd directory name
Function : Change the working directory. Change the current working directory to the specified directory for
example :
- 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
touch command
Syntax : touch [options] File
function : The touch command parameter can change the date and time of the document or directory, including the access time and change time, or create a new file that does not exist.
Common options :
- -a or --time=atime or --time=access or --time=use change access time only
- -c or --no-create do not create any documentation
- -d use the specified datetime instead of the current time
- -f This parameter will be ignored and will not be processed, it is only responsible for solving the compatibility problem of the touch command of the BSD version
- -m or --time=mtime or --time=modify only change the change time
- -r Set the date and time of the specified document or directory to be the same as the date and time of the referenced document or directory
- -t use the specified datetime instead of the current time
mkdir command
Syntax : mkdir [options] dirname
Function : Create a directory named "dirname" in the current directory
Common options :
- -p At this time, if some directories in the path do not yet exist, after adding this option, the system will automatically create those directories that do not exist, that is, multiple directories can be created at one time
For example: mkdir -p test/test1 : create multiple directories recursively
rmdir && rm commands
rmdir is a command corresponding to mkdir. mkdir is to create a directory, and rmdir is to delete the command.
Syntax : rmdir [-p] [dirName]
Function : Delete empty directories
Common options :
- -p When the subdirectory is deleted, if the parent directory also becomes an empty directory, delete it together with the parent directory
The rm command can delete files or directories at the same time
Syntax : rm [-firv] [dirName/dir]
Function : Delete files or directories
Common options :
- -f Even if the file attribute is read-only (ie write-protected), delete it directly
- -i ask for confirmation one by one before deleting
- -r delete the directory and all files under it
File copy, cut related instructions
cp command
Syntax : cp [options] source file or directory target file or directory
function : copy file or directory
Common options :
- -f Force copies of files or directories, regardless of whether the destination file or directory already exists
- -i ask user before overwriting files
- -r Recursive processing, process files in the specified directory together with subdirectories
mv command
Syntax : mv [options] source file or directory target file or directory
function :
- Depending on the type of the second parameter in the mv command (target file or target directory), the mv command renames the file or moves it to a new directory.
- When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (or the source directory name), and it renames the given source file or directory to the given source file or directory. target filename.
- When the second parameter is the name of an existing directory, there can be multiple source file or directory parameters, and the mv command moves the source files specified by each parameter to the target directory.
Common options :
- -f if the target file already exists, overwrite without asking
- -i If the destination file (destination) already exists, it will ask whether to overwrite!
File viewing, display related instructions
cat command
Syntax : cat [option] [file]
Function : View the contents of the target file
Common options :
- -b number non-empty output lines
- -n number all lines of output
- -s do not output multiple blank lines
more command
Syntax : more [options] [files]
Function : similar to cat
common options :
- -n number all lines of output
- q launch more
less command
Syntax : less [parameter] [file]
Function : less is similar to more, but with less you can browse files at will, while more can only move forward, but not backward, and less will not load the entire file before viewing.
Common options :
- -i ignore case when searching
- -N display the line number of each line
- /string function to search down "string"
- ? String up search function for "string"
- n Repeat previous search (related to / or ?)
- N Repeats previous search in reverse (related to / or ?)
- q quit
head directive
Syntax : head [parameter]… [file]…
Function : head is used to display the beginning of the file to the standard output, the default head command prints the first 10 lines of its corresponding file.
Common options :
- -n<number of lines> number of lines to display
tail command
Syntax : tail [required parameter] [optional parameter] [file]
Function : used to display the content at the end of the specified file. If the file is not specified, it will be processed as input information. Commonly viewed log files.
Common options :
- -f loop read
- -n<number of lines> Display the number of lines
time related instructions
date directive
- In terms of display, the user can set the format to be displayed. The format is set to a plus sign followed by several marks. The commonly used marks are listed as follows
- %H : hour (00…23)
- %M : minutes (00…59)
- %S : seconds (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
- in setting time
- date -s //Set the current time, only root privileges can set
- timestamp
- time->timestamp: date +%s
- Timestamp -> time: date -d@1508749502
Cal command
Syntax : cal [parameter][month][year]
Function : used to view time information such as calendar, if there is only one parameter, it means the year (1-9999), if there are two parameters, it means the month and year
common options :
- -3 Display the monthly calendar of the previous month, the current month and the next month of the system
- -j displays the day of the year
- -y displays the calendar for the current year
Find, search related instructions
find command
Syntax : find pathname -options
Function : used to find files in the file tree, and make corresponding processing
common options :
- -name Find files by filename
grep command
Syntax : grep [options] Search string file
Function : Search for strings in the file and print out the lines found
Common options :
- -i ignores differences in case, so case is treated as the same
- -n output line number by the way
- -v reverse selection, i.e. show the line without the 'search string' content
Compression and decompression related instructions
zip/unzip directives
Syntax : zip compressed file. zip directory or file
function : compress a directory or file into zip format
Common options :
- -r Recursive processing, processing all files and subdirectories in the specified directory together
for example:
Compress the test directory: zip test.zip test/*
Unzip it to the tmp directory: unzip test.zip -d /home
tar command
Syntax : tar [-cxtzjvf] File and directory parameters
Function : Pack/unpack, do not open it, directly see the content
Common options :
- -c parameter command to create a compressed file
- -x Unpack a compressed file parameter command!
- -t View the files in the tarfile!
- Does -z also have the gzip attribute? That is, does it need to be compressed with gzip?
- Does -j also have attributes for bzip2? That is, does it need to be compressed with bzip2?
- -v Show files during compression! This is commonly used, but it is not recommended to be used in the background execution process!
- -f Use the file name, please pay attention to the file name immediately after f! Do not add parameters!
- -C Extract to the specified directory
Pack: -czvf
Unpack: -xzvf .
other instructions
man command
Syntax : man [options] Command
function : man manual
Common options :
- -k Search online help by keyword
- num is only found in chapter num
- -a displays all chapters,
bc command
Syntax : bc
Function : The bc command can easily perform floating-point operations
uname -r command
Syntax : uname [options]
Function : uname is used to obtain basic information such as the version of the computer and operating system, the name of the hardware, etc.
Common options :
- -a Detailed output of all information, followed by kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name
file directive
Syntax : file [options] File or directory
function : Identify file types
Common options :
- -c Displays the instruction execution process in detail, which is convenient for debugging or analyzing the execution of the program.
- -z try to interpret the contents of the compressed file
tree directive
Syntax : tree
Function : Expand all files in the current directory
whoami command
Syntax : whoami
Function : Display user's username
which command
Syntax : which [file]
Function : Find file
stat command
Syntax : stat [file]
Function : View the time attribute of the file
shutdown command
Syntax : shutdown [options]
Function : Shutdown
Common options :
- -h Shut down the system immediately after the service is stopped.
- -r restart the system after stopping the service
- -t sec shutdown after sec seconds
- -n is equivalent to -h, shutdown immediately
Important hotkeys
- [Tab] button—with the functions of "command completion" and "file completion"
- [Ctrl]-c key - make the current program "stop"
- [Ctrl]-d key - usually means: "keyboard input ends"; in addition, he can also be used to replace exit