程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python developers must know the basic linux commands!

編輯:Python

As a Python developer , Just Python It's not enough .Linux It is also a language we often need to use .

In this article , I combed 11 Basic application commands , Also must learn . Let's share with you .

  1. ls command

Ls The order is Linux The most common command in , yes list Abbreviation , By default ls The command is to list the current directory , If ls Specify a different directory , The list of files and folders in the specified directory will be displayed .

Common usage ( Common parameters ):

(1) ls –l

In long format ( Only one file or directory information is displayed on each line ) List the details of files and directories , The output is as follows :

[[email protected] single]$ ls -l
total 14091544
-rw-r-----. 1 oracle oinstall 5368717312 Apr 10 10:50 sysaux02.dbf
-rw-r-----. 1 oracle oinstall 9061015552 Apr 10 08:05 users01.dbf

(2) ls –a

List all files and directories in the directory , The output is as follows :

[[email protected] single]$ ls -a
. .. sysaux02.dbf users01.dbf

(3) ls –s

List the total space occupied by the directory , And each file name and its size ( Unit is KB), The output is as follows :

[[email protected] single]$ ls -s
total 14091544
5242892 sysaux02.dbf 8848652 users01.dbf

(4) ls –lh

In long format ( Only one file or directory information is displayed on each line ), And display the total size of files and directories in an intuitive form , The output is as follows :

[[email protected] single]$ ls -lh
total 14G
-rw-r-----. 1 oracle oinstall 5.1G Apr 10 10:50 sysaux02.dbf
-rw-r-----. 1 oracle oinstall 8.5G Apr 10 08:05 users01.dbf

(5) ls –lrt

In long format ( Only one file or directory information is displayed on each line ), And sort the files and directories according to the most time , The output is as follows :

[[email protected] single]$ ls -lrt
total 14091544
-rw-r-----. 1 oracle oinstall 9061015552 Apr 10 08:05 users01.dbf
-rw-r-----. 1 oracle oinstall 5368717312 Apr 10 10:50 sysaux02.dbf

(6) ls –lrth

And “ls –lrt” comparison , Display the file size in a more intuitive way , The output is as follows :

[[email protected]ngle single]$ ls -lrth
total 14G
-rw-r-----. 1 oracle oinstall 8.5G Apr 10 08:05 users01.dbf
-rw-r-----. 1 oracle oinstall 5.1G Apr 10 10:50 sysaux02.dbf
  1. pwd command

pwd The order is Print Working Directory Abbreviation , The basic function is to print the current working directory .

Common usage ( Common parameters ):

(1) pwd

Displays the absolute path of the current directory , The output is as follows :

[[email protected] oradata]$ pwd
/u01/oradata

(2) pwd -p

Displays the physical path of the current directory . Because some directories are link After the results of the , use -P Can be displayed link The source path of , The output is as follows :

[email protected] oradata]$ cd /etc/init.d
[[email protected] init.d]$ pwd
/etc/init.d
[[email protected] init.d]$ pwd -P
/etc/rc.d/init.d
  1. cd command

cd The order is linux One of the most common commands in , Used to switch directory paths

Common usage ( Common parameters ):

(1) cd

Back to your own HOME Catalog , The output is as follows :

[[email protected] init.d]$ pwd
/etc/init.d
[[email protected] init.d]$ cd
[[email protected] ~]$ pwd
/home/oracle

(2) cd –

Return to the directory before entering this directory , The output is as follows :

[[email protected] ~]$ pwd
/home/oracle
[[email protected] ~]$ cd /u01/oradata/single
[[email protected] single]$ pwd
/u01/oradata/single
[[email protected] single]$ cd -
/home/oracle
[[email protected] ~]$ pwd
/home/oracle

(3) cd …

Go back to the previous Directory , The output is as follows :

[[email protected] ~]$ pwd
/home/oracle
[[email protected] ~]$ cd ..
[[email protected] home]$ pwd
/home

(4) cd …/…

Returns the two directories above , The output is as follows :

[[email protected] single]$ pwd
/u01/oradata/single
[[email protected] single]$ cd ../..
[[email protected] u01]$ pwd
/u01

(5) cd /u01

Switch to the specified directory path , The output is as follows :

[[email protected] /]$ cd /u01
[[email protected] u01]$ pwd
/u01
  1. grep command

grep yes global search regular expression(RE) Abbreviation , Is a powerful text search tool , It can search for text using regular expressions , And print out the matching lines .

(1) grep Command usage :

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

(2) Common parameters (OPTIONS)

-a : take binary Document to text Searching data by file

-c : Calculate find ‘ Search string ’ The number of times

-i : Ignore case differences , So case is the same

-n : Output line number by the way

-v : Reverse selection , That is to say, no ‘ Search string ’ Content line

-s: Do not display all lines that do not exist or have no matching text

–color: Add color to the key words found ( Value has :never、always、auto Three )

(3) Common regular expressions (PATTERN)

\: Ignore the original meaning of special characters in regular expressions .

^: Match the start line of the regular expression .

$: Match the end line of the regular expression .

<: From matching regular expression The line of form begins .

>: To the end of the line that matches the regular expression .

[ ]: Single character , Such as [A] namely A Meet the requirements .

[ - ]: Range , Such as [A-Z], namely A、B、C Until Z All meet the requirements .

.: All single characters .

*: Have a character , The length can be 0.

(4) Simple examples

Common usage or common parameters :

Will include passwd The character file and its line are displayed :

