Linux Learning command "1"

Source: Internet
Author: User
Tags clear screen parent directory

Linux学习之命令【1】

One • Command overview
?????? 1. Basic Simple commands
??????? ? 1.0 pwd
1.1 Echo
????????? 1.2 Date
????????? 1.3 cal
1.4 CD
????????? 1.4 ls
????????? 1.5 tab
1.6 Clear
1.7 Help Commands
??????? 1.7.1 Help
????????? 1.7..2 Mans
? ??? 2. User Information view Edit command
????????? 2.1 Who??
????????? 2.2 passwd
????????? 2.3 Useradd
????????? 2.4 Userdel
????????? 2.5 su
????????? 2.6 sudo
????? 3. File Operation commands
????????? 3.1 Touch
3.2 Cat
???????? 3.3 cp
???????? 3.4 mv
???????? 3.5 rm??
????? 4. System Status Management commands
???????? 4.1 Poweroff
????? ? 4.2 Init
?????? 4.3 shutdown
?????? Two-command explanation
1. Basic Simple commands
1.0 PWD Displays the absolute path of the current working directory

Description: The command does not take any options and parameters. This command lets you know that the current work is under that directory.
Using the example

1.1 Echo
(1) Display the parameters on the command line to the standard output (that is, the screen). The output string is separated by a white space character, and a newline number is added at the end
As follows:

(2) Options:
-E Hold (default) does not support \ Explain function
-N Not wrap line
For example:

-E with Enable \
(3) Display variables
echo "$VAR _name" variable is replaced with weak reference
Echo ' $VAR _name ' variable does not replace, strong reference

Enable command option-E, if the following characters appear in the string, the
Do not treat it as a general text output
\a issued a warning sound
\b Backspace key
\c Finally, no newline symbol is added.
\ n Wraps and the cursor moves to the beginning of the line
\ r Enter, that is, the cursor moves to the beginning of the line, but does not wrap
\ t Insert tab
\ insert \ Character
\0NNN insert ASCII character represented by NNN (octal)
Echo-e ' \033[43;31;5mmagedu\033[0m '
\XHH Insert the ASCII character represented by the HH (hex)

1.2 Date
Show date and time

Options:
+%y year
+%m Month
+%d Day
When +%h
+%m min
+%s sec
+%w Week
+%a Day of the week (Sunday. Saturday)
+%f year-month-day
+%t hours: minutes: seconds

    date +%Y%m%d???????? //显示现在天年月日

Date +%y%m%d--date= "+1 Day"? Date of day after display
Date +%y%m%d--date= "-1 day"? Show date of day before
Date +%y%m%d--date= "-1 month"? Show dates for last January
Date +%y%m%d--date= "+1 month"? Show dates for next January
Date +%y%m%d--date= "-1 year"? Show the date of the previous year
Date +%y%m%d--date= "+1 year"? Show the date of the next year
1.3 cal displays calendars for any one year or any one month in A.D. 1-9,999.

用法示例: (1)不带参数      $cal            --显示当前月份和日历 (2)带一个参数      $cal 10         --列出公元10年的日历 (3)带两个参数      $cal 9 2017     --显示2017年九月份的日历 (4) 拓展

-1. Show Calendar for one months
-3. Display system One months, current month, next one months calendar
-S? show Sunday for the first day of one weeks, the default format
Show Monday the first day of one weeks
? ? ? -j?? The day of the year that is displayed in the current year (the date is calculated from January 1, and the number of days in the year is displayed by default)
Y?? Display the calendar for the current year

1.4 CD Change Working directory
Command format: CD path name (dirname)
Using the example
Cd/app switch the current working directory to the app directory
Cd????? Enter the user's home directory;
Cd? ~? Enter the user's home directory;
Cd? -? Returns the directory where the directory was before it entered;

Cd?..? Return to the parent directory (if the current directory is "/", then "/"; "..." after execution) The meaning of the parent directory);
Cd.. /..? Return to the top level two directory;

1.5 ls used to display a list of file directories

