Linux Study Notes and linux Study Notes

Source: Internet
Author: User
Tags linux shell commands

Linux Study Notes and linux Study Notes
Linux is a free and free-to-use Unix-like operating system. It is a POSIX and UNIX-based multi-user, multi-task, multi-thread and multi-CPU operating system. It can run major UNIX tool software, applications and network protocols. It supports 32-bit and 64-bit hardware. Linux inherits the network-centric Unix design philosophy and is a stable multi-user network operating system. Linux has two basic ideas: first, everything is a file; second, every software has a definite purpose. In details, the first part is that everything in the system is classified as a file, including commands, hardware and software devices, operating systems, processes, etc. For the operating system kernel, are considered to have their own features or types of files. Linux is based on Unix. To a large extent, it is because the two have similar basic ideas.Linux shell commands System commands 

Command Function Usage
Ls Display directory files Ls-al <directory>
Cd Change directory Cd <route>
Mkdir/rmdir Create/delete directory Cd <directory>
Touch Create a file Touch <file>
Date/cal System Time/Calendar  
 
Ps Display Process  
Pwd Show Current Directory  
Df/du Display memory  
Ifconfig Configuration  
Kill/reboot/shutdown Kill process/restart/shut down  
Cp/rm/mv Copy/delete/move Cp <srcouce> <destination>
 
Ssh Remote Login Ssh haoqi @ haoqi-otc
Chown/chgrp/chmod Modify permissions Chmod a + x <dir/file>
Diff Compare file differences Diff <src> <dest>
Find Search for files Find <dir>-name <file>
Ping Check connectivity Ping <IP>
Tar Compression/Decompression Tar-cvf <file.tar> compressed tar-xvf <file.tar> decompress
 
Which Search for script files Which-a <file>
Whereis Search for files Whereis <file>
  Text Processing Command  
Cat Display file content from the first line Cat [-n] <file>
Grep Regular Expression search content Grep-n 'Re' displays the row number
Cut Split each line Cut-d 'Re'-f2 split by RE, select 2
Echo Show text Echo-[ne] "string" n newline e escape is available
Sed Text replacement Sed 1, 20 s/a/B/g line 1-20 replace a with B
Awk Processing a line of text Awk '{print $1 "\ t" $3}' prints the first and third blocks of a row.
 
Tr Character conversion Tr "" \ t "replaces" "with tab
Unset Delete variable Unset <var>
Type Display command type Type <command/dir/file>
Alias/unalias Create/delete aliases Alias string1 = 'string2'
Command> file1 File2 <command File2 <"EOF" end input
Command 2> & 1/&> file3 Command2> file1 continue to add Data Stream redirection
  Regular Expression (grep '')
^ Word Word beginning Grep-n '^ the' line begins with the row
Word $ Word end Grep-n' \. $ 'is at the end of the row. Rows
. Must have any character Grep-n 'go. G' contains the rows of go_g.
\ Escape  
Word * Contains 0 to infinite characters Grep-n 'Goo * G' contains the rows of go _____ g.
[List] There must be a character in [] Grep-n 'go [oa] G' contains goog/goag
 
N1-n2 There is a character in the range Grep-n' ^ [0-9] 'indicates a number at the beginning of the row.
[^ List] Characters not in the list Grep-n' [^ a-zA-Z] 'does not contain letters
Word \ {n, m \} Repeat the word character before the n-m side Grep-n 'go \ {2, 5 \} G' rows have 2-5 o numbers.
     
     
     
  Vim operations  
I/ESC Enter edit/general mode  
N G Row n 11 GB to 11 rows
Gg/G First/last line  
Ctrl + f/B Flip pages up/down  
Home/End Beginning/end of line  
/Word? Word Search for word backward/forward /Aaa search for and locate the row where aaa is located
 
N Repeat the previous operation  
: N1, n2s/a/B/g Replacement in Normal Mode : 2, 20 s/a/B/g replace line 2-20 a with B
X Delete a character  
Dd Delete a row  
N dd Delete n rows after the cursor Delete 111111 rows in 1111dd for clearing
N yy Copy n rows after the cursor 11yy
 
P Copy to cursor location  
U Undo the previous operation, similar to ctrl + z  
: Wq/wq! In normal mode, save and exit vim  
: Set nu Set the row mark  
: R/w <file> Read and Write another file : R a.txt
Judgment statement []The judgment statement is generally identified using brackets []. The comparison between values and variables is also different, and there is a fixed format. Brackets and content must be separated by spaces, for example, judge whether string1 and string2 are equal. If it is true, return 0. ["String1" = "string2"]  Comparison of integer values without <> =
-Eq Equal [N1-eq n2]
-Ne Not equal  
-Lt Less than litter  
-Le Less than or equal  
-Gt Greater than great  
-Ge Greater than or equal  
Judge variables and strings
-D Is the variable a directory? [-D/directory]
-Z Whether the variable has a value  
-F Is the variable a file?  
-N Whether the string is null  
     
     
 Ii. Commonly Used ubuntu commands 1. dpkg: package manager for Debian
