Linux Common commands

Source: Internet
Author: User
Tags aliases parent directory disk usage

I. Text editing commands

VI may be used in Linux more frequent text editor, if not proficient in the use of VI, to a certain extent, will affect the efficiency, so here to record the VI's common commands and operating methods

in [[email protected] ~]# VI carrie.txt, enter the default mode of VI, in this mode all user input is treated as a command, if VI Open Text does not exist, in the Open directory, automatically create a new document.

(1) Enter VI edit mode

In the default mode of VI, type directly into the interface:

I start editing at the cursor position;

A to start editing at the next position in the cursor position;

o Edit at the beginning of the next line of the row where the cursor is located, and insert a blank line;

ESC exits Edit and enters command mode

(2) VI Command mode

Cursor positioning

0 move the cursor to the beginning of the line

$ move cursor to end of line

/carrie from top to bottom to find content that contains Carrie, n jumps to the next; n jumps to the previous, the Find style changes to? Carrie

? + Find content start from bottom to top, n jumps to the previous; n jumps to the next, the Find style changes to/carrie

Undo and Redo

U undo previous action;

. Repeat a previous action;

Copy-paste Delete (Command mode not shown)

Nyy the next n-line content where the cursor is copied

P Paste the copied content at the cursor location

NDD Delete the next n-line content where the cursor is located

Shift+g to end of file

x Delete Current Position character

DD Delete delete entire row

Copy and paste Delete (Command mode display)

: Set number Displays line numbers

: Set Nonu suppress line numbers

: 1,3y copy first line to third row

: 1,3d Delete First row to third row

: 1,3s/str/str_new/g the first line to the third row of STR is replaced with str_new, if more than one line of STR is replaced

: 1,3s/str/str_new/the first row to the third row of Str with str_new, if there is more than one row, replace only the first one

: 1,3g/str/d Delete Row from first row to third row containing STR string

(3) Exit VI

: Q Exit VI

: q! Do not save exit

: Wq Save Exit

W Save! Enforcement action

(1) File management commands

LS, ls-l, LL, ls-a

Ls-a Show all files, including hidden files

LS enumerates subdirectories and files under the specified directory

Ls-l and ll enumerate the details of subdirectories and files under the specified directory

    • Total 56 represents the sum of the file sizes in the current directory as 56K;
    • File type: "-" for the normal file, "D" for the Directory, "L" for the connection file, "B" for the device file.
    • Each of the 9 characters is a group of 3, each representing the file owner, the user group where the file owner resides, and other users ' permissions to the file. The 3 characters in each group represent read, write, execute permissions, or "-" if none of the permissions are available.
    • The following number 2 represents the number of directory files in the directory "B"
    • User and group information
    • File size
    • File modification Time
    • File/folder name
123456789 [[email protected ] tmp]# ls-l total -rw-r-----. 1 root    Root 21225 Sep 00:56 backup -rw-r--r--. 1 root   root   Sep 01:24 backup.sh -rw-------. 1 root   root  2199 23:46 Bi Trock_installer.log -rw-r--r--. 1 higkoo root   586 sep  1 17:34 m_ Agent_daemonnyfycc.log drwx------. 2 root   root  4096 Sep 20 18:22 ssh-vafida1108 -rw-r--r--. 1 root   root    Sep 14 01:37 Sss.txt -rw-r--r--. 1 root   root   182 Sep + 22:50 tomcat.sh

Alias gives the command a nickname, example: Alias Rm=rm-rf, and only takes effect once. To take effect more than once, new aliases in the/ROOT/.BASHRC file

The CD changes the current directory or handles the relative of the Absolute directory

CD return: Back to the current user's personal directory
CD/: Back to the root directory
Cd.. /xx: Back to the parent directory of the XX directory
CD.: Stay in current directory
Cd.. : Return to Parent directory
cd–: Go back to the last action directory
CD ~: Back to the user home directory

PWD Displays the current path

CP Copy the specified file to another file or directory, for example: CP-RF a.txt/tmp

-B: Create a backup If the destination file exists
-R: If there are subdirectories in the source, the files and directories under the subdirectories are also copied to the destination directory
-I: If the destination has duplicate files, ask whether to overwrite
-F: Overwrite the original file if there are duplicate files in the destination

