Linux初窺門徑 【持續補充】

1. 經常使用基本命令

i. 文件操做

命令 參數 格式 做用
ls a.l.h ls -alh 列出當前目錄下的文件和文件夾
ll ll 列出文件和文件夾的詳細狀況
cd cd 進入文件夾,輸入cd 和文件夾首字母,按Tab鍵便可自動補全
cat cat 查看或合併文件內容
more/less more 文件名、less 文件名 查看文件內容(一次顯示一屏),按q退出查看
head n head -n 文件名 查看文件前n行
tail n tail -n 文件名 查看文件末尾n行
wc wc 文件名 查看文件總行數
touch touch 文件名 新建一個文件
echo echo 新內容 > 文件名 以覆蓋的方式爲文件追加內容,若是文件不存在則建立
echo echo 新內容 >> 文件名 以追加的方式爲文件追加內容,若是文件不存在則建立
cp a.f.i.r.v cp 拷貝文件或目錄
mv f.i.v. 格式: mv 源文件 目標文件mv 移動文件或目錄,也能夠用於文件與目錄重命名mv 原文件名 新文件名
rm 刪除文件:rm 文件名 、遞歸方式刪除文件夾:rm -r 目錄名rm 刪除文件或目錄
mkdir p 新建文件夾:mkdir 目錄名、遞歸建立文件夾組:mkdir -p 目錄1/目錄2/目錄3 新建文件夾
rmdir rmdir 目錄名 刪除文件夾(只能刪除空文件夾!)
ln s ln -s 源文件 連接文件 建立軟連接,當源文件不存在時,連接文件失效
ln ln 源文件 連接文件 建立硬連接,一個文件有多個文件名,只有所有刪除時纔會刪除

ii. 歸檔與壓縮、解壓縮

命令 參數 格式 做用
tar c.v.f.t.x tar 打包文件,xx.tar
tar d.r 格式:tar zcvf xx.tar.gz 待壓縮的文件gzipgzipgzip 壓縮,xx.tar.gz
tar C(大寫字母C) 格式:tar zxvf 壓縮包包名tartar 解壓縮,xx.tar.gz
tar jcvf tar jcvf 壓縮包包名 待壓縮文件 壓縮bzip2格式
tar jxvf tar jxvf 壓縮包包名 解壓bzip2格式
zip r tar jxvf 壓縮包包名 壓縮zip格式

iii. 經常使用配置

命令 參數 格式 做用
which which 命令(如which ls) 查看命令位置
ps a.u.x.w.r ps 查看進程信息
top top 動態顯示進程
kill kill 殺死(終止)進程,有的進程不能直接殺死,這時須要加一個參數「-9」,表示強制結束
reboot/shutdown/init 關機重啓
df a.m.t.T df 檢測磁盤空間
ifconfig ifconfig 查看或配置網卡信息

iv. 日期操做

  • date命令

date

ii. 搜索

  • grep 文本搜索命令

grep

grep

v. 幫助

命令 格式 做用 相關
help 指令 --help 查看指令幫助
man(manual) man 指令 查看指令幫助,按q退出 manman

2. 用戶管理

詳細介紹:
鳥哥私房菜 - 第十四章、Linux 帳號管理與 ACL 權限配置php

3. 權限管理

4. 軟件安裝與卸載

5. 經常使用服務器搭建及java開發環境配置

linux搭建後端環境與服務器html

i. FTP服務器- vsftpd

安裝步驟:java

1. 安裝vsftpd服務器

sudo apt-get install vsftpd

2. 進入vsftpd.conf文件配置

sudo vi /etc/vsftpd.conf

3. 具體設置

  • 設置anonymous_enable=NO,關閉匿名上傳
  • 指定ftp上傳目錄 local_root=/home/joysoarkey/ftp
  • 容許本機登陸 local_enable=YES
  • 修改容許登陸的用戶mysql

    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list
  • 容許上傳文件到FTP服務器linux

    write_enable=YES

4. 新建文件vsftpd.chroot_list

sudo vi /etc/vsftpd.chroot_list

在其中放入被容許登陸的ubuntu用戶名sql

5. 更改權限【重要】

將/home/joysoarkey/ftp文件夾擁有者的權限減去wapache

