Linux basic commands

Source: Internet
Author: User
Tags create directory parent directory posix readable touch command disk usage

1: Create file: Touch file name

The touch command can also change the access time and modification time of an existing file without changing the contents of the file.

Change modification time only touch-m file name

Change access time only touch-a file name

By default, touch uses the current time, and you can specify the time by using the-t parameter plus a specific timestamp

Touch-at 201112251200 GG

TOUCH-T 201112251200 GG

--------------------------------------------------------------------------------------------------------------- -----------------------------------------

2: Delete file: RM file name

-F,--force ignores nonexistent files and never gives hints.

-I,--interactive for interactive deletion

-R,-R,--recursive instructs RM to recursively delete all directories and subdirectories listed in the parameters

-V,--verbose detailed display of the steps performed

--HELP Display this help message and exit

--version output version information and exit

Friendly tip: General delete operation with RM can

--------------------------------------------------------------------------------------------------------------- -------------------------------------------

3: Create directory: mkdir-Parameter directory name

Parameter list:

-M: Set access permissions on the new directory or set with the chmod command;
-P: Can be a path name. In this case, if some directories in the path do not already exist, and with this option, the system will automatically establish those that do not already exist, that is, multiple directories can be established at one time;

--------------------------------------------------------------------------------------------------------------- -------------------------------------------

4: Delete directory:

RmDir directory name (it can only delete empty directories)

Rm-r Directory name (recursively delete files in the directory via the-r parameter, and finally delete the directory itself)

You can also force the deletion by adding parameter-F

It is important to note that this directory cannot be deleted directly if it is currently in the directory.

If the directory is executing a process, kill the process to delete the directory

If the directory is also a mount point, you need to uninstall the mount point before you can delete the directory

--------------------------------------------------------------------------------------------------------------- -------------------------------------------

5: Rename file or directory: MV File New name

To move a file or directory:

MV Directory name 1 directory Name 2//move all files under directory 1 and its directory to directory 2

MV FileName Directory name//move file to Directory

MV *.. ///move all files under the current folder to the parent directory

--------------------------------------------------------------------------------------------------------------- ------------------------

6: Copy files or folders: CP-Parameter source file name destination file name

If the target file is not created, the target file is created automatically, and then the Copy command is executed, and the two files have different index numbers;

If the target file has been created, it will overwrite the original contents of the target file;

Parameters:
-A or--archive the effect of this parameter with the same as specifying the "-DPR" parameter
-B or--backup Delete, overwrite destination files are backed up first, backed up files or directories are also created as symbolic links and point to source files or directories linked to source files or directories. If this parameter is not added, the source file or directory will be copied directly if a symbolic link is encountered during the copy process.
-F or--force forcibly copy a file or directory, regardless of whether the destination file or directory already exists
-I or--interactive overwrite the file before asking the user
-L or--link to create a hard link to the source file instead of copying the file
-P or--preserve preserves the properties of the source file or directory, including the owner, the owning group, the permissions and the time
-P or--parents retains the path to the source file or directory, which can be an absolute or relative path, and the destination directory must already be in
-R recursive processing, the files under the specified directory and subdirectories are processed together. If the form of the source file or directory is not a directory or symbolic link, it will be treated as normal file
-R or--recursive recursive processing, the files and subdirectories under the specified directory are processed together
-S or--symbolic-link to create symbolic links to source files instead of copying files
-S < back-end string > or--suffix=< back-up string > After backing up the destination file with the "-B" parameter, a backup string is added to the end of the backup file. The default backup character string is the symbol "~"
If you or--update use this parameter, the file will only be copied when the source file has been modified (modification time) when the destination file is updated, or the destination file for the name is not present.
-V or--verbose shows the execution process
-V < backup method > or--version-control=< backup method > Specifies that when backing up files, the backup file name is named in the following 3 ways:
1.numbered or T, the backup number will be used, and the ~1~ string will be added at the end of the word, with the number incremented sequentially
2.simple or never will use a simple backup, the default back-end string is ~, can also be specified by-s
3.existing or nil will use the current mode, the program will first check if there is a backup number, if there is a backup number, if not the use of simple backup
The file system that the file or directory is copied by-X or--one-file-system must be the same as the file system where the CP instruction is executed, otherwise it will not be copied or processed in other partitions
--help Show online Help
--sparse=< Timing > Setting time to save sparse files
--version Display version

