Linux basic commands

Source: Internet
Author: User
Tags clear screen parent directory save file

ls [-ALIHD] file directory query the contents of the directory:-A: Show all files, including hidden files;-L: Show file details;-I: Display inode;-h: humanized display file size;-d: View Directory properties

Directory processing commands

mkdir [-MP] to create a new directory ,-m configuration file permissions, direct settings, do not need to see umask;-p help you directly to the desired directory (including the upper directory) recursive set up.

CD directory switch directory,CD ~/CD switch home directory, cd– into the last directory, CD. /access to the parent directory; CD. Enter the current directory;

PWD (Print working directory)-P Displays the instructions for the current directory;

rmdir [-p] Directory delete directory:-P: Recursively delete directory

RM [-RF] Directory Delete directory/file:-r: Recursive delete;-F: Force Delete, do not need to ask every time

CP [-RPDA] source file/directory target directory:-r: Copy the directory (not the copy file);-P: Copy the file attributes;-d: The source file is a linked file, copy the linked file properties;-A: equivalent to-PDR (the target file and the source file are identical);

MV [-FIU] [Source files/directories] [target directory] cut (different directories) or renamed (same directory):- F: Mandatory,-i:destination exist, whether covered,-u:destination exist, and the source is newer, will update;

Common Directory Role

Bin Cgroup etc Lib Nedua nbt IoT riit sekubyx sys usr Boot dev home lost+found misc net proc sbin SRV tmp var

In the bin and sbin,usr directories under the root directory, both bin and sbin, these four directories are used to save system commands.

Boot : startup directory

Dev: Hardware Catalog

etc: configuration file directory

Home: General User Directory

Root: Super User home Directory

lib: function library for common functions

media,mnt,misc: empty directory, tape drive, CD-ROM, etc.

The proc and sys directories cannot be manipulated directly, and both directories hold the memory overload point, which is the drive letter of the memory

usr: system resource Save Directory

var: save variable Directory for system

Link command

ln-s [source file] [destination file] Link command:-S Create soft connection

Hard link: 1, have the same I node and storage block block, can be regarded as the same file, 2, can be identified through the I node, 3, cannot cross the partition, 4, can not be used for the directory, (not recommended to create a hard link)

Soft connection: 1, similar window shortcut, 2, the soft connection has its own I node and block blocks, but the data only save the source file name and I node number, do not save the source file data, 3, modify the soft connection, the source file changes, 4, delete the source file, the soft connection loses its function; 5. The permissions for a soft connection are rwxrwxrwx, but the permissions that depend on the source file

File Search Command

Locate file name: Short period, no resource consumption; disadvantage: only search file name

Find [Search scope] [search criteria (-name filename)]: Traversal from the start, consume resources, long cycle;

Find search scopes-iname file name: Case insensitive

Find search scopes-mtime/atime/ctime +10/-10 find 10 days ago/Within, modify/access/change files

Find search scope-size file size search for files of the specified size

Find search scope-inum inode lookup file for node xxx

the Find search scope-size +20k-a/-o-size 50k (-exec ls-lh {} \; The results of the search are lent to the second command processing) find and/or file size;-a: logical and;-O: Logical OR

Linux wildcard character: *: match any content;? : matches any one character; []: matches any one of the characters in brackets;

command to search for commands (cannot find files, directories)

Whereis [-BM] Command search the directorywhere the command is located:-B: Find only executable files;-m: Find only help files;

which command: search for directories and aliases of commands

Search string command

grep [-iv] string file name matches the qualifying string in the file:-I: ignores case;-V: excludes the specified string;

Help commands

The man command gets help for the specified command

Whereis command (determines whether the command is an internal command, the executable is not found is an internal command)

Help shell internal commands (only internal commands are available, external commands cannot be obtained)

Command--help

Info command For more information: Enter the sub-help page (with * sign); U: Go to the upper page; N: Enter the next Help section; p: Enter the previous help section; Q: Exit;

