[code]~$ touch test.txt
使用stdout,stderr,stdin這三個標准流的原因是這可以使得接口抽象化。一個程序不用關心它是從文件,鍵盤,或者其他什麼地方獲取輸入,也不用關心它的輸出將會被顯示,或者被存儲在文件,或者其他什麼地方。
[code]~$ echo "All bears should juggle" All bears should juggle
我們利用 > 這個符號進行重定向,比如echo “Dataquest is awesome” > dataquest.txt這條語句首先將Dataquest is awesome寫到stdout中,然後重定向stdout到dataquest.txt中,最後的結果就是Dataquest is awesome這條語句將會被寫入到dataquest.txt文件中。
[code]~$ echo "All bears should juggle" > test.txt上面這條語句將All bears should juggle寫入到我們前面創建的空文件test.txt中。
[code]~$ nano test.txt # 然後就是在文件中做修改
group – users in the owner’s group. Users on unix systems can be placed into groups.everyone – all other users on the system who aren’t the user or in
the user’s group.
每個范圍可以有三種權限:
read(r) – The ability to see what’s in a file. If defined on a folder, the ability to see what files are in a folder.write(w) – The ability to modify a file. If a folder, the ability to delete, modify, and rename files in the folder.
execute(e) – The ability to run a file. Some files are executable, and need this permission to be run.你可以通過ls -l命令來查看文件和文件夾的權限。比如:
[code] ~$ ls -l total 4 -rw-r--r-- 1 dq dq 1 May 4 08:16 test.txt ''' # 這幾個rw的對應關系如下: - rw- r-- r-- Ignore User Group Everyone '''
— ——no permissions, corresponds to 0.
–x —— execute only permission, corresponds to 1.
-w- —— write only permissions, corresponds to 2.
-wx —— write and execute permissions, corresponds to 3.
r– —— read only permissions, corresponds to 4.
r-x —— read and execute permissions, corresponds to 5.
rw- —— read and write permissions, corresponds to 6.
rwx —— grants read, write, and execute permissions, corresponds to 7.
其實就是x=1,w=2,r=4通過stat命令可以將-rw-r–r–轉為0644
[code]~$ stat test.txt File: ‘test.txt’ Size: 1 Blocks: 8 IO Block: 4096 regular file Device: 100003h/1048579d Inode: 2929 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ dq) Gid: ( 1000/dq) Access: 2016-05-04 08:16:47.656025719 +0000 Modify: 2016-05-04 08:16:45.256025719 +0000 Change: 2016-05-04 08:16:45.256025719 +0000 Birth: -上面結果中從Acess中可以看到0644
[code]~$ chmod 0760 test.txt
上面這段代碼給予owner讀寫執行的權限,給予group讀寫的權限,不給everyone任何權限。
[code]~$ mkdir test ~$ mv test.txt test
上面這段代碼在用戶主目錄下創建了一個test子目錄,而test.txt是在用戶主目錄下的,因此可以直接mv過去。
[code]~$ cd test ~/test$ cp test.txt test2.txt
[code]~$ ls test ~$ cd test ~/test$ ls test2.txt test.txt ~/test$ cd ~$ mv test/test.txt test/test_no_extension ~$ cd test ~/test$ ls test2.txt test_no_extension上面這段代碼將test.txt文件移動到另一個文件中去,並且這個新的文件沒有擴展名。與前面mv不同的是這次的第二個參數是文件而前面是文件夾,在這裡移動後,源文件沒有了,新文件的內容和源文件相同,名稱是第二個參數的名稱。這也可以表明在Linux中文件是可以沒有擴展名的。
[code]~$ rm /home/dq/test/test2.txt
[code]~$ sudo mkdir tt sudo: unable to change to root gid: Operation not permitted上面這段代碼顯示當前linux不允許執行sudo指令