Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux piecemeal Foundation Command

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Modify the linux terminal command line color and write to the file to make it permanent

Show prompt format

Modify prompt format

Determine the format you like.

Check to see if there is a .bashrc file

Enter the .bashrc file

Edit the .bashrc file to add character formatting

Wq save exit to see if the write was successful

Reconnect, successful

Type

Used to display the type of specified command and determine whether the instruction given is an internal instruction or an external instruction

Types of commands that can be executed in shell

1. Internal commands: provided by shell and provided in the form of a command

two。 External commands have corresponding executable program files under the file system path

View path: which-a |-- skip-alias; whereis

Internal command

External command

Displays the shell currently in use

Displays all shell currently used by the system

View or set command alias

Format: alias NAME='VALUE'

Cancel alias: unalias [- a] NAME

Example:

Set the command alias to bkmysql, copy / etc/my.cnf to / home/back/my.cnf.bak, and view the alias after setting it.

Example: write the alias setting in the above example in the configuration "piece" for permanent effect, and check it again

Example: do not use the alias of ls

Cancel alias

Date

Show date and time

-d: displays the date and time indicated by the string. Strings must be enclosed in double quotation marks

-s: sets the date and time according to the string. Strings must be enclosed in double quotation marks

-u: display GMT

-- help: online help

-- version: displays version information

List of date format strings:

Example:

Set the period to 2018 5: 24, 11: 27 for 30 seconds.

Show current time

Show current monthly calendar

Displays the calendar for the current full year

Formatted output:

Date + "% Y-%m-%d" 2009-12-07

Output yesterday date

Date-d "1 day ago" + "% Y-%m-%d" 2012-11-19

Output after 2 seconds

Date-d "2 second" + "% Y-%m-%d% H:%M.%S" 2012-11-20 14 Y-%m-%d 21.31

The legendary 1234567890 seconds

Date-d "1970-01-01 1234567890 seconds" + "% Y-%m-%d% H:%m:%S" 2009-02-13 23:02:30

General conversion format

Date-d "2009-12-12" + "% Y/%m/%d% H:%M.%S" 2009-12-12 00Rank 00.00

Apache format conversion

Date-d "Dec 5, 2009 12:00:37 AM" + "% Y-%m-%d% H:%M.%S" 2009-12-05 12:00:37 AM 00.37

Time wandering after format conversion

Date-d "Dec 5, 2009 12:00:37 AM 2 year ago" + "% Y-%m-%d% H:%M.%S" 2007-12-05 00 AM 00.37

Addition and subtraction operation

Date +% Y%m%d / / display the day before yesterday date-d "+ 1 day" +% Y%m%d / / display the date of the previous day date-d "- 1 day" +% Y%m%d / / display the date of the previous day date-d "- 1 month" +% Y%m%d / / display the date of the previous month date-d "+ 1 month" +% Y% m % d / / display the date of the next month date-d "- 1 year" +% Y%m%d / / display the date of the previous year date-d "+ 1 year" +% Y%m%d / / show the date of the next year

Set time

Date-s / / sets the current time. Only root permissions can be set. Others can only view date-s 20120523 / / set to 20120523. This will set the specific time to empty 00:00:00date-s 01:01:01 / / set the specific time. The date will not be changed date-s "01:01:01 2012-05-23" / / this will set all time date-s "01:01:01 20120523" / / this will set all time date-s "2012-05-23 01:01:01" / / this will set all time date-s "20120523 01:01:01" / / this will set all time

Sometimes it is necessary to check the time spent on a set of commands, for example:

#! / bin/bashstart=$ (date +% s) nmap man.linuxde.net & > / dev/nullend=$ (date +% s) difference=$ ((end-start)) echo $difference seconds.

Power off: halt,poweroff

Restart: reboot

Shutdown or restart: shutdown

Common option:-h: equivalent to halt shutdown command

User login information view command:

Example: whoami command to view the subscribers currently logged in to the system

Example: who command to view all current system login accounts

Example: W shows that the system currently logs in to the session and what it does.

Echo:

Used to print the value of a shell variable in shell, or to output a specified string directly

Common options:

-n: no automatic line wrapping

-e: enable interpretation of\ characters

Example: display character abc

Example: show the value of the PATH variable

Example: show that abc does not change.

Command extension: $() or ``

Example: print the output of one command to the parameters of another command

Curly braces extension: {}

Example: numeric, character extension

Tab key completion:

Function: in order to reduce the number of users entering a complete command or path, the display is displayed. The system will search for matching characters according to the existing environment. If you click the Tab key several times and can find a match, it will be displayed. If not, you can click the Tab key twice to list the optional items, but if there are no entries listed, the matching items will be indicated.

History

Command history

Configuration package: ~ / .bash_histroy

Example: perform several common methods respectively:

Call the last parameter of the last command:

1. Lose:! $

two。 Press the ESC key to release, then press. (dot)

Command history environment variables:

The default environment variable of the system makes "write" to show the contents of the environment variable, so you need to see its value in the form of the name of the environment variable "echo $". If you want to modify or set environment variables, there are two ways, one is that you can set environment variables directly in the command 'export command', then it will have an immediate effect, logging out of shell login or server restart will not work, or if you write the export command setting environment variable code to the configuration package, rereading the configuration component will have a permanent effect. There are two ways to reread the configuration effect: one is to make the source command reread the configuration, and the other is to use the dot.

HISTISIZE: number of command history entries

Example: check the number of command history entries

For example, the number of history entries for temporary modification of environment variables is 2000:

Example: the number of history entries for permanently modifying environment variables is 2000

Or make the "period" to make the configuration permanent:

Show the full path where the history piece is saved:

HISTFILESIZE: the number of historical entries recorded in a historical piece

View the number of entries in the history record:

HISTTIMEFRMAT: format of historical command records:

Example: set the history command to show the duration and time of execution

Keyboard shortcuts are often used in Bash:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report