Linux command summary 2

​​​​It feels very complete, just show it to yourself~~ 

1. Basic commands

uname -m 显示机器的处理器架构uname -r 显示正在使用的内核版本dmidecode -q 显示硬件系统部件(SMBIOS / DMI) hdparm -i /dev/hda 罗列一个磁盘的架构特性hdparm -tT /dev/sda 在磁盘上执行测试性读取操作系统信息arch 显示机器的处理器架构uname -m 显示机器的处理器架构uname -r 显示正在使用的内核版本dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI)hdparm -i /dev/hda 罗列一个磁盘的架构特性hdparm -tT /dev/sda 在磁盘上执行测试性读取操作cat /proc/cpuinfo 显示CPU info的信息cat /proc/interrupts 显示中断cat /proc/meminfo 校验内存使用cat /proc/swaps 显示哪些swap被使用cat /proc/version 显示内核的版本cat /proc/net/dev 显示网络适配器及统计cat /proc/mounts 显示已加载的文件系统lspci -tv 罗列 PCI 设备lsusb -tv 显示 USB 设备date 显示系统日期cal 2007 显示2007年的日历表date 041217002007.00 设置日期和时间 - 月日时分年.秒clock -w 将时间修改保存到 BIOS

2. Shut down

shutdown -h now 关闭系统(1)init 0 关闭系统(2)telinit 0 关闭系统(3)shutdown -h hours:minutes & 按预定时间关闭系统shutdown -c 取消按预定时间关闭系统shutdown -r now 重启(1)reboot 重启(2)logout 注销

3. Files and Directories