Command format
$ls (options) (parameters)
Options
-a,–all lists all files under the directory, including the. The implied file at the beginning
-A with-a, but not listed "." (represents the current directory) and ".." (Represents the parent directory of the current directory).
-C mate-lt: Sort by CTime and display CTime (time of last change of file status) mate?-L: Show CTime? But sort by name otherwise: based on? ctime? sort
-c list items from top to bottom of each column
–color[=when] Controls whether to use color-resolved files. When can be ' never ', ' always ' or ' auto ' one of them
-d,–directory Displays the directory as a file, rather than displaying the file below it.
-F does not sort the output files, the-au option is active, the-LST option is invalid
-g similar to-l, but does not list owner
-h,–human-readable list file sizes in an easy-to-understand format (e.g. 1K 234M 2G)
–si is similar to-H, but the file size takes 1000 times instead of 1024
-h,–dereference-command-line the true destination indicated by using symbolic links in the command column
-i,–inode Prints the inode number of each file
-K is the –block-size=1k that represents the size of the file in K-byte form.
-l lists the permissions, owner, file size, and so on, in addition to the file name.
-l,–dereference when displaying the file information for a symbolic link, displays the object indicated by the symbolic link instead of the information of the symbolic link itself
-m all items are separated by commas and fill the entire row width
-r,–reverse in reverse order.
-r,–recursive listing all subdirectory tiers at the same time
-s,–size to list the size of all files in block size
-s sort by file size
-T sorted by file modification time
-U mate-lt: Show access time and sort by access time
Mate-L: Show access time but sort by name
Otherwise: Sort by access time
-U does not sort, lists items according to the original order of the file system
-X list items line by row instead of columns by column
Usage examples
$ ls-a Displays all directories and files in the directory (including hidden directories and files)

$ ls-l (Small letter) long format lists directories and files in the current directory (excluding hidden directories and file files)

$ls-1 (number 1) displays the current directory and file vertically

$ls-M level displays the current directory and file

$ls-LD Displays details about the specified current directory.

$ls-S sorted by file size Descending

1.6tab Command Completion/path completion
(1) Command completion
External command: The path defined by bash according to the PATH environment variable, from left to
Right in each path to search for a file named after the given command name, the first command found, that is, the command to execute
The user-given string has only one unique command, which complements the entire
Otherwise, TAB again
(2) Path completion
Use the user-given string as the beginning of the path and specify the parent directory
Searches for the file name that begins with the specified string. If only: the direct complement
Otherwise: tab to the list again
1.7 Clear Clear Screen
Function: Clears the information on the screen. After you clear the screen, the prompt moves to the upper-left corner of the screen.
1.8 Help Commands
1.8.1 Help
Features: Can view help for all shell built-in commands
Format: Help [options] [parameters]
Usage examples
(1) Without any parameters, displays the use of the help command, listing the built-in list of shell commands

(2) with parameters
$HELP CD View CD command usage
1.2.2 Mans
Features: formatting and displaying an online Help man page for a command
Format "Options" command name
Using the example
$man ls Displays the LS command help information
2. User Information view Edit command
2.1 Who lists the users being used, the terminal name used and the time it was registered to the system.
Example:

2.2 passwd
change user Password
2.3 Useradd Create a new user
Command format: Useradd "Options" user name
Options:
-c< Remarks: Add notes text. Note text will be saved in passwd's remarks field;-d< login directory;: Specify the start directory of user login;
-D: Change the preset value;
-e< validity period;: Specify the expiry date of the account;
-f< buffer days;: Specify how many days after the password expires to close the account;
-g< Group;: Specify the group to which the user belongs;
-g< Group;: Specifies the additional group to which the user belongs;
-M: Automatically set up the user's log in directory;
-M: Do not automatically set up the user's log in directory;
-N: Cancels the creation of a group named after the user name;
-R: Establish the system account number;
-s<shell&gt: Specifies the shell used by the user when logging in;
-u<uid>: Specifies the user ID.

Usage examples:
$Useradd-U 520 liubei Create a new user and specify a user ID of 520
2.4 Userdel Delete a user
Command format: Userdel "Options" user name
Options:
-F: Force the deletion of the user, even if the user is currently logged in;
-r: Deletes all files associated with the user while deleting the user.
Userdel command is very simple, for example, we now have a user linuxde, whose home directory is in the/var directory, now we delete this user:
Userdel Liubei Delete User Liubei, but do not delete their home directory and files;
Userdel-r Liubei Delete User Liubei, his home directory and files are deleted;

3. File Operation commands
3.1 Touch Create a file
Command format: Touch "Options" file name or directory name
Options:
? -A-Modify only the file's access (access) time.
? ? -c? or--no-create? Does not create a file that does not exist.
? ? -d? Using the specified DateTime instead of the current time
? ? -M refers to modifying the Modify (modified) time without modifying access (access) time
? ? -r File-update timestamp (access,modify) of files with timestamp of specified file files (access,modify)
-T? Modify the time to the date specified by the parameter, such as: 11221420 for November 22 14:20
???? Note: Access indicates the time of the last access (only access, no changes) to the file
???????????? Modify for the last time the file was modified
???????????? = The last time the file attribute was changed, including permissions, size, attributes, and so on
Usage examples:
$touch hello.c Create a file named Hello.c under the current folder

  3.2 cat   

