Common commands of Linux system and their use methods

Source: Internet
Author: User
Tags aliases parent directory readable switches touch command

1.echo (printf)
Echo-display a line of text-displays a row of text

Common options:
-N: No line break;
-e: Make "\" effective; (eg:\n: line break, \ t: Horizontal tab)
Text color Identification method:
\033: Represents the CTRL key
[: Controls the delimiter between the character and the color code;
All color codes need to end with m;

Color code:
0: Turn off the color display property, revert to black white;
1: Bold display of text characters;
4: Underline text characters;
5: Is the text character flashes;
7: Exchange the background color and foreground color of the text character;
8: Set the background color of the text character to be the same as the foreground;

30-39: Set the foreground color of text character, 38,39 is reserved, not used temporarily;
40-49: Set the background color of the text character, 48,49 is reserved, temporarily not used;
eg:~]# echo-e "\033[1;31mboom\033[0m"

2.cd
Change the shell working directory-Switch working directory

Cd/path/to/somedir: Switch The working directory to the directory represented by the parameter;
CD: Switch The working directory to the home directory of the currently logged-in user, equivalent to CD ~;
CD-: Switches the working directory to the last working directory before;
CD ~username: Switches the working directory to the specified user's home directory;

3.pwd
Print the name of the working directory-output current working directory
The shell provides two variables: pwd,oldpwd
PWD: Current Working directory
OLDPWD: Top Level working directory
4.ls
Ls-list directory contents-; list File contents
The content of the directory is the file name;

Common options:
-A,--all: Displays all files, including hidden files, (in Linux file systems, all with "." Files that are the starting character of the file name, are hidden files)
-A,--almost-all: Displays except "." and ".." All files, including hidden files;
--color[=when]: Display the query results in different colors;
-H,--human-readable: Displays a more readable format when displaying the size of the file, usually in conjunction with the-l option;
-L: Displays the detailed properties of the file using a long column table;
-RW-------. 1 root root 1458 December anaconda-ks.cfg
-: Indicates the file type;
RW-------: The file's permission bit settings;
.: Indicates whether the file has special attributes or extended attributes;
1: Indicates the number of times the file has been hard-linked;
Root: The owner of the file
Root: The genus Group of the file
1458: Indicates the size of the file, in bytes when the-H option is not used;
December 23 2016: One of the timestamp of the file, indicating the time of the last modification;
Anaconda-ks.cfg: File name
For device files:
~]# ls-l/dev/sr0
BRW-RW----. 1 root cdrom 11, 0 September 10:50/dev/sr0
One by one, 0:major, minor
Major: The main device number that identifies the device type, and then determines what driver needs to be loaded;
Minor: The secondary device number that identifies the different devices in the same device type;
The device number defaults to 8-bit binary notation, so the default device number range is 0-255;
-R,--reverse: Reverse output result
-R,--recursive: recursive display, if there is a subdirectory in the target directory, then recursively display the contents of the subdirectory, in turn recursively go down;
-Z,--context: Displays the SELinux security context label for the file;

5.mkdir
Mkdir-make Directories-Create a new directory
Common options:
-P,--parents: When the directory is created, if its parent directory does not exist, it is created first;
-V,--verbose: Displays a piece of information for each directory created;

6.rm
Rm-remove files or directories-Deleting a file or directory
Common options:
-F,--force: Violence, forced deletion, no popup information;
-R,-R,--recursive: recursively deletes the contents of directories and directories;



7.touch
Touch-change file timestamps-timestamp of modified files
Common options:
-C,--no-create: Do not create any files;
-A: Only modify the access timestamp of the file;
-M: Only modify the file's modified timestamp;
-T STAMP: Replace the timestamp of the file with the specified STAMP;
The format of the stamp is: [[CC]YY]MMDDHHMM[.SS]
If the-c option is not specified, the touch command can be used as a file creation;


8.stat
Stat-display file or file system status-Displays the status of the files or filesystem
Common options:
-C,--format=format: Displays the specified state property of the file in the specified format;
FORMAT:
Total data blocks for%b files
%d free file node points in file system
%f free blocks in the file system
Inode number of the%i file
%l the maximum length of a file name
%n file name
%s File size



9.nano: Full screen Editing tool in text mode;
Under the Nano interface:
^: caret, indicating the CTRL key on the keyboard;
^+o: Save the contents of the document;
^+x: Exit the editing interface;

10.cat
cat-concatenate files and print on the standard output-connection file and display
Common options:
-B,--number-nonblank: Number output for non-blank lines;
-N,--number: number output for all lines;
-S,--squeeze-blank: merge contiguous blank lines;
-E,--show-ends: Displayed at the end of the line in $ characters;

Tac-concatenate and print files in reverse-reverse output results based on cat commands

Note: The cat or TAC command, if no parameters are given, all of the content needs to be done through standard input (typed from the keyboard), and can then be exited with "^+c" or "^+d";

11.head
Head-output the first part of the files-the beginning of the output file;
Common options:
-C,--bytes=[-]k: Displays the content of the corresponding length in bytes;
-N,--lines=[-]k: Displays the content of the corresponding length in the behavior unit;
-#: Show Front # lines