cd /home 进入 '/ home' 目录'
cd .. 返回上一级目录
cd ../.. 返回上两级目录
cd 进入个人的主目录
cd ~user1 进入个人的主目录
cd - 返回上次所在的目录
pwd 显示工作路径
ls 查看目录中的文件
ls -F 查看目录中的文件
ls -l 显示文件和目录的详细资料
ls -a 显示隐藏文件
ls *[0-9]* 显示包含数字的文件名和目录名
tree 显示文件和目录由根目录开始的树形结构(1)
lstree 显示文件和目录由根目录开始的树形结构(2)
mkdir dir1 创建一个叫做 'dir1' 的目录'
mkdir dir1 dir2 同时创建两个目录
mkdir -p /tmp/dir1/dir2 创建一个目录树
rm -f file1 删除一个叫做 'file1' 的文件'
rmdir dir1 删除一个叫做 'dir1' 的目录'
rm -rf dir1 删除一个叫做 'dir1' 的目录并同时删除其内容
rm -rf dir1 dir2 同时删除两个目录及它们的内容
mv dir1 new_dir 重命名/移动 一个目录
cp file1 file2 复制一个文件
cp dir/* . 复制一个目录下的所有文件到当前工作目录
cp -a /tmp/dir1 . 复制一个目录到当前工作目录
cp -a dir1 dir2 复制一个目录
ln -s file1 lnk1 创建一个指向文件或目录的软链接
ln file1 lnk1 创建一个指向文件或目录的物理链接
touch -t 0712250000 file1 修改一个文件或目录的时间戳 - (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
iconv -l 列出已知的编码
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)

4. File search

find / -name file1 从 '/' 开始进入根文件系统搜索文件和目录find / -user user1 搜索属于用户 'user1' 的文件和目录find /home/user1 -name \*.bin 在目录 '/ home/user1' 中搜索带有'.bin' 结尾的文件find /usr/bin -type f -atime +100 搜索在过去100天内未被使用过的执行文件find /usr/bin -type f -mtime -10 搜索在10天内被创建或者修改过的文件find / -name \*.rpm -exec chmod 755 '{}' \; 搜索以 '.rpm' 结尾的文件并定义其权限find / -xdev -name \*.rpm 搜索以 '.rpm' 结尾的文件,忽略光驱、捷盘等可移动设备locate \*.ps 寻找以 '.ps' 结尾的文件 - 先运行 'updatedb' 命令whereis halt 显示一个二进制文件、源码或man的位置which halt 显示一个二进制文件或可执行文件的完整路径

5. Mount a file system

mount /dev/hda2 /mnt/hda2 挂载一个叫做hda2的盘 - 确定目录 '/ mnt/hda2' 已经存在
umount /dev/hda2 卸载一个叫做hda2的盘 - 先从挂载点 '/ mnt/hda2' 退出
fuser -km /mnt/hda2 当设备繁忙时强制卸载
umount -n /mnt/hda2 运行卸载操作而不写入 /etc/mtab 文件- 当文件为只读或当磁盘写满时非常有用
mount /dev/fd0 /mnt/floppy 挂载一个软盘
mount /dev/cdrom /mnt/cdrom 挂载一个cdrom或dvdrom
mount /dev/hdc /mnt/cdrecorder 挂载一个cdrw或dvdrom
mount /dev/hdb /mnt/cdrecorder 挂载一个cdrw或dvdrom
mount -o loop file.iso /mnt/cdrom 挂载一个文件或ISO镜像文件
mount -t vfat /dev/hda5 /mnt/hda5 挂载一个Windows FAT32文件系统
mount /dev/sda1 /mnt/usbdisk 挂载一个usb 捷盘或闪存设备
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share 挂载一个windows网络共享

6. Disk space

df -h 显示已经挂载的分区列表
ls -lSr |more 以尺寸大小排列文件和目录
du -sh dir1 估算目录 'dir1' 已经使用的磁盘空间'
du -sk * | sort -rn 以容量大小为依据依次显示文件和目录的大小
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n 以大小为依据依次显示已安装的rpm包所使用的空间 (fedora, redhat类系统)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n 以大小为依据显示已安装的deb包所使用的空间 (ubuntu, debian类系统)

​​​​​​​7. Users and Groups

groupadd group_name 创建一个新用户组
groupdel group_name 删除一个用户组
groupmod -n new_group_name old_group_name 重命名一个用户组
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 创建一个属于 "admin" 用户组的用户
useradd user1 创建一个新用户
userdel -r user1 删除一个用户 ( '-r' 排除主目录)
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 修改用户属性
passwd 修改口令
passwd user1 修改一个用户的口令 (只允许root执行)
chage -E 2005-12-31 user1 设置用户口令的失效期限
pwck 检查 '/etc/passwd' 的文件格式和语法修正以及存在的用户
grpck 检查 '/etc/passwd' 的文件格式和语法修正以及存在的群组
newgrp group_name 登陆进一个新的群组以改变新创建文件的预设群组

8. File permissions, use "+" to set permissions, use "-" to cancel

ls -lh 显示权限
ls /tmp | pr -T5 -W$COLUMNS 将终端划分成5栏显示
chmod ugo+rwx directory1 设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限
chmod go-rwx directory1 删除群组(g)与其他人(o)对目录的读写执行权限
chown user1 file1 改变一个文件的所有人属性
chown -R user1 directory1 改变一个目录的所有人属性并同时改变改目录下所有文件的属性
chgrp group1 file1 改变文件的群组
chown user1:group1 file1 改变一个文件的所有人和群组属性
find / -perm -u+s 罗列一个系统中所有使用了SUID控制的文件
chmod u+s /bin/file1 设置一个二进制文件的 SUID 位 - 运行该文件的用户也被赋予和所有者同样的权限
chmod u-s /bin/file1 禁用一个二进制文件的 SUID位
chmod g+s /home/public 设置一个目录的SGID 位 - 类似SUID ,不过这是针对目录的
chmod g-s /home/public 禁用一个目录的 SGID 位
chmod o+t /home/public 设置一个文件的 STIKY 位 - 只允许合法所有人删除文件
chmod o-t /home/public 禁用一个目录的 STIKY 位
chmod +x 文件路径 为所有者、所属组和其他用户添加执行的权限
chmod -x 文件路径 为所有者、所属组和其他用户删除执行的权限
chmod u+x 文件路径 为所有者添加执行的权限
chmod g+x 文件路径 为所属组添加执行的权限
chmod o+x 文件路径 为其他用户添加执行的权限
chmod ug+x 文件路径 为所有者、所属组添加执行的权限
chmod =wx 文件路径 为所有者、所属组和其他用户添加写、执行的权限,取消读权限
chmod ug=wx 文件路径 为所有者、所属组添加写、执行的权限,取消读权限

9. Special attributes of the file, use "+" to set permissions, use "-" to cancel

chattr +a file1 只允许以追加方式读写文件chattr +c file1 允许这个文件能被内核自动压缩/解压chattr +d file1 在进行文件系统备份时,dump程序将忽略这个文件chattr +i file1 设置成不可变的文件,不能被删除、修改、重命名或者链接chattr +s file1 允许一个文件被安全地删除chattr +S file1 一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘chattr +u file1 若文件被删除,系统会允许你在以后恢复这个被删除的文件lsattr 显示特殊的属性

10. Packing and Compressing Files

bunzip2 file1.bz2 解压一个叫做 'file1.bz2'的文件
bzip2 file1 压缩一个叫做 'file1' 的文件
gunzip file1.gz 解压一个叫做 'file1.gz'的文件
gzip file1 压缩一个叫做 'file1'的文件
gzip -9 file1 最大程度压缩
rar a file1.rar test_file 创建一个叫做 'file1.rar' 的包
rar a file1.rar file1 file2 dir1 同时压缩 'file1', 'file2' 以及目录 'dir1'
rar x file1.rar 解压rar包
unrar x file1.rar 解压rar包
tar -cvf archive.tar file1 创建一个非压缩的 tarball
tar -cvf archive.tar file1 file2 dir1 创建一个包含了 'file1', 'file2' 以及 'dir1'的档案文件
tar -tf archive.tar 显示一个包中的内容
tar -xvf archive.tar 释放一个包
tar -xvf archive.tar -C /tmp 将压缩包释放到 /tmp目录下
tar -cvfj archive.tar.bz2 dir1 创建一个bzip2格式的压缩包
tar -xvfj archive.tar.bz2 解压一个bzip2格式的压缩包
tar -cvfz archive.tar.gz dir1 创建一个gzip格式的压缩包
tar -xvfz archive.tar.gz 解压一个gzip格式的压缩包
zip file1.zip file1 创建一个zip格式的压缩包
zip -r file1.zip file1 file2 dir1 将几个文件和目录同时压缩成一个zip格式的压缩包
unzip file1.zip 解压一个zip格式压缩包

11. RPM packages

rpm -ivh package.rpm 安装一个rpm包
rpm -ivh --nodeeps package.rpm 安装一个rpm包而忽略依赖关系警告
rpm -U package.rpm 更新一个rpm包但不改变其配置文件
rpm -F package.rpm 更新一个确定已经安装的rpm包
rpm -e package_name.rpm 删除一个rpm包
rpm -qa 显示系统中所有已经安装的rpm包
rpm -qa | grep httpd 显示所有名称中包含 "httpd" 字样的rpm包
rpm -qi package_name 获取一个已安装包的特殊信息
rpm -qg "System Environment/Daemons" 显示一个组件的rpm包
rpm -ql package_name 显示一个已经安装的rpm包提供的文件列表
rpm -qc package_name 显示一个已经安装的rpm包提供的配置文件列表
rpm -q package_name --whatrequires 显示与一个rpm包存在依赖关系的列表
rpm -q package_name --whatprovides 显示一个rpm包所占的体积
rpm -q package_name --scripts 显示在安装/删除期间所执行的脚本l
rpm -q package_name --changelog 显示一个rpm包的修改历史
rpm -qf /etc/httpd/conf/httpd.conf 确认所给的文件由哪个rpm包所提供
rpm -qp package.rpm -l 显示由一个尚未安装的rpm包提供的文件列表
rpm --import /media/cdrom/RPM-GPG-KEY 导入公钥数字证书
rpm --checksig package.rpm 确认一个rpm包的完整性
rpm -qa gpg-pubkey 确认已安装的所有rpm包的完整性
rpm -V package_name 检查文件尺寸、 许可、类型、所有者、群组、MD5检查以及最后修改时间
rpm -Va 检查系统中所有已安装的rpm包- 小心使用
rpm -Vp package.rpm 确认一个rpm包还未安装
rpm2cpio package.rpm | cpio --extract --make-directories *bin* 从一个rpm包运行可执行文件
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm 从一个rpm源码安装一个构建好的包
rpmbuild --rebuild package_name.src.rpm 从一个rpm源码构建一个 rpm 包

12. YUM software package upgrader

yum install package_name 下载并安装一个rpm包
yum localinstall package_name.rpm 将安装一个rpm包,使用你自己的软件仓库为你解决所有依赖关系
yum update package_name.rpm 更新当前系统中所有安装的rpm包
yum update package_name 更新一个rpm包
yum remove package_name 删除一个rpm包
yum list 列出当前系统中安装的所有包
yum search package_name 在rpm仓库中搜寻软件包
yum clean packages 清理rpm缓存删除下载的包
yum clean headers 删除所有头文件
yum clean all 删除所有缓存的包和头文件

13. deb package

dpkg -i package.deb 安装/更新一个 deb 包dpkg -r package_name 从系统删除一个 deb 包dpkg -l 显示系统中所有已经安装的 deb 包dpkg -l | grep httpd 显示所有名称中包含 "httpd" 字样的deb包dpkg -s package_name 获得已经安装在系统中一个特殊包的信息dpkg -L package_name 显示系统中已经安装的一个deb包所提供的文件列表dpkg --contents package.deb 显示尚未安装的一个包所提供的文件列表dpkg -S /bin/ping 确认所给的文件由哪个deb包提供APT 软件工具 (Debian, Ubuntu 以及类似系统)apt-get install package_name 安装/更新一个 deb 包apt-cdrom install package_name 从光盘安装/更新一个 deb 包apt-get update 升级列表中的软件包apt-get upgrade 升级所有已安装的软件apt-get remove package_name 从系统删除一个deb包apt-get check 确认依赖的软件仓库正确apt-get clean 从下载的软件包中清理缓存apt-cache search searched-package 返回包含所要搜索字符串的软件包名称

14. View file contents

cat file1 从第一个字节开始正向查看文件的内容tac file1 从最后一行开始反向查看一个文件的内容more file1 查看一个长文件的内容less file1 类似于 'more' 命令,但是它允许在文件中和正向操作一样的反向操作head -2 file1 查看一个文件的前两行tail -2 file1 查看一个文件的最后两行tail -f /var/log/messages 实时查看被添加到一个文件中的内容

15. Text processing

cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt 合并一个文件的详细说明文本,并将简介写入一个新文件中
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt 合并一个文件的详细说明文本,并将简介写入一个已有的文件中
grep Aug /var/log/messages 在文件 '/var/log/messages'中查找关键词"Aug"
grep ^Aug /var/log/messages 在文件 '/var/log/messages'中查找以"Aug"开始的词汇
grep [0-9] /var/log/messages 选择 '/var/log/messages' 文件中所有包含数字的行
grep Aug -R /var/log/* 在目录 '/var/log' 及随后的目录中搜索字符串"Aug"
sed 's/stringa1/stringa2/g' example.txt 将example.txt文件中的 "string1" 替换成 "string2"
sed '/^$/d' example.txt 从example.txt文件中删除所有空白行
sed '/ *#/d; /^$/d' example.txt 从example.txt文件中删除所有注释和空白行
echo 'esempio' | tr '[:lower:]' '[:upper:]' 合并上下单元格内容
sed -e '1d' result.txt 从文件example.txt 中排除第一行
sed -n '/stringa1/p' 查看只包含词汇 "string1"的行
sed -e 's/ *$//' example.txt 删除每一行最后的空白字符
sed -e 's/stringa1//g' example.txt 从文档中只删除词汇 "string1" 并保留剩余全部
sed -n '1,5p;5q' example.txt 查看从第一行到第5行内容
sed -n '5p;5q' example.txt 查看第5行
sed -e 's/00*/0/g' example.txt 用单个零替换多个零
cat -n file1 标示文件的行数
cat example.txt | awk 'NR%2==1' 删除example.txt文件中的所有偶数行
echo a b c | awk '{print $1}' 查看一行第一栏
echo a b c | awk '{print $1,$3}' 查看一行的第一和第三栏
paste file1 file2 合并两个文件或两栏的内容
paste -d '+' file1 file2 合并两个文件或两栏的内容,中间用"+"区分
sort file1 file2 排序两个文件的内容
sort file1 file2 | uniq 取出两个文件的并集(重复的行只保留一份)
sort file1 file2 | uniq -u 删除交集,留下其他的行
sort file1 file2 | uniq -d 取出两个文件的交集(只留下同时存在于两个文件中的文件)
comm -1 file1 file2 比较两个文件的内容只删除 'file1' 所包含的内容
comm -2 file1 file2 比较两个文件的内容只删除 'file2' 所包含的内容
comm -3 file1 file2 比较两个文件的内容只删除两个文件共有的部分