Command format: "Options" file name
Options:
-N or –number the number of rows for all outputs starting from 1
-B or –number-nonblank and-n similar, except for blank lines not numbered
-S or –squeeze-blank when a blank line with more than two consecutive lines is encountered, it is substituted as a line of white space
Usage examples:
$ cat?-n? F1 displays all the contents of a file named F1 once.

$ cat? > filename to create a file from the keyboard. Only new files can be created and existing files cannot be edited.

$cat?? File1?? File2? > file merges several files into one file.

???????? 3.3 cp copy file or directory
Command format: "Options" source file or directory destination file or directory
option:
-A or--archive???? The effect of this parameter is the same as specifying the "-DPR" parameter
????-B or--backup????? deleted, the overwrite destination file is backed up first, the backed up file
or directory is also established as a symbolic link, and points to the source file or directory of the origin file or directory link. If this parameter is not added, the source file or directory
-F or--force will be copied directly if a symbolic link is encountered during the copy process????? Forcibly copy a file or directory, regardless of whether the destination file or directory already exists
????-I or--interactive overwrite the file before you ask the user
????-l or--link?????? to make a hard link to the source file, rather than copy the file
????-P or --preserve??? Keep the properties of the source file or directory, including the owner, the owning group, the permission and time
????-P or--parents???? Keep the path to the source file or directory, which can be an absolute or relative path, and the destination directory must already be abundant in
????-R??????????? Recursive processing, the files under the specified directory and subdirectories are processed together. If the form of a source file or directory is not a directory or symbolic link, it is treated as normal file processing
????-R or--recursive?????? Create a symbolic link to the source file instead of copying the file
???-U or--update????? Using this parameter, the file will only be copied when the source file has been updated at the modified time (modification) than the destination file, or the destination file for which the name corresponds does not exist.
???-V or--verbose???? display the execution procedure
? usage Example
$ CP f2/app/f0 copy files to directory app and rename F0
$CP-R/app/test//app/new directory/app/te All files under ST and their subdirectories are copied to the directory/app/new

???????? 3.4 mv Rename a file or directory, or move a file from one directory to another
Command format: MV "parameter" source file or directory destination file or directory
Options:
-B: Overwrite the previous backup if you need to overwrite the file.
-f:force mandatory Meaning, if the target file already exists, will not be asked and directly covered;
-I: If the target file (destination) already exists, you will be asked to overwrite it!
-U: If the target file already exists and source is newer, update (update)
-T: Specifies the target directory for MV, which is used when moving multiple source files to a directory where the destination directory is before the source file.
Usage examples:
$MV F1 New To rename the file to new
$MV/etc/*. Move all files under the/etc file to the current directory

???????? 3.5 rm?? Delete Files and directories
Command format: List of "Options" files
Options:
-D--directory Delete directories that may still have data (super users only)
-F--force Skip files that do not exist, do not display any information, force delete
-I--interactive must confirm before any delete operation
-R/R--recursive Delete all directory tiers in this directory at the same time
-V--verbose detailed display of the steps performed
Usage examples
$RM-I F1 need to confirm before deleting F1
$rm-rf F1file Delete all files in the F1file subdirectory and subdirectories without one by one confirmation

4. System Status Management commands
???????? 4.1 Poweroff shut down the computer
Usage format: Poweroff "Options"
Options:
-N: Do not perform sync operation when shutting down the operating system;
-W: does not really shut down the operating system, only in the log file "/var/log/wtmp";
-D: When the operating system is shut down, the operation is not written to the log file "/var/log/wtmp" to add the corresponding record;
-F: Force shutdown of the operating system;
-I: Shut down all network interfaces before shutting down the operating system;
-H: Set all hardware in the system to standby mode before shutting down the operating system.
???????? 4.2 Init
Usage format: init "Options"
Options:
0: Turn off the machine
1: Single-user form, only root for maintenance
2: Multi-user, cannot use net file system
3: Full Multi-user
5: Graphical
4: Safe Mode
6: Restart
Usage examples
$Init 0 shut down immediately.

???????? 4.3 Shutdown security shutdown command requires root permission to use
Usage format: Shutdown "Options"
Options:
C: When the "shutdown-h 11:50" command, just press the + key to interrupt the shutdown instructions;
-F: Do not perform fsck when restarting;
-F: Perform fsck upon reboot;
-H: Shut down the system;
-K: Just send out information to all users, but not actual shutdown;
-N: Do not call the INIT program to shut down, but by the shutdown themselves;
Restart after-r:shutdown;
-t< seconds;: How many seconds to delay between sending the warning message and deleting the message.

Usage examples
$shutdown-H now shuts down
$shutdown +5 timer Five minutes after the shutdown, can be removed with Ctrl + C cancel shutdown

Linux Learning command "1"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.