2017年7月19日 星期三

Linux Base Command Example

Linux Base Command Example

推薦觀看:

鳥哥的Linux私房菜

結構筆記

N|Solid

目錄結構圖片




             man 查看指令說明

In [ ]:
man pwd

pwd 查看目前所在目錄

In [1]:
pwd
/Users/pellok/github/pellok/linux_command/jupyter

cd 切換目錄指令

  • ./ 代表當前目錄
  • ../ 上層目錄
In [ ]:
man cd
In [3]:
cd ../
total 2
dr-xr-xr-x   2 root  wheel     1  7  6 13:49 .
drwxr-xr-x  33 root  wheel  1190  5 25 04:03 ..

單打 cd 會回到家目錄

In [4]:
cd
pwd
/Users/pellok

mkdir 創建目錄

  • -p 創建多層級目錄
In [14]:
cd //Users/pellok/github/pellok/linux_command/jupyter
mkdir linux_command
ls -al
total 32
drwxr-xr-x  5 pellok  staff    170  7 19 13:56 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  15633  7 19 13:55 base.ipynb
drwxr-xr-x  2 pellok  staff     68  7 19 13:56 linux_command
In [17]:
cd //Users/pellok/github/pellok/linux_command/jupyter
mkdir -p linux_command/1/2/3
ls -al
total 16
drwxr-xr-x  5 pellok  staff   170  7 19 13:59 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  5147  7 19 13:59 base.ipynb
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command
In [18]:
cd linux_command
ls -al
total 0
drwxr-xr-x  3 pellok  staff  102  7 19 13:59 .
drwxr-xr-x  5 pellok  staff  170  7 19 14:00 ..
drwxr-xr-x  3 pellok  staff  102  7 19 13:59 1
In [19]:
cd 1
ls -al
total 0
drwxr-xr-x  3 pellok  staff  102  7 19 13:59 .
drwxr-xr-x  3 pellok  staff  102  7 19 13:59 ..
drwxr-xr-x  3 pellok  staff  102  7 19 13:59 2

rmdir 刪除空資料夾

  • -p 刪除多層空目錄
In [15]:
rmdir linux_command
ls -al
total 32
drwxr-xr-x  4 pellok  staff    136  7 19 13:56 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  15633  7 19 13:55 base.ipynb
In [20]:
cd //Users/pellok/github/pellok/linux_command/jupyter
rmdir -p linux_command
ls -al
rmdir: linux_command: Directory not empty
total 16
drwxr-xr-x  5 pellok  staff   170  7 19 14:00 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  5298  7 19 14:00 base.ipynb
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command

touch 創建檔案

In [21]:
touch filename
ls -al
total 16
drwxr-xr-x  6 pellok  staff   204  7 19 15:09 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  6722  7 19 14:01 base.ipynb
-rw-r--r--  1 pellok  staff     0  7 19 15:09 filename
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command

rm刪除

  • -r dir 刪除目錄
  • -f file 強制刪除檔案
  • -rf dir 強制刪除目錄(注意很恐怖)
In [22]:
rm filename
ls -al
total 16
drwxr-xr-x  5 pellok  staff   170  7 19 15:09 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  6722  7 19 14:01 base.ipynb
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command
In [23]:
touch test
ls -al
total 24
drwxr-xr-x  6 pellok  staff   204  7 19 15:18 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  9643  7 19 15:13 base.ipynb
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command
-rw-r--r--  1 pellok  staff     0  7 19 15:18 test
In [24]:
rm -f test
ls -al
total 24
drwxr-xr-x  5 pellok  staff   170  7 19 15:18 .
drwxr-xr-x  4 pellok  staff   136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff   102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  9643  7 19 15:13 base.ipynb
drwxr-xr-x  3 pellok  staff   102  7 19 13:59 linux_command
In [31]:
mkdir -p folder/1/2/3/4/5
ls -al
total 24
drwxr-xr-x  6 pellok  staff    204  7 19 15:21 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  12172  7 19 15:19 base.ipynb
drwxr-xr-x  3 pellok  staff    102  7 19 15:21 folder
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command
In [32]:
rm -r folder
ls -al
total 24
drwxr-xr-x  5 pellok  staff    170  7 19 15:21 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  12172  7 19 15:19 base.ipynb
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command
In [36]:
mkdir folder
touch folder/file
ls -al
total 24
drwxr-xr-x  6 pellok  staff    204  7 19 15:21 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  12172  7 19 15:19 base.ipynb
drwxr-xr-x  3 pellok  staff    102  7 19 15:21 folder
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command
In [37]:
rm -rf folder
ls -al
total 24
drwxr-xr-x  5 pellok  staff    170  7 19 15:21 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  12172  7 19 15:19 base.ipynb
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command

cp source destination 複製檔案

  • -r 複製目錄
In [38]:
touch file
cp file file2
ls -al
total 32
drwxr-xr-x  7 pellok  staff    238  7 19 15:40 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  13362  7 19 15:39 base.ipynb
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file2
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command
In [39]:
mkdir folder
cp -r folder folder2
ls -al
total 32
drwxr-xr-x  9 pellok  staff    306  7 19 15:40 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  13362  7 19 15:39 base.ipynb
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file2
drwxr-xr-x  2 pellok  staff     68  7 19 15:40 folder
drwxr-xr-x  2 pellok  staff     68  7 19 15:40 folder2
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command

ln 連結檔案

  • -s source_file target_link 創建 file檔案 連結到 link
In [41]:
ln -s folder3 folder
ls -al
ln: folder/folder3: File exists
total 32
drwxr-xr-x  9 pellok  staff    306  7 19 15:41 .
drwxr-xr-x  4 pellok  staff    136  7 19 12:01 ..
drwxr-xr-x  3 pellok  staff    102  7 19 12:10 .ipynb_checkpoints
-rw-r--r--  1 pellok  staff  14732  7 19 15:41 base.ipynb
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file
-rw-r--r--  1 pellok  staff      0  7 19 15:40 file2
drwxr-xr-x  3 pellok  staff    102  7 19 15:42 folder
drwxr-xr-x  2 pellok  staff     68  7 19 15:40 folder2
drwxr-xr-x  3 pellok  staff    102  7 19 13:59 linux_command

cat 查看檔案,印出檔案所有資料

相近指令:more、less
In [44]:
echo "1234" > text.txt
cat text.txt
1234

head 列出前十行

  • -n 指定行數
In [45]:
echo "5678" >> text.txt
head text.txt
1234
5678
In [46]:
head -n 1 text.txt
1234

tail 列出最後端十行

  • -n 指定行數
  • -f 一直顯示最後幾行,直到下中斷指令ctrl + c
In [47]:
echo "90123" >> text.txt
tail -n 1 text.txt
90123
In [ ]:
tail -2f text.txt
5678
90123

1 則留言:

  1. Las Vegas Hotel & Casino - MJH
    The Las Vegas Hotel & Casino is the ultimate destination for 사천 출장마사지 entertainment, gaming, shopping, dining and more. Book your 속초 출장마사지 staycation 대전광역 출장마사지 now!Location: 5.0 Rating: 4.3 · ‎14 reviews · ‎Price range: 포항 출장마사지 from 하남 출장샵 9.8

    回覆刪除