16. Character settings and file format conversion

dos2unix filedos.txt fileunix.txt 将一个文本文件的格式从MSDOS转换成UNIXunix2dos fileunix.txt filedos.txt 将一个文本文件的格式从UNIX转换成MSDOSrecode ..HTML < page.txt > page.html 将一个文本文件转换成htmlrecode -l | more 显示所有允许的转换格式

17. File system analysis

badblocks -v /dev/hda1 检查磁盘hda1上的坏磁块fsck /dev/hda1 修复/检查hda1磁盘上linux文件系统的完整性fsck.ext2 /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性e2fsck /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性e2fsck -j /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性fsck.ext3 /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性fsck.vfat /dev/hda1 修复/检查hda1磁盘上fat文件系统的完整性fsck.msdos /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性dosfsck /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性

18. Initialize a file system

mkfs /dev/hda1 在hda1分区创建一个文件系统mke2fs /dev/hda1 在hda1分区创建一个linux ext2的文件系统mke2fs -j /dev/hda1 在hda1分区创建一个linux ext3(日志型)的文件系统mkfs -t vfat 32 -F /dev/hda1 创建一个 FAT32 文件系统fdformat -n /dev/fd0 格式化一个软盘mkswap /dev/hda3 创建一个swap文件系统

19. SWAP file system