--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------

7: Build a link

Hard Link: cp-l source file destination file or ln source file destination file

A soft link is a symbolic Link: cp-s source file Destination file or ln-s source file destination file

parameter list of the LN command:

-B: Files that will be overwritten or deleted at the time of the link are backed up;
-D: Allow system managers to hard link their own directories;
-F: Forcibly create a link to a file or directory, regardless of whether the file or directory exists;
-N: Treats the destination directory of the symbolic link as a general document;
-I: When deleting files with the same file name of Dist, ask first;
-S: Soft link (symbolic link);
-V: Displays the file name before the link;

For a detailed explanation of the links:

Https://zhidao.baidu.com/question/527753457.html

http://blog.csdn.net/zhy_yz/article/details/5601210

Http://www.cnblogs.com/kex1n/p/5193826.html

http://blog.csdn.net/gsl68/article/details/6956842

--------------------------------------------------------------------------------------------------------------- -----------------------------------

8: Show files and directories in current directory ls-parameter (common parameters are-sail)

Parameter list:

-a,–all lists all the files in the directory, including the hidden files that begin with.
-A with-a, but does not list "." (represents the current directory) and ".." (Represents the parent directory of the current directory).
-c  mate-lt: Sort and display CTime according to CTime (the last time the file state was changed) mate-L: Show CTime but sort by name otherwise: Sort by CTime
-C list items from top to bottom of each column
–color[=whe N] Controls whether color-resolved files are used. When can be ' never ', ' always ' or ' auto ' one of the
-d,–directory displays the directory as a file, rather than displaying the file under it.
-d,–dired produces dired mode suitable for EMACS use results
-F to output files are not sorted,-au option takes effect,-LST option expires
-g similar to-l, but does not list owner
-g,–no-group does not list any The information for the off group
-h,–human-readable to list the file size in an easy-to-understand format (for example, 1K 234M 2G)
–si similar to-H, but the file size takes 1000 of the time instead of the 1024x768
-h,–dereference-comma Nd-line the true destination indicated by the symbolic link in the command column
–indicator-style= specifies that after each project name is prefixed with the indicator < mode >:none (default), classify (-f), File-type (-P
-i,–inode Prints the inode number for each file
The-i,–ignore= style does not print any items that conform to the shell Universal Character < style >
-K, which is the size of the file in K-byte format.
-L lists the file's permissions, owner, file size, and more, in addition to the file name.
-l,–dereference When displaying the file information for a symbolic link, display the object indicated by the symbolic link instead of the information for the symbolic link
-m all items are separated by commas and fill the entire row width
-o similar to-L, showing details of the file in addition to the group information.
-r,–reverse in reverse order
-r,–recursive all sub-directory layers are listed at the same time

-s,–size to list the size of all files in block size
-s sort by file size
–sort=word The following are optional WORD and the corresponding options they represent:
Extension-x status-c
None-u time-t
Size-s Atime-u
Time-t Access-u
Version-v Use-u
-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
-V Sort by version
-W,–WIDTH=COLS Specifies the screen width without using the current value
-X list items line by row instead of columns by column
-x Sort by extension
-1 list only one file per line
Help display this help message and leave
–version display version information and leave

--------------------------------------------------------------------------------------------------------------- -----

9: View file Statistics: Stat file name

-------------------------------------------------------------

10: View File type: filename

------------------------------------------

View File Contents

11:cat file name

Parameters:

-N adds line numbers to all rows

-B Add line numbers to text only

-S compresses multiple blank rows into a single blank line

-T Remove tab

The cat command does not control the subsequent operation once it is run

---------------------------------------------------------------

12:more-Parameter file name

Parameters:

+num starting from Num line;

-num defines the screen size for NUM lines;

+/pattern starts from the first two lines of the pattern;

-C clear the screen from the top and then display;

-D Prompt Press space to continue, ' Q ' to quit. (Pressing the NULL key to continue, press the Q key to exit), disable the ringing function;

-L ignores Ctrl+l (page break) characters;

-P pages are changed by clearing the window instead of scrolling. A bit similar to the-c parameter;

-S displays consecutive empty lines as one line;

-U Remove the underline from the contents of the file

The action command to exit more is Q

Here are some kids shoes don't understand what these command options mean, here I'll give you a few examples and add some notes.

[Email protected]:~ $more-dc/etc/profile Note: the-D and-C options are displayed and displayed at the top of the terminal or console;

[Email protected]:~$ more +4/etc/profile Note: +num option, starting from the 4th line of profile;

[Email protected]:~$ more-4/etc/profile Note:-num option, display 4 rows per screen;

[e-mail protected]:~$ more +/mail/etc/profile Note: +/pattern option, starting from the first two lines in profile;

Some shortcut keys

In the use of more, you may be enabled to view the default mode, that is, you do not add the +/pattern option, so the full interruption of the display when you are a little out of the way, do not be afraid, please see below, hehe.

Ctrl+f (or SPACEBAR) is to display a screen down, Ctrl+b is to return to the previous screen, the ENTER key can scroll down to display n rows, to set by itself, the default is 1 lines; = output the line number of the current line;: F output File name and line number of the current line; v Call VI editor; command to invoke the shell and execute the command; Q quit more, there is another when we look at a file, want to call VI to edit it, do not forget the V action command, which is more convenient.

----Supplement

When explaining the use of the [File Management tool Cat command], we also mentioned some examples of working with pipelines and redirects, and today I'll combine pipelines (|) to give an example:

For example, when you view the command through other files, (Ls,cat) and so on, the content of LS is too much, you need to display the page, at this point you can:

[Email protected]:~$ ls-l/etc |more

---------------------------------------------------------------------------------------------------

13:less-Parameter file name

Parameter list:

-b <缓冲区大小> 设置缓冲区的大小-e  当文件显示结束后,自动离开-f  强迫打开特殊文件,例如外围设备代号、目录和二进制文件-g 只标志最后搜索的关键词-i 忽略搜索时的大小写-m 显示类似more命令的百分比-N 显示每行的行号-o <文件名> 将less 输出的内容在指定文件中保存起来-Q 不使用警告音-s 显示连续空行为一行-S 行过长时间将超出部分舍弃-x <数字> 将“tab”键显示为规定的数字空格
/string: Search down the function of "string"? String: Search Up "string" function N: Repeat previous search (with/or?). AboutN: Reverse repeats the previous search (and/or?) About) b Turn back one page D back half page h Display Help interface Q exit less command U forward scroll half page forward scroll one line key scroll a page [PageDown]: Flip one page [PageUp]: Turn one page up
-------------------------------------------------
View some files
14:tail-Parameter file name
The end 10 lines are displayed by default
Parameter list:
-C bytes Displays the last bytes bytes of a file
-N lines displays the last lines line of the file
-F Let the tail program remain active, if new content is added to the end of the file is displayed
--pid=pid with the-f parameter, keeps track of a file until the process ID is PID is ended
-S SEC and-f parameter together, sleep sec seconds between each loop output,
-V always displays headers with file names
-Q never displays headers with file names
The tail command allows you to view the contents of a file while other processes are using it. The tail command remains active and continuously displays the content that is added to the file. This is a wonderful way to detect system logs in real time
--------------------------------------------------------------------------------------------------------------- ----------
15:head-Parameter file name
The contents of the first 10 rows of the file are displayed by default
It is similar to the tail command and supports the-C,-n parameter, but does not support the-f parameter;
The head command is a sharp weapon that does not know the contents of the file and wants to know the approximate content without having to load all the files
-------------------------------------------------------------------
16: Convert the current time to a timestamp
Date +%s
17: Convert Timestamps to TIME
On Mac: date-r< timestamp >
On CentOS: date [email protected]< timestamp >
-----------------------------------------
18: View Process: PS-parameters
Explanation: http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185938.html
19: Real-time monitoring process: Top (can download htop, better use a bit)
---------------------------------------------------------------------
20: Kill the process
(1) Kill PID
It's mandatory the strongest. When the process receives this signal, it will stop running immediately, may cause the file corruption;
Other signals can be specified with the-s parameter;
Linux Process signal List
Signal Name Description

