1:vim編寫文件並保存
進入cenos7後,右鍵,打開Terminal,輸入 su ,回車,進入root用戶,【root@localhost conf】#,輸入yum -y install vim
1.1.#vi test.java :進入test.java文件。此時進入的是命令模式。點擊‘insert’進入編輯模式,編輯完後,點擊‘esc’,退出編輯模式,‘:q!’不保存直接退出,‘:wq’保存並退出【#vi +2 test.java 進入文本最後一行;#vi + text.java.進入文本最後一行。】; 進入命令模式後,:/aa 查找文件test.java是否含有aa字符。 進入命令模式後, :$ 查看文本的最後一行,:3,同調到第3含。。
1.2 :輸入i,進入編輯模式,如果要之間進入文本的最後一行。輸入
【如果想退出root權限用戶,可按Ctrl+D鍵,即可退出到你登入的用戶[helloword@localhost Desktop]$ 】
2:查看文件中的內容:
cat fileName :直接輸出文件中的內容
vi fileName:進入vi編輯模式;
sort -u fileName:去重複輸出文件中的內容。
sort fileName | uniq -d:顯示有重複的記錄
sort fileName | uniq -c:顯示無重複的記錄,並編號。
sed -n '$=' fileNam :統計文本行數
3:jiang一個文件中的內容複製到另一箇中?
eg:複製 usr/test04中的內容到usr/test05:
:vim usr/test05【打開test05】---》進入命令模式:r!cat usr/test04,保存並退出,完成了把test04的內容複製到test05.
4:創建文件夾和文件:
[root@localhost Desktop]# mkdir usrou //會在桌面生成一個usrou的文件夾
[root@localhost Desktop]# mkdir usrou/file //會在usrou下生成file文件夾
[root@localhost Desktop]# touch usrou/file.java //會在usrou下生成file.java文件
5:查看目錄下文件
[root@localhost Desktop]# ls /usr //會輸出usr目錄下的所有文件,同理,ls /usr/bin/ 會輸出usr/bin下的所有文件。
6:查看文件路徑:
[ouyang@localhost Desktop]$ find $PWD -name "shell01.sh" 【“”的shell01.sh爲自己的文件名】暗處
7:刪除文件【eg:centos中你的桌面文件】:
1):用pwd文件查看當前用戶全路徑[eg:/home/myusername];2):用ls命令查看當前路徑有哪些文件 夾【可以看到有一個Desktop文件】;3)rm /home/muusername/Desktop/xxx.java. 4):文件移入Trash文件夾後用:sudo rm -rf /home/yourname/.local/share/Trash/ 清空垃圾箱。
8:移動文件位置
9:更改文件名:mv oldfilename newfilename
10:查看centos中虛擬機中與本機的共享文件:vmware-hgfsclient【此外共享文件被放在/mnt/hgfs/目錄下】
11:清空日誌文件:#echo "">catalina.out 【要進入catalina.out所在目錄】
12:查看文件性質:#ls -l fileName 輸出: 共有10個字符,第一個字符就是代表文件的類型,如果是文件,第一個字符就是-(短橫槓),如果是文件夾,第一個字符就是d(小寫字母D)。
12:複製文件到指定的目錄:
1):進入要複製文件的指定目錄【eg: /home/ouyang/test.java】:#cd /home/ouyang
2):指定要目標路徑並複製:#cp test.java /home/ouyang2
則文件夾下/home/ouyang2目錄下就會有新增文件test.java.
【root@localhost Desktop】echo -e "\e[1;31m This is red word\e[0m" 【注:-e 與 “”之間有空格,否則沒有效果出現;2:引號內部後面的[0m:代表顏色作用行數,0一行,1就有兩行,........】
[helloword@localhost Desktop]$ echo -e "\e[3;31mThis is what color\e[0m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[0m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[2m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[0m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[0m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[1m"
This is what color
[helloword@localhost Desktop]$ echo -e "\e[13;31mThis is what color\e[0m"
【優秀博客鏈接:http://blog.csdn.net/felix_f/article/details/12433171】
echo -n :不要自動換行
[helloword@localhost Desktop]$ echo
[helloword@localhost Desktop]$ echo -n
[helloword@localhost Desktop]$
【優秀博客鏈接:http://blog.163.com/bobile45@126/blog/static/96061992201391335835172/】
prinf:輸出【1:加上\n纔會換行】
[helloword@localhost Desktop]$ printf "Hello,word\n"
Hello.word
【1:注意觀察,應該不難理解】
[helloword@localhost Desktop]$ printf "the first program printd'%s,%s'\n" ouyang fang
the first program printd'ouyang,fang'
[helloword@localhost Desktop]$ printf "the first program printd'%d+%d=%d'\n" 1 2 3
the first program printd'1+2=3'