mkswap /dev/hda3 创建一个swap文件系统swapon /dev/hda3 启用一个新的swap文件系统swapon /dev/hda2 /dev/hdb3 启用两个swap分区

20. Backup

dump -0aj -f /tmp/home0.bak /home 制作一个 '/home' 目录的完整备份
dump -1aj -f /tmp/home0.bak /home 制作一个 '/home' 目录的交互式备份
restore -if /tmp/home0.bak 还原一个交互式备份
rsync -rogpav --delete /home /tmp 同步两边的目录
rsync -rogpav -e ssh --delete /home ip_address:/tmp 通过SSH通道rsync
rsync -az -e ssh --delete ip_addr:/home/public /home/local 通过ssh和压缩将一个远程目录同步到本地目录
rsync -az -e ssh --delete /home/local ip_addr:/home/public 通过ssh和压缩将本地目录同步到远程目录
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' 通过ssh在远程主机上执行一次备份本地磁盘的操作
dd if=/dev/sda of=/tmp/file1 备份磁盘内容到一个文件
tar -Puf backup.tar /home/user 执行一次对 '/home/user' 目录的交互式备份操作
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' 通过ssh在远程目录中复制一个目录内容
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' 通过ssh在远程目录中复制一个本地目录
tar cf - . | (cd /tmp/backup ; tar xf - ) 本地将一个目录复制到另一个地方,保留原有权限及链接
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents 从一个目录查找并复制所有以 '.txt' 结尾的文件到另一个目录
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 查找所有以 '.log' 结尾的文件并做成一个bzip包
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 做一个将 MBR (Master Boot Record)内容复制到软盘的动作
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 从已经保存到软盘的备份中恢复MBR内容

