Linux 常用命令

Linux 常用命令收集

这篇笔记是笔者整理的一些简单有用的 Linux 命令,供平时查阅。

文件权限与用户权限

# 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
    原文作者:plus2047
    原文地址: https://segmentfault.com/a/1190000010172163
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