The MV is used to rename a file or directory, or to move a file from one directory to another, for example: Move all Files under/usr/local/tomcat to/tmp/tomcat, mv/usr/local/tomcat/*/tem/tomcat

Example: Renaming a.txt to B.TXT,MV a.txt b.txt

-I: Interactive mode operation. If the MV operation will result in overwriting an existing target file, then the system asks whether to overwrite it, asking the user to answer "y" or "n", which avoids overwriting the file by mistake.
-F: Disables interactive operation. MV operation to overwrite an existing target file without giving any indication, after specifying this parameter the I parameter will no longer work.

RM is used to delete files or directories, for example: delete all files under/tmp/logs, rm-rf/tmp/logs/*,* means delete all contents of current directory

-R: Delete directories and subdirectories, directories and files will be deleted if there are subdirectories
-F: Do not ask for direct deletion

mkdir Create a folder, Mkdir-p/usr/tmp/carrie, create a folder with the name Carrie, and if the parent directory for the folder ancestor does not exist, create the parent directory

Cat is used to connect and display information about one or more of the files specified

Tail view end of file,-F dynamic Read

Dynamic View Log tail-f Err.log
View the end of 10 rows of logs tail-10f Err.log
Dynamically view the end of the 5-line log tail-5f Err.log

ln creates a file link

Linux, each file corresponds to a unique index node on the file system
Hard Links
A file can have multiple filenames, each of which is a hard link that points to an index node in the file system where the destination file is located, and the hard link points to the same physical location, so that a hard link can be established between files in the same file system
Hard links can be considered file aliases, and when all hard links are deleted, the files are actually deleted.
The directory cannot establish a hard link, otherwise the directory traversal will fall into a dead loop
ln source file hard-link destination file
Soft connection
Contains path information for the destination file or directory
A soft connection can span a file system or connect to a directory
Shortcut equivalent to Windows
Ln-s source file Soft-connect directory or file

Du file and directory disk usage space

Du-sh displaying disk usage for files and directories, output in megabytes

Df-h The disk space used by the class that displays the disk partition, in k,m,g to improve readability

LOSF list files that are currently open by the system

Lsof-i: 80 querying open files on specified ports
Lsof-p PID Query the specified PID open file

CHOMD assigning permissions to files or files or folders

-R recursion, which is used primarily for a directory, to assign permissions to all files/folders under this directory

Digital way:

D[rw-] The current user [r--] belongs to the group [r--] other users,

d---folder, r---Read permission, w---Write permission, x---Execute permission

1234567 [[email protected] tmp]# lltotal 56-rw-r-----. 1 root   root 21225 Sep 15 00:56 backup-rw-r--r--. 1 root   root   250 Sep 15 01:24 backup.sh-rw-------. 1 root   root  2199 Aug 21 23:46 bitrock_installer.log-rw-r--r--. 1 higkoo root   586 Sep  1 17:34 m_agent_daemonNyFyCC.logdrwx------. 2 root   root  4096 Sep 20 18:22 ssh-vaFIDa1108

Text mode:

U – Owner of the file;
G-Persons belonging to the same group (group) as the owner of the file;
O-persons other than others;
A--all
+--Increase permissions
---Remove permissions

Chown changing the file owner and owning group

Note: Only the file owner and Superuser can use this command

-R recursive processing, processing all files and subdirectories under the specified directory

Wc-l count rows

(2) Search command

| Pipe break, bar The result of the previous command gives the latter command

Ps-ef Show All Processes

grep displays matching rows in the file

-V output does not contain rows modified by fields

-I ignores case

-W matches the difference between the specified character grep-w Tmocat and grep Tomcat

Find files in Directory

-name file name, which can be followed by a wildcard character

Find/-name Carrie query file named Carrie file under directory

Find/-name carrie* the file with the directory under the query file name that starts with Carrie

-ctime days, file last modified at the top of the number of days before the negative numbers indicate

-user user name, directory and file belonging to the user

(3) Archive compression command

Zip [options] Compressed file name a list of documents that need to be compressed

-R recursive compression to compress all files and subdirectories under the specified directory

Unzip [options] compress file names

-O overwrites files that already exist and does not require user confirmation
-D directory name unzip the compressed file to the specified directory

Tar file packaging

tar[parameter] destination file source directory or file

-C: Create a new document
-X: Extracting archive files
-F file name: Using an archive file
-Z: Unzip with gzip
-V: Verbose output mode

Tar zcvf test.tar test# compression
Tar zxvf Test.tar #解压缩

(4) Background running process

Running in the background:

Add & after the command, indicating that it is running in the background, if the terminal is closed, the background command with & is closed together

Nohup command &, indicates that the terminal is shut down and the background process continues to run

Crontab Scheduled Tasks

Crontab–e Open the Crontab configuration file in edit mode.

The format of the crontab file is "M H d M D cmd". where m stands for minutes (0~59), H for hours (0~23), D for Day (1~31), M for month (1~12), d for Day of week (0~6,0 for Sunday). CMD represents the program to run, * represents every minute of execution

Example:

* * * * * * sh/opt/lampp/test.sh means to execute test.sh this script every minute
*/5 * * * * * sh/opt/lampp/test.sh means to execute test.sh this script every 5 minutes
* * * * * */usr/local/apache/bin/apachectl restart means 21:30 restart Apache per night

Linux Common 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.