21. CD-ROM

cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force 清空一个可复写的光盘内容
mkisofs /dev/cdrom > cd.iso 在磁盘上创建一个光盘的iso镜像文件
mkisofs /dev/cdrom | gzip > cd_iso.gz 在磁盘上创建一个压缩了的光盘iso镜像文件
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd 创建一个目录的iso镜像文件
cdrecord -v dev=/dev/cdrom cd.iso 刻录一个ISO镜像文件
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - 刻录一个压缩了的ISO镜像文件
mount -o loop cd.iso /mnt/iso 挂载一个ISO镜像文件
cd-paranoia -B 从一个CD光盘转录音轨到 wav 文件中
cd-paranoia -- "-3" 从一个CD光盘转录音轨到 wav 文件中(参数-3)
cdrecord --scanbus 扫描总线以识别scsi通道
dd if=/dev/hdc | md5sum 校验一个设备的md5sum编码,例如一张 CD

22. Network (Ethernet and WIFI wireless )

ifconfig eth0 显示一个以太网卡的配置
ifup eth0 启用一个 'eth0' 网络设备
ifdown eth0 禁用一个 'eth0' 网络设备
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 控制IP地址
ifconfig eth0 promisc 设置 'eth0' 成混杂模式以嗅探数据包 (sniffing)
dhclient eth0 以dhcp模式启用 'eth0'
route -n show routing table
route add -net 0/0 gw IP_Gateway configura default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16'
route del 0/0 gw IP_gateway remove static route
echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing
hostname show hostname of system
host www.example.com lookup hostname to resolve name to ip address and viceversa(1)
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2)
ip link show show link status of all interfaces
mii-tool eth0 show link status of 'eth0'
ethtool eth0 show statistics of network card 'eth0'
netstat -tup show all active network connections and their PID
netstat -tupl show all network services listening on the system and their PID
tcpdump tcp port 80 show all HTTP traffic
iwlist scan show wireless networks
iwconfig eth1 show configuration of a wireless network card
hostname show hostname
host www.example.com lookup hostname to resolve name to ip address and viceversa
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
whois www.example.com lookup on Whois database

