這篇筆記是筆者整理的一些簡單有用的 Linux 命令,供平時查閱。shell
# change file mod chmod +rwx file chmod 777 file # 數字模式是使用二進制計算出來的,三位分別表明 owner,group,others,4 - r, w - 2, x - 1,則 7 = 4 + 2 + 1 = rwx chown -c root ./hello.txt # change owner to root chgrp -c root ./hello.txt # change group to root # change login shell: chsh # or edit /etc/passwd. # get /etc/passwd file in cygwin system: mkpasswd -c | sed -e 'sX/bashX/zshX' | tee -a /etc/passwd
# 顯示文本文件,展現,查看文件開頭部分,查看文件尾 cat file | less head file tail file # find [path] [expr] find /var /usr -name "*.pdf" # use -iname to ignore A or a find /var -name "*.pdf" -a "*.txt" # -a means and find /var -name "*.pdf" -type d # d means dir find /var -name "*.pdf" -size +100c # +100c means more than 100 chars. find .name "*.sh" -type f -exec cat {} \; # run `cat` for all finded files. find . -type f -mmin -10 # any file changed in passed 10 minute. find . -ctime -10 # change time, by day. ctime = change time, mtime = modified time, atime = access time. locale # like find, but much speeder becase of using a datebase(update once perday). # Search bin file path in PATH which progName # Search bin file path in system whereis progName apropos # 尋找具備 XXX 功能的命令 type CMD # make sure where a cmd from, bash or exec.
ln source_file target_dir # make soft link: ln -s source_file_or_dir target_dir tar -cvf to_filename form_dir # 自動識別後綴名壓縮 tar -tvf filename # 自動識別後綴名瀏覽文件內容 tar -xvf filename # 自動識別後綴名解壓 # tar 其餘選項: c:建立,x:解壓,t:查看 # !!! Very useful !!! # also work on mac # check finder's disk usage du -sh ./*
userdel username useradd username groupadd groupname groupdel groupname
ps # list all process top # an interact program to manage process lsof # list opened files kill 234 # kill a process by pid nice # run a program with modified scheduling priority renice # alter priority of running process
history # command history id # my uid gid etc. fsck.ext4 -p /dev/sdb1 # rapair EXT4 file system