1 HUP hanging off
2 INT Interrupt
3 QUIT End Run
9 Kill unconditionally terminated
One SEGV segment error
The term is terminated as far as possible
+ Stop unconditionally stops running, but does not terminate
TSTP stopped or paused, but the background continues to run
CONT resumes execution after stop or TSTP

It is usually acceptable to try the term signal first. If the process ignores it, then use an int or hup signal. Kill signal when no other signal is in effect;
(2) Killall process name
Columns such as: Killall http*
This command ends all processes that start with HTTP, such as the HTTP service of the Apache Web server
---------------------------------------------------------------------------
21: Mount Storage Media
By default, the Mount command outputs a list of devices mounted on the current system
Format: Mount [-parameter] [device name] [Mount Point]
The Mount command is detailed:
Http://www.cnblogs.com/xd502djj/p/3809375.html
http://tutu.spaces.eepw.com.cn/articles/article/item/70737
------------------------------------------------------------------------------
22:fuser

You can show which program is currently using a file on disk, mount point, or even network port, and give detailed information about the program process.

fuser只把PID输出到标准输出,其他的都输出到标准错误输出;

Format: fuser-parameters

such as: FUSER-MVU file name/directory name

Parameter list:

-a displays all the files specified on the command line, and the files that are accessed by default are displayed.
-C and-M are used for POSIX compatibility.
-K kills the process that accesses the file. If no-signal is specified, the Sigkill signal is sent. Combined with –signal