23. List directory contents

ls -a:显示所有文件(包括隐藏文件);ls -l:显示详细信息;ls -R:递归显示子目录结构;ls -ld:显示目录和链接信息;ctrl+r:历史记录中所搜命令(输入命令中的任意一个字符);Linux中以.开头的文件是隐藏文件;pwd:显示当前目录

24. Check the file type

file:查看文件的类型

25. Copy file directory

1. cp: Copy files and directories cp source file (folder) target file (folder).

Commonly used parameters: -r: recursively copy the entire directory tree; -v: display detailed information;

When copying a folder, add a -r parameter after the cp command:

For example: cp -r source folder destination folder.

2. touch+filename: When the file does not exist, create the corresponding file; when the file exists, modify the creation time of the file.

Function: Generate an empty file or modify the access/modification time record value of the file;

touch *: Modify the current file time to the current system time;

touch –d 20040210 test: Change the date of the test file to 20040210;

touch abc: If the abc file exists, modify it to the current time of the system; if it does not exist, generate an empty file with the current time.

3. mv file target directory: move or rename the file or directory (if you specify a file name, you can rename the file). You can move files and directories to another directory, or change the names of files and directories.

The format is: mv [parameter]<source file or directory> <target file or directory>

mva.txt ../: Move the a.txt file to the upper directory

mv a.txt b.txt: Rename a.txt to b.txt

mvdir2 ../: Move the dir2 directory up one level

4. rm: delete files

Common parameters: -i: interactive -r: recursive deletion including all contents in the directory.

5. mkdir + folder name: create a folder

6. rm -r + folder name: delete the folder (both empty folders and non-empty folders can be deleted);

rmdir folder name: delete the folder (only empty folders can be deleted).

7. mkdir -p dir1/dir2: Create the dir1 directory under the current directory, and create the dir2 directory under the dir1 directory, that is, create two directories (dir1/ and dir1/dir2) in succession.

8. rmdir –p dir1/dir2: Delete the dir2 directory under dir1. If the dir1 directory is empty, delete it as well.

9. rm *: delete all files in the current directory

10. -f parameter: Forced deletion of files rm -f *.txt: Forced deletion of all files with the suffix txt.

11. -i parameter: ask when deleting files

rm –i *: Delete all files in the current directory and the following prompt will appear:

rm:backup:is a directory will be skipped when encountering a directory

rm: remove ‘myfiles.txt’ ? Y

You will be asked when deleting a file. You can press the Y or N key to allow or deny deletion of the file. 

12. -r parameter: recursive deletion (deleting subdirectories together, this is a very commonly used parameter).

rm -r test: delete the test directory (including all files and subdirectories in the test directory);

rm -r *: Delete all files (including all files in the current directory, all subdirectories and files in subdirectories). Generally, r and f are used together when deleting a directory to avoid trouble;

rm -rf test: Forced deletion without asking.

13. grep: Function: Search for matching characters in the file and output it.

Format: grep[parameter] <string to be found> <source file to be found for string>

greplinux test.txt: Search for the string linux in the test.txt file and output it.

14. ln command

Function: Establish links between files and directories

Format: ln [parameter] <source file or directory> <target file or directory>

Links are divided into "soft links" and "hard links"

1. Soft link:

ln-s /usr/share/do doc: Create a link file doc and point to the directory /usr/share/do

2. Hard link:

ln /usr/share/test hard: Create a hard link file hard. At this time, for the storage area corresponding to the test file, there is another file pointing to it.