Compression

. zip format compression (and Window Universal)

Zip compressed file name source files compressed files

Zip-r compressed file name directory compression directory

Unzip compressed files Extract files

. gz format compression (source file disappears, cannot compress directory)

Gzip source files are compressed into. gz format and the source files disappear

Gzip-c source Files (> Compressed files are written to files) compressed into. GZ compressed files, source files reserved

gzip-d Compressed File Decompression file

. bz2 format Compression

bzip2 [-KD] Source file compressed file, source file does not save:-K: Save the source file;-D: Unzip the file

Shutdown and restart

shutdown [-CHR] Time:-C: Cancel the previous shutdown command;-h: Shutdown;-r: Restart

Other shutdown commands: Halt, Poweroff init 0

Restart command: Reboot init 6

Exit Login: Logout

Mount command

Mount to view the devices that are already mounted on the system

Mount-a automatically mounts based on the contents of the configuration file/etc/fstab

Mount [-T file System][-o Special options] Device file name mount point;-t file system: Add the file system type to specify the type of mount, you can ext3, ext4,iso9660 and other file systems;-O Special options: You can specify additional options for Mount

Mounting discs

1, mkdir/mnt/cdrom/set up mount point

2, Mount (-t iso9660 can be omitted)/dev/sr0/mnt/cdrom/

3. umount device file name or mount point (required)

Mount USB Drive

1. fdisk-l View USB drive device file name

2, mkdir/mnt/usb/set up mount point

3. Mount-t vfat/dev/sdb1/mnt/usb/mount (NTFS file system is not supported by Linux by default)

User Login View

W User name view login user information; User: Login username; TTY: Login terminal; from: Which IP address is logged in; [email protected]: login time; idle: User idle time; JCPU: Refers to the elapsed time of all processes linked to the terminal. This time does not include the past background job time, but it includes the time that the background job is currently running; PCPU: The time occupied by the current process; What: the command that is currently running;

Last query the current login and past login user information: Read the default/var/log/wtmp file data; command output user name-Login terminal-Login ip-login time-Logout time

Lastlog View the last login time for all users lastlog command is read/var/log/lastlog file content command output user name-Login terminal-Login ip-Last Login time

Shell Basics

echo [-e] Print content:-E: Output special symbols;

Script Execution Method: 1, Vim script file, 2, chmod 755 script file; 3, execute

Basic features of Bash

command aliases and shortcut keys alias Delete Unalias

Command effective Order: 1, the first order of execution with absolute or relative path execution of the command, 2, the second order to execute the alias, 3, the third order to execute the Bash internal command, 4, the fourth sequential execution according to the $PATH environment variable defined in the directory lookup order to find the first command;

Shortcut key: Ctrl + C: Force terminate the current command; Ctrl+l: clear screen; Ctrl + A: The cursor moves to the beginning of the command line, Ctrl+e: The cursor moves to the end of the command, Ctrl+u: from the position of the cursor to the beginning; Ctrl + Z: Put the command in the background; R: Search from the historical command;

Historical command

History [-CW] [Historical command Save file];-C: Empty History command;-W: Write History command in cache to history command save file ~/.bash_history

Standard output redirection

Command > file to overwrite the correct output of the command to the specified file or device

Commands >> files are appended to the correct output of the command to the specified file or device

Standard Error Output redirection

Command 2> file to overwrite the error output of the command to the specified file or device

Command 2>> file to append the error output of the command to the specified file or device

Correct output and error output are saved at the same time

Command > File 2>&1 is overridden to save the correct output and error output to the same file

Command >> file 2>&1 has been appended to save the correct output and error output to the same file

Command &> file is overridden to save the correct output and error output to the same file

Command &>> file is appended to save the correct output and error output to the same file

Command >> file 1 2>> file 2 Append the correct output to file 1, error output appended to file 2

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.