[[email protected] admin]$ grep -n passwd *
catexp7.sql:170: (name, userid, passwd, defrole, datats, tempts, profile#,
catzxs.sql:364: tmp := DBMS_XDB.CreateResource('/sys/xs/roles/dbms_passwd.xml',XSAUTHXSD);
csminst.sql:25:rem ywu 02/19/04 - fix bug 3434808, delete hard code passwd.

Will include 0-9 Take out the rows of numbers :

[[email protected] admin]$ grep -n '[0-9]' xsu111.sql
2:Rem $Header: rdbms/admin/xsu111.sql /main/13 2010/06/06 21:49:30 snadhika Exp $
4:Rem xsu111.sql
6:Rem Copyright (c) 2007, 2010, Oracle and/or its affiliates.
  1. cat

cat It's a text file viewing and linking tool . Look at the contents of a file , use cat Relatively simple , Namely cat Followed by the file name .

Common usage ( Parameters ):

(1)cat / file name

The simplest cat usage , Print out the whole contents of the whole document literally

(3) cat –b / file name

Print out the contents of the whole document , And number the non blank lines , Line number from 1 Start , The output is as follows :

[[email protected] admin]$ cat -b xsu111.sql |more
1 Rem
2 Rem $Header: rdbms/admin/xsu111.sql /main/13 2010/06/06 21:49:30 snadhika Exp $
3 Rem
4 Rem xsu111.sql
5 Rem
……
  1. more

similar cat command , However, it will be displayed page by page to facilitate users to read page by page , And the most basic command is to press the space bar (space) The next page shows , Press b The key will go back (back) One page shows , It also has the function of searching for strings ( And vi be similar )

[[email protected] admin]$ more test.txt
  1. echo

Echo The command is to display the values of characters or variables on the screen .

Common usage :

(1) Output string

The string to be output , Enclosed in double quotation marks , The output is as follows :

[email protected] admin]$ echo "please wait 2 minute"
please wait 2 minute

(2) Output variable value

Output $ORACLE_HOME The value of the environment variable , The output is as follows :

[[email protected] admin]$ echo $ORACLE_HOME
/dba/oracle/product/11.2.0/db_1
  1. hostname

Display and set the name of the current host system , Only have ROOT Only users with permissions can set the hostname .

Common usage :

(1) Display host name :

[[email protected] admin]$ hostname
ol6-single

(2) Resolve the corresponding host name IP Address :

Premise is /etc/hosts There is a corresponding host name in IP Address information , or DNS It can be parsed normally , The output is as follows :

[[email protected] ~]# hostname -i
192.168.2.150

(3) Temporarily set the host name :

Temporarily set the host name , After modification ,/etc/sysconfig/network In the document HOSTNAME The value remains unchanged , To permanently change the hostname , It needs to be revised /etc/sysconfig/network In file hostname Value , How to use it is as follows :

[[email protected] ~]# hostname lijunjie
[[email protected] ~]# hostname
lijunjie
  1. touch

Touch The command is used to modify the time of accessing and changing the file to the current time or the specified time , Or create a new file that doesn't exist

Common usage :

(1)touch file name

Used to create a new file , If the file name already exists , Then the modification time of the modified file is the current system time

[[email protected] admin]$ ls -l test.txt
-rw-r--r--. 1 oracle oinstall 31 Apr 11 05:18 test.txt
[[email protected] admin]$ date
Sat Apr 11 05:20:01 CST 2015
[[email protected] admin]$ touch test.txt
[[email protected] admin]$ ls -l test.txt
-rw-r--r--. 1 oracle oinstall 31 Apr 11 05:20 test.txt

(2)touch –r The source file name Destination filename

Put the time of the source file , Update to the target file , Make the time of two files the same

[[email protected] admin]$ ls -l
-rw-r--r--. 1 oracle oinstall 363 Sep 10 2014 listener.ora
-rw-r--r--. 1 oracle oinstall 31 Apr 11 05:20 test.txt
[[email protected] admin]$ touch -r listener.ora test.txt
[[email protected] admin]$ ls -lrt
-rw-r--r--. 1 oracle oinstall 31 Sep 10 2014 test.txt
-rw-r--r--. 1 oracle oinstall 363 Sep 10 2014 listener.ora

(4) touch –t yyyymmddhhmi.ss

Change the time of the document to the specified year 、 month 、 Japan 、 Hours 、 branch . second

[[email protected] admin]$ ls -l test.txt
-rw-r--r--. 1 oracle oinstall 31 Sep 10 2014 test.txt
[[email protected] admin]$ touch -t 201101012050.50 test.txt
[[email protected] admin]$ ls -l test.txt
-rw-r--r--. 1 oracle oinstall 31 Jan 1 2011 test.txt
  1. df

Df The command is used to display details of file systems and directories .

Common usage :

(1) df –a

List all file systems and mount points , The output is as follows :

[[email protected] admin]$ df -a
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 10321208 3403240 6393680 35% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
tmpfs 507124 0 507124 0% /dev/shm
/dev/sda1 198337 50193 137904 27% /boot
/dev/sda2 39015880 27626000 9407928 75% /dba
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
/dev/sdb1 51605436 15703408 33280624 33% /u01

(2)df -h

List the file systems and mount points that have been used and the size information that is easy to identify , The size information for easy identification is K、M、G Format , The output is as follows ;

[[email protected] admin]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.9G 3.3G 6.1G 35% /
tmpfs 496M 0 496M 0% /dev/shm
/dev/sda1 194M 50M 135M 27% /boot
/dev/sda2 38G 27G 9.0G 75% /dba
/dev/sdb1 50G 15G 32G 33% /u01
  1. vim|vi

Exemplar Windows Notepad on , Used to edit the contents of a file or create a new file .

Master this 11 individual Linux Basic commands , Be a qualified Python developer !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved