Some linux commands

Source: Internet
Author: User
Tags printable characters touch command

Alias
Note: Set aliases and display aliases for commands.

Syntax: alias [alias] = [command name] % is an alias starting with [command name.

Alias [alias] % displays the command corresponding to [alias.

Alias % displays all alias settings.

Bg
Note: Place commands in the background for running.

Syntax: bg [job]

The options of this command are as follows:

Job command job number.

Export
Description: sets or displays environment variables.

Syntax: export [Option] [variable name] = [variable setting value]

The options of this command are as follows:

-F indicates the function name in [variable name;
-N: Delete the specified variable. The variable is not actually deleted, but is not output to the execution environment of subsequent commands;
-P: list all environment variables that the shell assigns to the program.

Date
Display or set the system time and date

Syntax: date [-d <string>] [-u] [+ format parameter]
Date [-s <string>] [-u] [+ format parameter]

The options of this command are as follows:

Note:
The first syntax can be used to display the system date or time. Parameters starting with "%" are format parameters. You can specify the display format of the date or time.
The second syntax can be used to set the system date and time. Only the Administrator has the permission to set the date and time.
If no parameter is added, data displays the current date and time.

The options of this command are as follows:

-D <string> displays the date and time specified by the string. Double quotation marks must be added before and after the string.
-S <string> specifies the date and time based on the string. Double quotation marks must be added before and after the string.
-U indicates GMT.
-- Help Online help.
-- Version: displays the version information.

The available format parameters of this command are as follows:

% H (expressed in-23 ).
% I hour (expressed as 01-12 ).
% K hour (expressed as 0-23 ).
% L hour (expressed as 0-12 ).
% M minutes (expressed in-59 ).
% P am or PM.
% R time (including hour, minute, and second, expressed in 12 hours AM/PM ).
% S total number of seconds. The start time is 00:00:00 UTC.
% S seconds (expressed in local usage ).
% Z city.
%.
% A full name of the week.
% B the abbreviation of the English name of the month.
Full English name of month % B.
% C date and time. The same result is displayed when only the date command is input.
% D Date (expressed in 01-31 ).
% D Date (including year, month, and day ).
% J the day of the year.
% M month (expressed as 01-12 ).
% U the number of weeks in the year.
% W the number of days of the week. 0 indicates Sunday, 1 indicates Monday, and so on.
% X date (expressed in local usage ).
% X time (expressed in local usage ).
% Y year (in the format of 00-99 ).
% Y year (in four digits ).
% N Insert a new row when it is displayed.
% T insert a tab when it is displayed.
% T time (including hour, minute, and second, expressed in 24 hours ).
MM Month (required ).
DD date (required ).
Hh hour (required ).
Mm minutes (required ).
The first two digits (optional) of the CC year ).
The last two digits of the year YY (optional ).
Ss seconds (optional ).

Example: date + % D

Date + % x % X

Date-d '6 days ago'

Date-d 'now'

Df
View remaining disk space

Syntax: df [Option] [filename]

The options of this command are as follows:

-H outputs results in a user-friendly manner.
-T only outputs the file system of type columns in fstype.
-X: only file systems with output types not listed in fstype.
The unit of-k display space is K.
-M: The display space is in MB.
-A outputs the file system with zero space.
Filename specifies the size of the file to be viewed.

Fdisk/sfdisk
View hard disk partition information

Syntax: fdisk-l [-u] [device...]

Fdisk-s partition

The options of this command are as follows:

-U replaces the cylindrical size with the slice size when listing partition tables.
-L list the partition tables of a given device. If no device is specified,
Lists the partition tables of devices in/proc/partions.
-S partition indicates the partition size (in blocks) of the partition ).

File
Identify file types

Syntax: file Name

Groupadd
Create a new user group.

Syntax: groupadd [-g gid [-o] [-r] [-f] group name

The options of this command are as follows:
-G gid specifies group ID-GID value;
-O reuse the group ID;
-R is used to create a system account;
-F force a new user group to be created.

Groupdel
Delete a user group.

Syntax: groupdel group name

Groupmod
Syntax: groupmod [-g gid [-o] [-n group_name] group name

The options of this command are as follows:

-G gid: Specify the group ID value again;
-O reuse the group ID;
-N group_name: Change the user group name.

Halt
Shutdown command.

Syntax: halt [-dfinpw]

The options of this command are as follows:

-D do not record it in the wtmp (Login record file;
-F, regardless of the current runlevel, forces the system to be shut down without calling shut down;
-I disable all network interfaces before shutting down the system;
-N before shutting down the system, you do not need to execute sync (write all the data in the cache to the hard disk );
-P: After the system is shut down, turn off the power supply;
-W records only in wtmp, instead of actually ending the system.

Kill
Terminate a process

Syntax: kill [-s | p] [-a] PID

The options of this command are as follows:

-S indicates the signal sent to the process. For example,-9 (Force termination) sends a TERM signal by default.
-P indicates the process ID and no signal is sent.
-A: Terminate all processes.
0 sends signals to all processes in the current process group.
-1 sends signals to all processes whose process number is greater than 1.

Ps
View Process status

Syntax: ps [Option]

The options of this command are as follows:

-E/A lists all processes.
-U: select a valid user ID.
-P: select the process under the specified terminal.
-C: select the specified file name.
-F lists all details.
-L display in long format.
-J is displayed in the job format.
-X: select a process that does not control the terminal.

Quota
Displays the disk usage. Generally, users can view their own disk usage permissions.

Syntax: quota [Option] user name or group name

The options of this command are as follows:

-G indicates the permission of the user's Group to use the disk.
-U indicates the user's permission to use the disk.
-P simplifies the display information.

Reboot
Restart command. Needless to say.

Rename
Modify file names in batches

Syntax: rename from to file...

The options of this command are as follows:

From source character.
To target character.
File the file to be renamed

Rename. rm. rmvb *
% Change the suffix of all files from rm to rmvb

Rename 'tr/A-Z/a-z /'*
% Replace uppercase letters in all file names with lowercase letters

Rm/rmdir
Delete a file or directory

Syntax: rm [Option] File Name or directory name
Rmdir directory name (must be an empty directory)

The options of the rm command are as follows:

-D after this option is used, rm generally wants to be used as unlink.
-I prompt the user when deleting each file.
-R: Delete the entire directory, including files and subdirectories.
-V provides a prompt when deleting each file.
-F force delete, and no prompt is given.

Tail
The part after the output file content

Syntax: tail [Option] File Name

The options of this command are as follows:

-N: only the next n rows are displayed.
-F dynamic display, which is often used to track message files.

Top
View CPU usage and modify the priority of processes.

By default, processes are sorted by CPU usage, including PID (N), time limit (A), resident memory usage (M), time (T), and CPU usage (P).

Syntax: top option

The options of this command are as follows:

-D delay specifies the number of seconds to refresh.
-P pid: view the CPU usage of the specified pid.

Type
View the path of a command

Syntax: type command

Whereis
Location of executable files, source code files, and help files in the file system

Syntax: whereis [-bmsu] [BMS directory name-f] File Name

The options of this command are as follows:

-B. Locate the executable file.
-M: locate the Help file.
-S: locate the source code file.
-U searches for executable files, source code files, and help files in the default path.
-B specifies the path to search for executable files.
-M specifies the path for searching the Help file.
-S specifies the path to search for source code files.

W
View login users and what they are doing

Syntax: w [Option] [user]

The options of this command are as follows:

-H does not print the information header.
-S displays information in short format.
-F print the user source.
-V: display version information

Who
View the current user's convenience

Syntax: who [Option]

The options of this command are as follows:

-I: displays the user's activity status.
-U is the same as-I.
-M: displays the user's status.

Last
Lists information about users who have logged on to the system.

Syntax: last [-aRx] [-n <number>] [user account name…] [Terminal number…]

The options of this command are as follows:

-A displays the host name or IP address of the host where the user is logged on to the system in the last row;
-R does not display the host name or IP address of the logon system user;
-X displays information such as system shutdown, restart, and Operation grade change;
-N <count> specifies the number of recent logon users to be viewed;
[User account name…] Specifies to view the logon records of a user account;
[Terminal number…] Specify to view logon records from a terminal.

Lsmod
Displays the kernel modules loaded into the system.

Syntax: lsmod

Lspci
Displays the bus and device information of all system PCI devices.

Syntax: lspci [-bmMnt] [-v [v] [-x [xx] [-s] [[:] [] [. [] [-d []: [] [-I] [-p]

The options of this command are as follows:

-B displays IRQ and I/O addresses;
-M: copy the data of the PCI device;
-M: search for all PCI devices;
-N: display the PCI vendor code;
-T displays all bus, bridges, devices, and relationships in a tree chart;
-V: displays details;
-Vv: displays more details;
-X displays the first 64 bytes of the PCI configuration space in hexadecimal format;
-Xx displays all content of the PCI configuration space in hexadecimal format;
-S [[]:] [] [. [] displays devices that meet the specified bus, slots, and functions;
-D []: [] displays devices that match the vendor ID and device ID;
-I sets file as the PCI ID database. The default value is/usr/share/pci. ids;
-P sets dir as the directory containing PCI information. The default value is/proc/bus/pci.

Mkbootdisk
Create a Linux boot floppy disk with the same version as the current system.

Syntax: mkbootdisk [-- device <device Name>] [Kernel version]

The options of this command are as follows:

-- Device <device Name> specifies the name of the disk where the floppy disk is located, usually/dev/fd0;
[Kernel version] Kernel version of the current system.

Modinfo
Displays kernel module information.

Syntax: modinfo [-adphV] [-f format_string] module File Name

The options of this command are as follows:

-A: displays the author of the kernel module;
-D: displays the description of the kernel module;
-P: displays the parameters supported by the kernel module;
-H: displays help information;
-V: displays version information;
-F format_string specifies any format string, which is used to extract module information from the ELF part of module_file.

Shutdown
Shut down the Linux system and computer.

Syntax: shutdown [-fFhr] [-t <number of calls>] [time] [Warning Information]

The options of this command are as follows:

-F does not perform the fsck check on the disk when the disk is restarted;
-F run The fsck command to check the disk when restarting;
-H shut down the Linux system and then shut down;
-R: Shut down the Linux system and restart it;
-T <seconds> A few seconds later, the shutdown command is executed;
[Time] Use hh: mm or + mm to set the time for executing the shutdown command. You can also use now to execute the command now;
[Warning Information] It can be used to send information about shutdown to every user logged on to the system.

Su
You can use su to temporarily change the user to another user account for logon. If the user name is not included, replace it with the root account.

Syntax: su [-fl] [-c <command>] [User Account]

The options of this command are as follows:

-The effect is the same as that of the-l option;
-F after logging on with another user account, do not read startup settings files such as. profile of the user;
-L after the user account is changed, the working directory is also changed, just like the New Login of the user account;
-C <command> after executing the specified command, return to the original user account.

Chattr
Changes the attributes of files in Linux.

Syntax: chattr [-RV] [-v <version number>] [+/-/= <attribute>] [file or directory]

The options of this command are as follows:

-R recursive processing: all files and subdirectories in the specified directory are processed together;
-V shows the command execution process;
-V <version number> sets the file or directory version;
+/-/= <Attribute> enable/disable/specify this attribute for a file or directory;
[Files or directories] include
A: The file or directory can only be modified in append mode, but cannot be edited and written directly;
A: Do not update the last access time of the file or directory;
C: compress and store files or directories;
D: exclude files or directories from the Dump operation;
I: once set, the file or directory cannot be deleted, renamed, or modified;
S: Confidential deletion of files or directories;
S: updates files or directories in real time without passing through the Buffer zone;
U: prevents accidental deletion.

Du
Used to measure the disk space occupied by directories or files.

Syntax: du [-chkmsS] [-- exclude = <directory/File>] [-- max-depth = <directory layers>] [file/directory]

The options of this command are as follows:

-C not only displays the size of each file/directory, but also the total number of all directories and files;
-H is measured in KB, MB, and GB to improve the readability of output information;
-K is measured in KB;
-M is measured in MB;
-S: only the statistical value is displayed;
-S: displays the size of a directory in hours, excluding the subdirectory size of the directory;
-- Exclude = <directory/File> skips the specified directory and file;
-- Max-depth = <directory layers> if the number of directories exceeds the specified number of layers, ignore the directory.

Passwd
Set or change the user account password.

Syntax: passwd [-dlSu] [user name]
The options of this command are as follows:

-D. Delete the password;
-L lock the account;
-S: List password-related information;
-U unlocks the locked account;
[User name] the user account for which the password is to be set. If no password is specified, the current user's password is set.

Cal
Display a simple calendar.

Syntax: cal [-mjy] [[mouth] year]

The options of this command are as follows:

-M indicates Monday as the first day of each week. The default value is Sunday;
-J is displayed in Julina format, that is, every month. The first day of every year is January 1, January 1;
-Y: displays the calendar of all months of the current year.

Rup
Displays the host status, including the local host, network host, and all hosts on the local network.

Syntax: rup [-dhlt] [host…]

The options of this command are as follows:

-D: displays the local time of the network host;
-H: displays information in alphabetical order of the host name;
-L sort by average server load;
-T sort by host system running time

Ping
It can be used to check whether it can be connected to a host on the network.

Syntax: ping [-fn] [-c <connection count>] [-I <interval>] [-I <network device>]

The options of this command are as follows:

-F generates a ping storm, which puts a serious burden on the network and is only available to root users. This can be used to collect statistics on Packet Loss and error rate;
-N: only the number is output, and the host name is not obtained;
-I <interval> sets the interval between two Ping packets, in seconds;
-I <network device> when the system has multiple devices, you can use this parameter to specify a network device.

Clear
Clear the information on the screen. It is similar to the cls command in DOS. After the screen is cleared, the prompt is moved to the upper left corner of the screen.

Syntax: clear

Comm
To compare two ordered files, run the comm command.

Syntax: comm [-123] file1 file2

The options of this command are as follows:

Note: This command compares two sorted files. File1 and file2 are sorted files.
Comm reads the two files and generates three output columns: rows that appear only in file1; only in file2
The row that appears; the row that exists in both files. If the file name is "-", it indicates reading from the standard input.
Option 1, 2, or 3 suppress the corresponding column display.
For example, comm-12 only displays the rows that exist in both files;
Comm-23 only displays the rows that appear in the first file but not in the second file;
Comm-123 then nothing is displayed.

Wc
The wc command is used to count the number of bytes, number of words, and number of lines in a specified file, and display the statistical result.

Syntax: wc [Option] file...

Note: This command counts the number of bytes, number of words, and number of lines in a given file. If no file name is provided, it is read from the standard input. Wc also provides the President count for all specified files. Is the largest string separated by space characters.

The options of this command are as follows:

-C: counts the number of bytes.
-L number of statistics rows.
-W counts the number of words.
These options can be used in combination. The order and number of output columns are not affected by the order and number of options.
It is always displayed in the following order and each item has at most one column.

Number of lines, number of words, number of bytes, and file name

If there is no file name in the command line, no file name appears in the output.

Tar
Tar can create files and directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now, you can create files, such as floppy disks, on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission. Tar on Linux is of the GNU version.

Syntax: tar [primary option + secondary option] file or directory

The options of this command are as follows:

The tar command has the primary and secondary options, and the primary options are required. It tells tar what to do,
The secondary option is used as an aid and can be used.

Main options:
C. Create a new archive file. Select this option if you want to back up a directory or some files.
R: append the file to the end of the file. For example, if you have prepared a backup file
If you forget to back up a directory or some files, you can use this option
Append to the backup file.
T list the file content and check which files have been backed up.
U updates the file. That is to say, replace the original backup file with the new file. If the backup file cannot be found
Append the updated file to the end of the backup file.
X release a file from the file.

Auxiliary options:
B. This option is set for the tape drive. It is followed by a number to describe the block size. The default value is 20.
(20*512 bytes ).
F. This option is usually required when you use an archive file or device.
K. Save the existing files. For example, when we restore a file, we encounter the same file during restoration,
Does not overwrite.
M sets the modification time of all files to the present when restoring files.
M creates a multi-volume archive file to store it on several disks.
V detailed report on the file information processed by tar. If this option is not available, tar does not report file information.
W each step requires confirmation.
Z uses gzip to compress/decompress the file. With this option, the file can be compressed, but the file can also be restored.
Be sure to use this option for decompression.

Example: $ tar cvf usr.tar/home
Complete the sub-directories in the/home directory as a local file named usr.tar.

Example: $ tar czvf usr.tar.gz/home
Back up all the subdirectories in the/home directory and compress them,
The ghost file is named usr.tar.gz.

Example: $ tar xzvf usr.tar.gz
Restore and decompress the backup file usr.tar.gz.

Example: $ tar tvf usr.tar | more
The contents of the usr.tar backup file are displayed on the display in split screen mode.

To back up a file to a specific device, you only need to use the device name as the backup file name.
Example: $ tar cf/dev/fd0/home
You can create a backup file in a floppy disk of the/dev/fd0 device,
Copy all the files in the/home directory to the backup file.

To restore files on the device disk, use the xf option: $ tar xf/dev/fd0.

If the size of the backup file exceeds the storage space available for the device, such as a floppy disk, you can create a multi-volume
Tar backup file. The M option indicates that the tar command prompts you to use a new storage device.
When a floppy disk is archived, the tar command will remind you to put a new floppy disk when a floppy disk is full.
In this way, you can save the tar file to several disks.
Example: $ tar cMf/dev/fd0/home

To restore the files on several disks, you only need to put the first disk into the soft drive, and then enter the tar command with the x and M options.
If necessary, you will be reminded to add another floppy disk.
Example: $ tar xMf/dev/fd0

2) tar call bzip2
Bzip2is a more powerful compression program. The file ending with .bz2 is the result of bzip2 compression.
The decompress program relative to bzip2 is bunzip2. Use the-j parameter in tar to call gzip.
The following is an example:

# Tar-cjf all.tar.bz2 *. jpg
This command is to compress all .jpg files into a tar package and use bzip2 to generate a bzip2 File.
Compressed package named all.tar.bz2

# Tar-xjf all.tar.bz2
This command unlocks the generated package.

Finger
Query user information

Syntax: finger [Option] [user] [user @ host]

The options of this command are as follows:

-S displays the user's registration name, actual name, terminal name, write status, stagnation time, Logon Time, and other information.
-L in addition to the information displayed with the-s option, it also displays the user's home directory, logon shell, mail status, and other information,
And the. plan,. project, and. forward files in the user's main directory.
-P is the same as the-l option except that the. plan and. project files are not displayed.

Netstat
The netstat command displays network connection, route table, and network interface information, allowing you to know which network connections are currently in operation.

Syntax: netstat [Option]

The options of this command are as follows:

-A displays all sockets, including those being monitored.
-C is re-displayed every one second until the user interrupts it.
-I displays information of all network interfaces in the same format as "ifconfig-e ".
-N is replaced by a network IP address to show network connection conditions.
-R displays the core route table in the same format as "route-e ".
-T shows the TCP connection status.
-U: displays the connections of the UDP protocol.
-V: displays ongoing work.

Sort
The sort command sorts all rows in the file. The sort command has many very useful options, which were initially used to sort the file content in the database format. In fact, the sort command can be considered as a very powerful data management tool to manage files with similar content to database records. The sort command sorts the content in the file line by line. If the first character of the two lines is the same, the command will continue to compare the next character of the two lines, the comparison will continue.

Syntax: sort [Option] File

The options of this command are as follows:

Note: The sort command sorts all the rows in the specified file and displays the results on the standard output.
If the input file is not specified or "-" is used, the sorting content comes from the standard input.

Sort sorting is done by comparing one or more keywords extracted from the input line. Sort keyword Definition
The smallest character sequence used for sorting. By default, the entire behavior keyword is ordered by ASCII characters.

The options for changing the default settings are as follows:

-M if the given file is sorted, merge the file.
-C check whether the given files are sorted in order. If they are not all sorted, an error message is printed,
And exit with the status value 1.
-U considers that only one row is left for the same row after sorting.
-O: the output file writes the sorting output to the output file instead of the standard output file. If the output file is an input file
One, sort first writes the content of the file into a temporary file, and then sorts and writes the output results.

The options for changing the default sorting rule are as follows:

-D is ordered alphabetically. Only letters, numbers, spaces, and tabs are meaningful for comparison.
-F treats lowercase letters as uppercase letters.
-I ignore non-printable characters.
-M is used as the month comparison: "JAN" <"FEB" <... <"DEC ".
-R outputs the sorting results in reverse order.
+ Posl-pos2 specifies one or more fields as sorting keywords. The field position starts from posl to pos2.
(Including posl, excluding pos2 ). If pos2 is not specified, the keyword is from posl to the end of the row.
The position of the field and character starts from 0.
-B ignores leading spaces (spaces and tabs) when searching for sorting keywords in each line ).
-T separator specifies the character separator as the field separator.

The following describes how to use sort through several examples.

Use the sort command to sort all rows in the text file and output the result. Note that
The first word is exactly the same. This command will continue from the first character of their second word vegetables and fruit
.

$ Cat text
Vegetable soup
Fresh vegetables
Fresh fruit
Lowfat milk

$ Sort text
Fresh fruit
Fresh vegetables
Lowfat milk
Vegetable soup

You can save the sorted file content or output the sorted file content to the printer. In the following example
The sorted file content is saved to the file named result.
$ Sort text> result

Sort the content of the file example using 2nd fields as the sorting keyword.
$ Sort + 1-2 example

In reverse sorting of file1 and file2 files, the results are placed in outfile, using the first word of 2nd Fields
As the sort keyword.
$ Sort-r-o outfile + 1.0-1.1 example

Sort sorting is often used in pipelines with other commands to combine complex functions, such
Files in the previous working directory are sent to sort for sorting. The sorting keywords are 6th to 8th fields.
$ Ls-l | sort + 5-7

The sort command can also operate on standard input. For example, if you want to merge several lines of file text and
And then sort the text lines. You can first use the command cat to merge multiple files, and then use the pipeline operation to merge the files.
The following text lines are input to the sort command, and the sort command will output these merged and sorted text lines. In the following example
Child, the text lines of the veglist and fruitlist are merged and sorted and saved to the clist file.
$ Cat veglist fruitlist | sort> clist

Touch
The touch command changes the time record of the file. If the file does not exist, the system creates a new file.

Syntax: touch [Option] file1 [file2...]

The options of this command are as follows:

-A: changes the file read time record.
-M: Change the modification time record of the file.
-C if the target file does not exist, no new file will be created. The same effect as -- no-create.
-F is not used and is reserved for compatibility with other unix systems.
-R uses the time record of the reference file, which has the same effect as -- file.
-D: set the time and date in different formats.
-T sets the time record of the file. The format is the same as that of the date command.
-- No-create does not create a new file.
-- Help lists the instruction formats.
-- Version: List version information.
-- Version: List version information.

Chgrp
The group to which the file or directory belongs. In the UNIX system family, the control of file or directory permissions is managed by the owner and Its group. You can use the chgrp command to change the group to which the file and directory belong. You can set the group name or group ID.

Syntax: chgrp [Option] [group] [file or directory...]

The options of this command are as follows:

-V shows the command execution process.
The-c effect is similar to the "-v" parameter, but only the changed part is returned.
-F: no error message is displayed.
-H only modifies the file connected by the symbol, and does not change any other related files.
-R recursive processing: all files and subdirectories in the specified directory are processed together.
-- Help Online help.
-- Reference = <reference file or directory> sets all groups of the specified file or directory to the same group as that of the reference file or directory.
-- Version: displays the version information.

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.