-signal uses the specified signal instead of Sigkill to kill the process. Signals (such as-hup,-1) can be represented by name or number, which is used with-K, otherwise it is ignored.

-L lists all known signal names.
-I asks the user before the process is killed, which is ignored if there is no-k option.
-m name specifies a mount on the file system file or The block device being mounted (name). All processes that access this file or file system will be listed. If a directory is specified, it is automatically converted to "name/" and uses all file systems mounted under that directory.
-n space specifies a different namespace (space). This supports different spatial files (file name , the default here), TCP (local TCP port), UDP (local UDP port). For ports, you can specify the port number or name, and if not ambiguous, you can use the form of a simple representation, such as: Name/space (i.e., a representation of a shape such as a 80/tcp).
-s silent mode, when-U,-V is ignored. -A cannot be used with-S.  
-u Add the user name of the process owner after each PID.
-v verbose mode. Outputs the output of the PS-like command, including many domains such as Pid,user,command, and if the kernel is accessed then the PID is kernel.

See also:

http://czmmiao.iteye.com/blog/1733722

Http://www.cnblogs.com/lizhilin/p/5111004.html

-----------------------------------------------------------------------------------

23: View disk usage for mounted devices:

DF [Options] [file]

Parameter list:

Necessary parameters:

-A All File system list

-h easy to read mode display

-H equals "-H", but the formula, 1k=1000, rather than 1k=1024

-I display inode information

-K block is 1024 bytes

-L show local file system only

-M block is 1048576 bytes

--no-sync Ignore sync command

-P output format POSIX

--sync perform the sync command before obtaining the disk information

-T File system type

Select parameters:

--block-size=< Chunk Size > specified chunk size

-t< file system type > show only disk information for selected file systems

-x< file System type > does not display disk information for the selected file system

--HELP Display Help information

--version displaying version information

See also: http://www.cnblogs.com/peida/archive/2012/12/07/2806483.html

---------------------------------------------------------------------------------------------------

24: Display directory and file disk usage space

du [Options] [file]

Parameter list:

-A or-all displays the size of individual files in the directory.

-B or-bytes displays the directory or file size, in bytes.

-C or--total displays the sum of all directories or files in addition to the size of individual directories or files.

-K or--kilobytes output in kilobytes (1024bytes).

-M or--megabytes is output in megabytes.

-S or--summarize displays only the totals, listing only the last added total value.

-H or--human-readable in k,m,g to improve the readability of the information.

-X or--one-file-xystem the file system at the beginning of the processing, if any other different file system directories are skipped.

-l< the source file size of the symbolic link specified in the Symbolic link > or--dereference< symbolic link > Display option.

-S or--separate-dirs displays the size of individual directories without the size of their subdirectories.

-x< file > or--exclude-from=< file > in < file > specify directory or file.

--exclude=< directory or File > skip the specified directory or file.

-D or--dereference-args displays the source file size for the specified symbolic link.

-H or--si is the same as the-h parameter, but the k,m,g is converted to 1000 units.

-L or--count-links duplicates the hardware-linked files.

------------------------------------------------------------------------------

Linux basic commands

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.