* Installation: dpkg-I package
* Uninstall: dpkg-r package
* Uninstall and delete the configuration file dpkg-P | -- purge package
* If a package is installed. Dependent on some databases. You can first apt-get install somelib...
* View the package installation content: dpkg-L package
* Check which software package provides the file: dpkg-S filename
* In addition, dpkg also has dselect and aptitude frontend.
2. apt
* Installation: apt-get install packs
* Apt-get update: update source
* Apt-get upgrade: upgrade the system.
* Apt-get dist-upgrade: Smart upgrade. Install new software packages and delete discarded software packages
* Apt-get-f install:-f = -- fix broken to fix Dependencies
* Apt-get autoremove: automatically deletes useless software.
* Apt-get remove packages: deletes software.
* Apt-get remove package -- purge Delete the package and clear the configuration file
* Clear the residual configuration file of the deleted package: dpkg-l | grep ^ rc | awk '{print $2}' | tr ["/n"] [""] | sudo xargs dpkg-P
* Temporary directory for storing packages during software installation:/var/cache/apt/archives
* Clear the Directory: apt-get clean
* Clear the old software cache of this directory: apt-get autoclean
* Check the dependency package of some software: apt-cache depends some
* Check which packages of software some depend on: apt-get rdepends some
* Search software: apt-cache search name | regexp
* View the function of the software package: apt-cache show package
* View the compilation dependency library of a software: apt-cache showsrc packagename | grep Build-Depends
* Download the source code of the software: apt-get source packagename (Note: deb-src source should be included in sources. list)
* When installing the software package source code, install its compiling environment: apt-get build-dep packagename (with deb-src Source)
* How to add a Local CD to the installation source list: apt-cdrom add
3. system command:
* View the kernel version: uname-
* Check the ubuntu version: cat/etc/issue.
* View the NIC status: ethtool eth0
* View the memory and cpu information: cat/proc/meminfo; cat/proc/cpuinfo
(/There is a lot of system information under proc)
* Print the usage of the file system space: df-h
* View hard disk partitions: fdisk-l
* File size: du-h filename;
* View the directory size: du-hs dirname; du-h dirname indicates the size of all files in the directory.
* View memory usage: free-m |-g |-k
* View processes: ps-e or ps-aux --> display users
* Kill the process: kill pid
* Force killall-9 processname
4. network problems:
* Configure ADSL: sudo pppoeconf
* ADSL Manual dialing: sudo pon dsl-provider
* Activate ADSL: sudo/etc/ppp/pppoe_on_boot
* Disconnect ADSL: sudo poff
* Query NIC address based on IP Address: arping IP Address
* Local network information (including ip addresses) for production: ifconfig | ifconfig eth0
* View route information: netstat-r
* Disable the NIC: sudo ifconfig eth0 down
* Enable NIC: sudo ifconfig eth0 up
* Add a service: sudo update-rc.d service name defaults 99
* Deleting a service: sudo update-rc.d service name remove
* Temporarily restart a service:/etc/init. d/service name restart
* Temporarily close a service:/etc/init. d/service name stop
* Start a service temporarily:/etc/init. d/service name start
* The console displays Chinese characters: sudo apt-get install zhcon
* Find a file: whereis filename or find directory-name file name
* Transfer files through ssh
Scp-rp/path/filename username @ remoteIP:/path # copy the local file to the server
Scp-rp username @ remoteIP:/path/filename/path # download the remote file from the server to the local device
5. Compression:
* Decompress a.tar.gz: tar zxvf a.tar.gz
* Decompress a.tar.bz2: tar jxvf a.tar.bz2
* Compress the aaa bbbdirectory as xxx.tar.gz: tar zcvf xxx.tar.gz aaa bbb
* Compress the aaa bbbdirectory as xxx.tar.bz2: tar jcvf xxx.tar.bz2 aaa bbb [6] 6. Nautilus:
Special URI address
* Computer: //-all mounted devices and networks
* Network: //-browse Available Networks
* Burn: // a data virtual directory for burning CDs/DVDs
* Smb: //-available windows/samba Network Resources
* X-nautilus-desktop: //-desktop project and icon
* File: //-local file
* Trash: //-local recycle bin directory
* Ftp: //-FTP folder
* Ssh: //-SSH folder
* Fonts: //-font folder. You can drag the font file here to complete the installation.
* Themes: //-system topic folder
* Display hidden files: Ctrl + h
* Display address bar: Ctrl + l
* View installed fonts: Enter "fonts: //" in the address bar of nautilus to view all the fonts [6] on the local machine. supplement: * view all local TPCs and udp listening ports: netstat-tupln (t = tcp, u = udp, p = program, l = listen, n = numric)
* Run man-k keyword. eg: man-k user.
* You can also use apropos
* Actual disk space occupied by the Statistical file: du (du-estimate file space usage)
* Characters in the statistics file, in bytes: wc-c/-l/-w (wc-print the number of newlines, words, and bytes in files)
* View the file content: od-x/-c/... (od-dump files in octal and other formats)
I think the most useful od is the byte stream of the file: od-t x1 filename
View the file's Ascii code format: od-t c filename (the leftmost part of the statistics is the number of bytes)
* Find the location of the command file: which od output:/usr/bin/od
Check which package provides the file: dpkg-S/usr/bin/od output: coreutils:/usr/bin/od
Check all the content of the coreutils package and you will know the linux core command: dpkg-L coreutils
Then info coreutils Haha, learn it carefully. The whole world is a command!
* You can use the man command to view the interpretation of all sections of a command: man-a tty
Then use q, and next to convert to the next section.
* Bash shortcut keys:
Ctrl + a: move the cursor to the beginning of the line.
Ctrl + B: move the cursor to the left
Ctrl + c: Kill the current process.
Ctrl + d: exit the current Shell.
Ctrl + e: move the cursor to the end of the row.
Ctrl + h: Delete the character before the cursor, which is the same as the backspace key.
Ctrl + k: Clear the content from the cursor to the end of the row.
Ctrl + l: clear screen, equivalent to clear.
Ctrl + r: Search for commands that have been used before. There will be a prompt to search for bash history based on the keyword you entered
Ctrl + u: Clear all content from the front of the cursor to the beginning of the line.
Ctrl + w: Remove a word before the cursor
Ctrl + t: two characters before the cursor position
Ctrl + y: paste or restore the last Deletion
Ctrl + d: Delete the letter where the cursor is located. Note the difference with backspace and ctrl + h. The two are the characters before the cursor is deleted.
Ctrl + f: move the cursor right
Ctrl + z: run the current process in the background and run the 'fg' command to restore the process. For example, top-d1, ctrl + z, go to the background, then fg, and restore
* Quick paste: first select the text in a place, and then press the mouse button in the place where you want to paste it.
* Equivalent middle key: a. Pressing the pulley is equivalent to the middle key. B. Simultaneously pressing the left and right keys is equivalent to the middle keys.
* Restart X service quickly: press Alt + Ctrl + Backspace at the same time.
* Open the "run" window: press Alt + F2 at the same time.
* Screen wear: a. Full Screen: press the PrtScr key directly.
B. Current window: press Alt + PrtScr at the same time.
C. delayed screen wear: Enter the command: gnome-screenshot -- delay 3 in the terminal or "run" window, and wear the screen after a delay of 3 seconds.
* Drag the file in the file manager to the GNOME terminal to obtain the complete path name. [6] 8. ulimit
Ulimit: displays (or sets) limits on resources that a user can use. These limits are divided into soft limits (current limits) and Hard Limits (upper limits ), the hard limit is the upper limit of the soft limit. The system resources used by the application during running cannot exceed the corresponding soft limit. Any exceeding causes the process to terminate.
Ulimited does not limit the resources that users can use, but this setting sets the maximum number of files that can be opened (max open files)
The maximum number of processes that can run simultaneously (max user processes) is invalid.
-A: List the limits of all current resources.
-C: sets the maximum value of the core file. Unit: blocks
-D. Set the maximum value of a process's data segment. Unit: kbytes
-F Shell: maximum size of the file to be created. Unit: blocks
-H specifies the hard limit of a given resource. If you have root user permissions, you can increase the hard limit. Any user can reduce the hard limit
-L maximum value of physical memory that can be locked
-M: maximum value of the resident memory that can be used. Unit: kbytes
-N maximum number of files that each process can open simultaneously
-P: sets the maximum value of the MPs queue, in the unit of block, 1 block = 512 bytes
-S indicates the maximum value of the stack. Unit: kbytes.
-S specifies the soft limit for the given resource. The soft limit can be increased to the hard limit value. If the-H and-S signs are not specified, the limit applies to the above two
-T indicates the number of seconds used by each process. Unit: seconds.
-U maximum number of concurrent processes that can be run
-V Shell indicates the maximum virtual memory available. Unit: kbytes.
Eg: ulimit-c 1000 (you can first use ulimit-c to view the original value) tips for a younger brother!

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.