K may have a multiplier suffix:b, KB, K, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and So on for T, P, E, Z, Y.
If you do not use any options, the first 10 lines of the specified file contents are displayed by default;

12.tail
Tail-output the last part of the files-the final portion of the output file;
Common options:
-C,--bytes=[-]k: Displays the content of the corresponding length in bytes;
-N,--lines=[-]k: Displays the content of the corresponding length in the behavior unit; can use-#K方式替换-n #K;
-F,--follow[={name|descriptor}]: Monitor changes at the end of the file;
Eg: ~]# tail-f/etc/a.txt occupancy standard output continuously monitors changes in this file

13.more
More-file perusal Filter for CRT viewing-page display of document content, filtering;

Interactive editing methods:
You can use "/" to search for filters based on subsequent string combinations;
You can use "n" to find the next match;
Use "Q" to exit more mode;
Using Enter, you can turn down one line;
Using space, you can turn down one page;

14.less
Less-opposite of more-commands corresponding to more

Interactive editing methods:
You can use the "/" or "?" Search filtering based on subsequent string combinations;
The next occurrence can be found using "n" or "n";
Use "Q" to exit more mode;
Using Enter, you can turn down one line;
Using space, you can turn down one page;

15.date
Operating system time, referred to as system time, time recorded using the software mode clock;
Date-print or set the system date and time-print or set the

Common options:
-S,--set STRING: Sets the system time to the specified time;
Two types of formats:
1) MMDDHHMM[[CC]YY][.SS]
2) "Ccyy-mm-dd HH:mm:ss" or "Ccyy/mm/dd HH:mm:ss"
eg:~]# date-s 2018-4-3 +20:55:22
FORMAT:
%F: Represents the full date format, i.e.: YY-MM-DD
%T: Indicates the complete time-division-seconds format, and: HH:MM:SS
%Y: Represents the full year
%m: Indicates the month
%d: Represents the date
%H: Indicates hours
%M: Indicates minutes
%s: Indicates seconds
%s: Time stamp, from 1970-01-01 00:00:00 to the current system time the number of seconds experienced;
Note: January 1, 1970 as the Unix of the same;
This timestamp is represented by a 32-bit binary, so the maximum range of its representation is 0~4294967295;

16.clock/hwclock
Hwclock-query or set the hardware clock (RTC)-query or set hardware clocks (RTC)

Common options:
-S,--hctosys: Set the system time according to the hardware clock;
-W,--SYSTOHC: Sets the hardware clock according to the system time; (not recommended)

17.cal-Display a calendar


18.cp
CP-Copy files and directories
Format: CP [OPTION] ... [-T] SOURCE DEST: Single source copy
CP [OPTION] ... SOURCE ... DIRECTORY: Multi-source replication

1) The CP command must be connected to at least two parameters;
2) The last parameter, usually the target location to be copied to;
3) If the target given at the time of copying is the directory, copy the file directly to the specified directory, retain the original file name, and copy and rename the file if the target is not a directory when copying the non-directory file;

Common options:
-R,-R,--recursive: recursively copy directory files;
-d Same as--no-dereference--preserve=links
When the copied source file is a symbolic link file, the-D option preserves the symbolic link file as the source file is copied, and does not copy the file that the symbolic link file points to;
-p Same as--preserve=mode,ownership,timestamps
The permission bits, ownership, and timestamp attributes in the copied source file are preserved;
-A,--archive same as-dr--preserve=all
Equivalent to a combination of-DPR;
-F,--force: If the target file already exists, then force the copy and do not prompt; To make this option effective, the CP command needs to be preceded by "\" in front of the CP, i.e.: # \CP source_file destination_file

19.mv
Mv-move (rename) files-Move or rename a file
Format:
MV [OPTION] ... [-T] SOURCE DEST: Single source Mobile
MV [OPTION] ... SOURCE ... DIRECTORY: Multi-source mobile

Common options:
-F,--force: Move the file and force overwrite the file with the same name in the target location;
-N,--no-clobber: When moving a file, the source file does not move if it has the same name as the file in the target location;

20.alias
Alias-defines or displays aliases.
Format: Alias [-P] [Name [= value] ...]
Note: If the alias command does not have any options and parameters, it shows all the alias settings that have been defined and are in effect;

# alias alias= ' COMMAND [OPTION] ... [ARGUMENT] ... '

Unalias
Unalias-Remove each "name" from the alias definition list.
Format: Unalias [-A] name [name ...]

Attention:
The functions of the alias command and the Unalias command take effect immediately; the lifetime of this second command is only the life of the current shell; Once logged off, it is equivalent to shutting down bash, using aliases defined by the alias command or alias operations that are removed using the Unalias command. Will lapse immediately;

For each user, there is a private bash profile, a hidden file in the user's home directory, with the file name ". BASHRC", whose main function is to preserve the definition of the alias of the command;

Attention:
After you edit and save the command alias in this file, it does not take effect immediately in the currently running bash and requires reloading the file for the configuration to take effect, the following two actions are possible:
1. Restart bash: Log in again after logging off;
2. Execute the command defined in the file: using the source command, or the. command;
eg:~]# source. BASHRC

Source-Executes a command in a file in the current shell.
. -Executes a command in a file in the current shell.

Common commands for Linux systems and how to use them

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.