sudo chmod u-w /home/joysoarkey/ftp

6. 重啓FTP服務器

sudo /etc/init.d/vsftpd restart

ftp

若重啓成功,則終端會顯示如下信息bootstrap

[ ok ] Restarting vsftpd (via systemctl): vsftpd.service.

在其餘機器鏈接服務器(ip地址視具體狀況而定),若顯示登陸成功則說明FTP服務正常,可使用。ubuntu

C:\Users\Soarkey>ftp 192.168.0.104
鏈接到 192.168.0.104。
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode.
用戶(192.168.0.104:(none)): joysoarkey
331 Please specify the password.
密碼:
230 Login successful.
ftp>

7. 上傳下載

上傳:put 文件名segmentfault

下載:get 文件名

有圖形化界面的開源ftp軟件:FileZilla
ftp

ii.SSH服務器 - openssh-server

1. 檢查是否已經安裝

在終端輸入ssh localhost,
若出現如下提示說明未安裝

joysoarkey@Ubuntu-PC:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

如下提示說明已經安裝

joysoarkey@Ubuntu-PC:~$ ssh localhost
joysoarkey@localhost's password: 
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-59-generic x86_64)

* Documentation:  https://help.ubuntu.com
* Management:     https://landscape.canonical.com
* Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

Last login: Sun Jul 30 20:19:51 2017 from 192.168.0.101

2. 安裝ssh-server

sudo apt-get install openssh-server

3. 遠程登陸

ssh 用戶名@IP

iii. 安裝JDK

1. 下載JDK

連接: http://www.oracle.com/technet...

2. 解壓JDK

設置存放路徑爲/opt(可自定義),
進入到root帳戶,將下載好的JDK文件拷貝到/opt目錄

cp jdk-8u144-linux-i586.tar.gz /opt

解壓

tar zxvf jdk-8u144-linux-i586.tar.gz

等待一段時間,JDK就解壓完成了。
JDK目錄下有如下文件

JDK目錄

3. 設置環境變量

在/etc/profile中進行JDK環境變量的編輯。

vi /etc/profile

在文件的最後加入如下幾行(對應的位置填你的JDK解壓目錄)【注意不要輸錯】

export JAVA_HOME=/opt/jdk1.8.0_144
export JRE_HOME=/opt/jdk1.8.0_144/jre
export PATH=$JAVA_HOME/bin:$PATH 
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

配置完成以後,必定記得要用命令source /etc/profile刷新配置文件,讓配置文件生效!!!

4. 檢驗是否安裝成功

在終端輸入java,出現如下界面說明已經安裝配置成功了!恭喜!

root@ubuntu:~$ java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32      use a 32-bit data model if available
    -d64      use a 64-bit data model if available
    -client      to select the "client" VM
    -server      to select the "server" VM
    -minimal      to select the "minimal" VM
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

5. 編寫一個java文件測試

編輯Hello.java文件

public class Hello{
      public static void main(String[] args){
            System.out.println("Hello World!");
      }
}

編譯:javac Hello.java
執行:java Hello
順利輸出:Hello World!

至此,JDK的配置已經完成!

iv. Tomcat服務器

1. 下載Tomcat

連接: http://tomcat.apache.org/down...

2. 解壓Tomcat

先將下載好的安裝包拷貝到/opt中(目錄可根據你本身喜愛而定)

cp apache-tomcat-9.0.0.M22.tar.gz /opt

解壓

tar zxvf apache-tomcat-9.0.0.M22.tar.gz

3. 啓動server服務

進入到tomcat的bin目錄下
啓動服務

./startup.sh

啓動成功後會輸出

Using CATALINA_BASE:   /opt/apache-tomcat-9.0.0.M22
Using CATALINA_HOME:   /opt/apache-tomcat-9.0.0.M22
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.0.M22/temp
Using JRE_HOME:        /opt/jdk1.8.0_144
Using CLASSPATH:       /opt/apache-tomcat-9.0.0.M22/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.M22/bin/tomcat-juli.jar
Tomcat started.

此時便可在瀏覽器中經過IP:8080訪問tomcat了。

v. 安裝mysql

vi. 安裝eclipse

6. 相關資料

相關文章
相關標籤/搜索