26. Commonly used system commands

1. Display command

date: View or set the current system time: formatted display time: +%Y--%m--%d;

date -s: Set the current system time;

hwclock(clock): displays the hardware clock time (requires administrator rights);

cal: View calendar;

Format cal [parameter] month and year;

cal: displays the calendar of the current month cal4 2004: displays the calendar of April 2004;

cal-y 2003: displays the calendar of 2003;

uptime: View system running time.

2. Output the view command

echo: Display the input content. Append the file echo "liuyazhuang" >> liuyazhuang.txt

cat: displays the file contents, and can also merge several files into one file;

Format: Format: cat[parameter]<file name>

cat test.txt: Display the contents of the test.txt file;

cat test.txt | more: Display the contents of the test.txt file page by page;

cat test.txt >> test1.txt: Append the content of test.txt to the test1.txt file;

cat test.txt test2.txt >readme.txt: merge test.txt and test2.txt files into readme.txt file;

head: Display the first few lines of the file (default 10 lines) -n: Specify the number of lines to display Format: head -n file name;

tail: Display the last few lines of the file (default 10 lines) -n: Specify the number of lines to be displayed -f: Track and display file updates (generally used to view logs, the command will not exit, but will continue to display the newly added content);

Format: Format: tail[parameter]<file name>

tail-10 /etc/passwd: Display the last 10 lines of the /etc/passwd/ file;

tail+10 /etc/passwd: Display the contents of the /etc/passwd/ file from line 10 to the end;

more: used to turn pages to display file content (can only page down);

The more command is generally used when the content to be displayed exceeds the length of one screen. In order to prevent the screen from flashing by when it is displayed, the user can use the more command to pause the screen when it displays a full page. At this time, you can press the space key to continue displaying the next screen, or press the Q key to stop displaying;

ls -al |more: Display the file list in the etc directory in long format. The display will pause after one screen is full. You can press the space bar to continue to display the next screen, or press the Q key to escape;

less: Turn pages to display the file contents (turn pages up and down). Press the up key to page, and press q to exit;

The usage of the less command is similar to the more command, and can also be used to browse files that exceed one page. The difference is that in addition to pressing the space bar to display the file downwards, the less command can also use the up and down keys to scroll the file. When you want to end browsing, just press the Q key at the prompt ":" of the less command;

ls -al | less: List all contents in the /etc directory in long format. Users can press the up and down keys to browse or press the Q key to escape.

3. View hardware information

Ispci: View PCI devices -v: View details

Isusb: view USB devices -v: view details

Ismod: View loaded modules (drivers)

4. Shut down and restart

shutdown to shut down and restart the computer

shutdown [shutdown, restart] time -h shut down the computer -r: restart the computer

For example: shut down immediately: shutdown -h now

Shut down after 10 minutes: shutdown -h +10

Shut down at 23:30: shutdown -h 23:30

Restart immediately: shutdown -r now

poweroff: shut down the computer immediately

reboot: Restart the computer immediately

5. Archiving and compression

zip: compressed file zip liuyazhuang.zip myfile format is: "zip compressed zip file file name"

unzip: Unzip the file unzip liuyazhuang.zip

gzip: compressed file gzip file name

tar: archive file

tar -cvf out.tar liuyazhuang Pack an archive (package the file "liuyazhuang" into an archive)

tar -xvf liuyazhuang.tar releases an archive (releases the liuyazhuang.tar archive)

tar -cvzf backup.tar.gz/etc  

The -z parameter gzip-compresses the archived archive to reduce size.

-c: Create a new tar file

-v: Display information about the running process

-f: Specify file name

-z: Call the gzip compression command for compression

-t: View the contents of the compressed file

-x: Unpack the tar file

tar -cvf test.tar *: Pack all files into test.tar, the extension .tar needs to be added by yourself

tar -zcvf test.tar.gz *: Pack all files into test.tar, and then use the gzip command to compress them

tar -tf test.tar: View which files are included in the test.tar file

tar -xvf test.tar Unpack test.tar

tar -zxvf foo.tar.gz decompress

gzip gunzip commands

gziptest.txt: No parameters are required when compressing files

gizp–l test.txt.gz: Display compression ratio

6. Search

locate: quickly find files and folders: locate keyword

