?
pwd? ? ? ? ? ? ? ? ? ?# 顯示當前工作目錄
cd /tmp? ? ? ? ? ? ?# cd切換工作目錄
pwd
cd ./dir01? ? ? ? ? ? ? ? ? ? ? # .當前工作目錄
cd ../dir02? ? ? ? ? ? ? ? ? ? ?# ..上層工作目錄
cd -? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # -前一個工作目錄
cd ~? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ~當前用戶的家目錄
cd ~? ?用戶名? ? ? ? ? ? ? ?# 用戶的家目錄
pwd
mkdir /tmp/sampledir? ? ? ? ? ? ? ? ? #創建名為sampledir的目錄
cd /tmp/sampledir
pwd
cd ..
mkdir -p /tmp/dirlevel01/dirlevel0101? ? ? ? ? ? ?# -p創建嵌套目錄
pwd
rmdir /sampledir? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 刪除sampledir目錄
cd sampledir
cd /sampledir
rmdir dirlevel01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # rmdir只能刪除空目錄
cd /tmp
ls /etc/passwod? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ls列出文件
ls /etc? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 列出目錄下的所有文件
ls? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 列出當前目錄下所有文件
ls -a? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 列出所有文件,包括隱藏文件
ls -l? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 以長格式列出文件
ls -al
nano ./hello.sh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # nano打開文件
./hello.sh
su - nboocer01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # su切換用戶
cd /tmp
ls -l
ls -l /tmp
chmod 700 hello.sh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# chmod修改文件屬性
ls -l ./hello.sh
su - root
chown nbcc:stu hello.sh? ? ? ? ? ? ? ? ? ? ? ?# chown修改文件擁有者和從屬用戶組
chown stu hello.sh
chown :stu hello.sh
cd ~
ls
cp /tmp/file01 ~? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# cp拷貝文件
ls
cp /tmp/file01 ~/file01_bak
ls
cp /tmp/file02 /tmp/file03 /tmp/file04 ~
cp -r /tmp/dir01 ~? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # cp -r 拷貝目錄
\cp -f /tmp/file02 /tmp/file03 /tmp/file04 ~? ? ? ? ? ? ? ? ? ? ?# \cp -f拷貝時強制覆蓋所用同名文件
ls -l /tmp/sample.sh ~
cp /tmp/sample.sh ~nbcc
ls -l ~nbcc/sample.sh
cp -p /tmp/sample.sh ~nbcc? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# cp -p 不改變文件屬性。(登錄用戶對該文件有寫權限才能使用該命令)
mv? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # mv移動文件,與cp類似。不加參數。強制覆蓋重名文件是mv -f。
mv ./file08 ./file08_rename? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #? mv用于重命名文件,Linux沒有專門的重命名文件命令
ls?
rm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # rm刪除文件
rm ./file01 ./file02
rm -R ./dir01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # rm -R 刪除目錄
rm -fR ./dir02/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # rm -fR 不詢問,直接刪除文件
cd /tmp
ls
touch ./empty? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # touch 創建空文件
ls
touch ./sample.sh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # sample.sh 為原有文件,則會改變時間戳屬性
ls -l ./sample.sh
ls -l /tmp/hello.sh
ln -s /tmp/hello.sh ./hello_slink? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ln -s 創建鏈接。為hello.sh創建一個名為hello_slink的符號鏈接。
ls -l ./hello_slink
rm /tmp/hello.sh
ls -l ./hello_slink
./hello_slink
ls -il #ls -i 列出文件的inode-number
ln? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ln 創建硬鏈接
ln /tmp/sample.txt ./sample_hl01
ls -il /tmp/sample.txt ./sample_hl01
ln /tmp/sample.txt ./sample_hl02
ls -il /tmp/sample.txt ./sample_hl01 ./sample_hl02
rm /tmp/sample.txt
ls -il
cat ./sample_hl01 #
cat ./sample_hl02
ls -l /tmp
tar -cf samplefile.tar /tmp/file01 /tmp/file02 /tmp/file03 /tmp/file04 /tmp/file05 #tar 打包文件
ls -l /tmp
tar -cf samp;edir01.tar /tmp/sampledir01 #tar打包目錄
ls -l
tar -tf ./samplefile.tar? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # tar -tf查看打包的文件
tar -f ./samplefile.tar --delete tmp/file05? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 刪除打包文件中的一個文件
tar -f ./samplefile.tar
tar -f ./sampledir01.tar -A ./samplefile.tar? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 合并打包文件(后到前中)
tar -tf .sampledir01.tar
tar -f ./sampledir01.tar -r ~/fileA.txt? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 向打包文件添加一個新文件
tar -tf .sampledir01.tar
ls
ls ./sampledir
tar -xf ./sampledir01.tar -C ./sampledir? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 解包文件,默認解包到到當前目錄,-C解包到指定目錄
ls -Rl ./sampledir
ls -l
gzip ./sampledir.tar? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# gzip壓縮文件 只能壓縮單個文件,不能壓縮目錄或多個文件,因此常與tar連用
ls -l
gzip -d ./sampledir.tar.gz? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 解壓文件
ls -l
gzip -9 samplefile01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 壓縮比9
gzip samplefile01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 默認壓縮比6
gzip -1 samplefile01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 壓縮比1
tar -caf sample.tar.gz /tmp/samplefile01 /tmp/samplefile02 /tmp/samplefile03 #打包時同時壓縮
ls -l
tar -xzf sample.tar.gz? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# 解包時同時解壓縮
ls -l
locate .tar #locate查找文件
updatedb #更新文件數據庫
find / -name password #find查找文件,-name文件名
find /bin -type l #-type 根據文件類型查找
date
find /tmp -mtime -3 -ls #在/tmp目錄下查找3天之內內容改變過的文件
find /tmp -mtime +7 -ls #在/tmp目錄下查找7天前內容改變過的文件
find /tmp -mtime 4 -ls #在/tmp目錄下查找4天前那一天內容改變過的文件
find /tmp -size -3k -ls #在/tmp目錄下查找小于3k字節的文件
find /tmp -size +100c -ls #在/tmp目錄下查找大于100k字節的文件
find /tmp -size 10M -ls #在/tmp目錄下查找大小正好為10M字節的文件
find /tmp -user root -ls #在/tmp目錄下查找擁有者為root的文件
find /tmp -uid 500 -ls #在/tmp目錄下查找擁有者id為500的文件
find /tmp -group stu -ls #在/tmp目錄下查找從屬于stu用戶組的文件
find /tmp -gid 0 -ls #在/tmp目錄下查找從屬于gid為0的用戶組的文件
find /tmp -perm 754 -ls #查找754權限的文件
find /tmp \(-size +lk -a -size -10M -a -mmin -30 -a -type f \) -ls #多個條件查找。-a與,-o或,!非。
find /tmp \(-size +lk -a -size -10M \) -exec rm -rf {} \; #-exec 對查找到的文件進行操作。相同功能-OK,每次執行前都提示
ls /tmp
rm -f /tmp/*.txt # 通配符*,表示任意長度字符串(包括0長度)
ls -l /bin/??sh # 通配符?,表示單個字符串
ls ~
cp /tmp/file[0-9].txt ~ #通配符[],匹配[]內任意單一字符
chmod 700 /tmp/script[a,1,x].sh
ls -l /tmp
rm -rf {jiaoben,script}*.sh #通配符{},
tar -cf file .tar /tmp/file[!0-9].txt #通配符!,取反。
cat /etc/password #cat 查看文件
less /var/log/messages #less 查看文件。 之后鍵入/root,可以找到root,用n跳轉到下一個root處,N跳轉到上一個root處,q退出less,回到命令行
head/tail -n 20 /var/log/messages #查看messages文件前/后20行。不跟-n和參數,默認顯示前/后10行
?