This command requires the database to be established in advance. The database is updated once a day by default. You can use the updatedb command to manually create and update the database.

find find location search parameters

like:

find . -name *liuyazhuang* Find files containing "liuyazhuang" in their names in the current directory

find / -name *.conf Find files with the suffix .conf in the root directory (the entire hard disk)

find / -perm 777 finds all files with permission 777

find / -type d returns all directories under the root directory

find . -name "a*"-exec ls -l {} \;

find function: used to find files or directories

Format: find [<path>] [matching criteria]

find / -name httpd.conf Search for a file named httpd.conf in the system root directory

7. ctrl+c: terminate the current command

8. who or w command

Function: Check which users are logged in in the current system

Format: who/w[parameter]

9. dmesg command

Function: Display system diagnostic information, operating system version number, physical memory size and other information.

10. df command

Function: Used to view the occupancy status of each partition of the file system.

11. du command

Function: View the amount of hard disk space used by subdirectories at all levels in a directory.

Format: du [parameter] <directory name>

12. free command

Function: Used to check the size and occupation of system memory and virtual memory (swap space).

27. VIM

VIM is a powerful command line text editor. The vim editor can be started through the vim command in Linux.

Generally, vim is used in the form of vim + target file path.

If the target file exists, vim opens the target file. If the target file does not exist, vim creates and opens the file.

:q: Exit vim editor

VIM mode

vim has three modes:

(1) Command mode (regular mode)

After vim is started, it enters the command mode by default. You can return to the command mode through the esc key in any mode (you can press it several times). In the command mode, you can type different commands to complete operations such as selection, copy, paste, and undo.

Common commands for naming patterns are as follows:

i : Insert text before the cursor

o: Insert a new line below the current line

dd: delete the entire line

yy: Put the contents of the current line into the buffer (copy the current line)

n+yy: Put the contents of n lines into the buffer (copy n lines)

p: Put the text in the buffer after the cursor (paste)

u: Undo the previous operation

r: replace the current character

/ Find keywords

(2) Insert mode

Press the "i" key in command mode to enter insert mode. In insert mode, you can enter editing text content, and use the esc key to return to command mode.

(3)ex mode

Press the " : " key in command mode to enter ex mode, and the cursor will move to the bottom, where you can save changes or exit vim.

Commonly used commands in ext mode are as follows:

:w: Save current changes

:q: Exit

:q!: Force quit and save changes

:x: Save and exit, equivalent to:wq

:set number displays line number

:! System command Execute a system command and display the results

:sh: switch to the command line, use ctrl+d to switch back to vim

28. Package Management Commands (RPM)

1. Installation of software packages

Use the installation mode of the RPM command to put all the components in the software package into the correct path in the system. The command to install the software package is: rpm –ivh wu-ftpd-2.6.2-8.i386.rpm

i: Use rpm installation mode v: Verify file information h: Display the installation progress with # sign.

2. Deletion of software packages

The deletion mode will delete all the contents of the specified software package, but does not include the changed configuration files. The command to delete the RPM software package is as follows: rpm –e wu-ftpd

Note: The software name "wu-ftpd" or "wu-ftpd-2.6.2-8 must be used here instead of the originally installed software package name.wu-ftpd-2.6.2-8.i386.rpm

3. Software package upgrade

The upgrade mode will install the updated version specified by the user and delete the same software package already installed in the system. The upgrade package command is as follows: rpm –Uvh wu-ftpd-2.6.2-8.i386.rpm –Uvh: upgrade parameters .

4. Software package update

In update mode, the rpm command checks whether the software package specified on the command line is newer than the original software package in the system. If this is true, the rpm command will automatically update the specified software package; otherwise, if there is no older version of the specified software package in the system, the rpm command will not install this software package. In upgrade mode, the rpm command will install the specified software package regardless of whether there is an older version in the system.

rpm –Fvhwu-ftpd-2.6.2-8.i386.rpm -Fvh: update parameters

5. Software package query

To obtain information about RPM packages, you can use query mode. Use the -q parameter to query the contents of an installed software package.

rpm  –q wu-ftpd

Query the location where the software package is installed: rpm –ql package-name

rpm –ql xv (l parameter: display file list)

whaosoft aiot http://143ai.com  

Guess you like

Origin blog.csdn.net/qq_29788741/article/details/132923084