Today, I bring you a very comprehensive article summarizing Linux commands. It is also a very frequently used operation command in our daily work. There are a lot of commands. It is recommended that friends collect it first and then read it.
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
shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours:minutes & 按预定时间关闭系统 shutdown -c 取消按预定时间关闭系统 shutdown -r now 重启(1) reboot 重启(2) logout 注销
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)
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 显示一个二进制文件或可执行文件的完整路径
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网络共享
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类系统)
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 登陆进一个新的群组以改变新创建文件的预设群组
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 文件路径 为所有者、所属组添加写、执行的权限,取消读权限
chattr +a file1 只允许以追加方式读写文件 chattr +c file1 允许这个文件能被内核自动压缩/解压 chattr +d file1 在进行文件系统备份时,dump程序将忽略这个文件 chattr +i file1 设置成不可变的文件,不能被删除、修改、重命名或者链接 chattr +s file1 允许一个文件被安全地删除 chattr +S file1 一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘 chattr +u file1 若文件被删除,系统会允许你在以后恢复这个被删除的文件 lsattr 显示特殊的属性
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格式压缩包
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 包
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 删除所有缓存的包和头文件
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 返回包含所要搜索字符串的软件包名称
cat file1 从第一个字节开始正向查看文件的内容 tac file1 从最后一行开始反向查看一个文件的内容 more file1 查看一个长文件的内容 less file1 类似于 'more' 命令,但是它允许在文件中和正向操作一样的反向操作 head -2 file1 查看一个文件的前两行 tail -2 file1 查看一个文件的最后两行 tail -f /var/log/messages 实时查看被添加到一个文件中的内容
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 比较两个文件的内容只删除两个文件共有的部分
dos2unix filedos.txt fileunix.txt 将一个文本文件的格式从MSDOS转换成UNIX unix2dos fileunix.txt filedos.txt 将一个文本文件的格式从UNIX转换成MSDOS recode ..HTML < page.txt > page.html 将一个文本文件转换成html recode -l | more 显示所有允许的转换格式
牛逼啊!接私活必备的 N 个开源项目!赶快收藏
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文件系统的完整性
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文件系统
mkswap /dev/hda3 创建一个swap文件系统 swapon /dev/hda3 启用一个新的swap文件系统 swapon /dev/hda2 /dev/hdb3 启用两个swap分区
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内容
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
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
ls -a:显示所有文件(包括隐藏文件); ls -l:显示详细信息; ls -R:递归显示子目录结构; ls -ld:显示目录和链接信息; ctrl+r:历史记录中所搜命令(输入命令中的任意一个字符); Linux中以.开头的文件是隐藏文件; pwd:显示当前目录
file:查看文件的类型
1、cp:复制文件和目录 cp 源文件(文件夹)目标文件(文件夹)
常用参数:-r:递归复制整个目录树;-v:显示详细信息;
复制文件夹时要在 cp 命令后面加一个-r 参数:
如:cp -r 源文件夹 目标文件夹
2. touch file name: When the file does not exist, create the corresponding file; when the file exists, modify the creation time of the file. In addition, when searching for public accounts, Linux should learn how to reply "monkey" in the background and get a surprise gift package.
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 Change to 20040210
touch abc : If the abc file exists, it will be modified to the current time of the system; if it does not exist, an empty file with the current time will be generated
3, mv file target directory: Move or rename the file or directory (if the file name is specified, the file can be renamed). You can move files and directories to another directory, or change the names of files and directories.
##The format is: mv [parameter]
## mva.txt ../: Move the a.txt file to the upper directorymv a.txt b.txt: Rename a.txt to b.txt
mvdir2 ../: Move the dir2 directory up one level
4, rm: Delete files;
Commonly used parameters: -i: interactive -r: recursive Delete all contents in the include directory
5, mkdir Folder name: Create folder;
6, rm -r folder name: Delete the folder (both empty and non-empty folders can be deleted)
rmdir folder Name: Delete folder (only empty folders can be deleted)
7, mkdir -p dir1/dir2: Create the dir1 directory in 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 too
9, rm *: Delete all files in the current directory
10, -f parameter : Forced deletion File rm –f *.txt: Force the deletion of all txt files with the extension
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 Skip
rm: remove 'myfiles.txt' ? Y
You will be asked when deleting the file. You can press Y or N to allow it. Or refuse to delete the file
12, -r parameter : recursive deletion (deleting subdirectories together, this is a very common parameter)
rm -r test: Delete the test directory (including all files and subdirectories under the test directory)
rm -r *: Delete all files (including all files in the current directory, all subdirectories and files under 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
Format: grep[parameter]
greplinux test.txt: Search for the string linux in the test.txt file and output
14, ln command
Function: Establish a link between a file and a directory
Format: ln [parameter]
Links are divided into "soft links" and "hard links"
1.Soft links:
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
date: View or set the current system time: format Customized display time: %Y--%m--%d;
date -s: Set the current system time
hwclock( clock): Display hardware clock time (requires administrator rights);
cal: View calendar
Format cal [Parameter] Month Year
cal: Display the calendar of the current month cal4 2004: Display the calendar of April 2004
cal- y 2003: Display the calendar of 2003
uptime: Check the system running time
echo: Display the input content and append the file echo "liuyazhuang" >> liuyazhuang.txt
cat: displays the file content, and can also merge several files into one file.
Format: Format: cat[parameter]
cat test.txt: Display test.txt file content
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 the 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 file The last few lines (default 10 lines) -n: Specify the number of displayed lines -f: Track 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]
##tail-10 /etc/passwd: Display the reciprocal of the /etc/passwd/ file 10 lines of content
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 turn pages down)
The more command is generally used when the content to be displayed exceeds the length of one screen. In order to avoid the screen flashing when it is displayed, the user can use the more command to pause the screen when a full page is displayed. At this time, the user can press the space bar 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. It will pause after displaying one screen. You can press the space bar to continue to display the next screen, or press Q Key jump away
less: Turn pages to display the file content (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. , can also be used to browse documents 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 less command prompt ":".
ls -al | less: List all contents in the /etc directory in long format. The user can press the up and down keys to browse or press the Q key to escape
Ispci: View PCI device -v: View Detailed information
Isusb: View USB device -v: View detailed information
Ismod: View loaded module (driver)
shutdown Shutdown and restart the computer
shutdown[关机、重启]时间 -h 关闭计算机 -r:重启计算机
如:立即关机:shutdown -h now
10 分钟后关机:shutdown -h +10
23:30 分关机:shutdown -h 23:30
立即重启:shutdown -r now
poweroff:立即关闭计算机
reboot:立即重启计算机
zip:压缩文件 zip liuyazhuang.zip myfile 格式为:“zip 压缩后的 zip 文件文件名”
牛逼啊!接私活必备的 N 个开源项目!赶快收藏
unzip:解压文件 unzip liuyazhuang.zip
gzip: compressed file gzip file name
tar: archive file
tar -cvf out.tar liuyazhuang pack one Archive (package the file "liuyazhuang" into an archive)
tar -xvf liuyazhuang.tar Release an archive (release the liuyazhuang.tar archive)
tar -cvzf backup.tar.gz/etc
#-z parameter gzip compresses the archived archive file to reduce the size.
-c: Create a new tar file
-v: Display information about the running process
-f: Specify the file name
-z: Call the gzip compression command for compression
-t: View the contents of the compressed file
-x: Unzip 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
##tar -tf test.tar: Check which files are included in the test.tar file
tar -xvf test.tar Unzip test.tar
tar -zxvf foo.tar.gz Unzip
gzip Each gunzip command
gziptest.txt: When compressing a file, no parameters are required
gizp–l test.txt.gz: Display compression rate
locate: Quickly find files and folders: locate keyword
This command requires a database to be established in advance , the database is updated once a day by default, and the updatedb command can be used to manually create and update the database. Welcome to follow us, the official account will last forever.
find Find location search parameters
For example:
find . -name liuyazhuangFind files with "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 Find all files with permission 777
find / -type d Return all directories under the root directory
find . -name "a*"-exec ls -l {} ;
find Function: Used to find files or directories.
Format: find [
find / -name httpd.conf Search the system root directory File named httpd.conf
Function: Check which users are logged in in the current system
Format: who/w[parameter]
Function: Display system diagnostic information, operating system version number, physical memory size and other information
Function: Used to check the occupancy of each partition of the file system
Function: View the amount of hard disk space used by subdirectories at all levels in a directory
##Format: du [parameter]
Function: Used to check the size and occupancy of system memory and virtual memory (swap space)
VIM is a powerful command line text editor. The vim editor can be started through the vim command in Linux.
Generally use vim in the form of the target file path
If the target file exists, vim will open the target file, if the target file does not exist , then 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. In any mode, you can return to the command mode through the esc key (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: In the current line Insert a new line below;
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 placing the cursor (paste)
u: Undo the previous operation
r: Replace the current character
/ Search keyword
(2) Insert mode
#Press the "i" key in command mode to enter insert mode, and you can enter in insert mode Edit 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, the cursor It will move to the bottom, where you can save changes or exit vim.
Common commands in ext mode are as follows:
:w: Save the current Modify
:q: Exit
:q!: Force exit, save the modification
:x: Save and exit, equivalent to:wq
:set number Display line number
:! System command executes a system command and displays the result
:sh: Switch to the command line and use ctrl d to switch back to vim
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 the installation mode of rpm v: Verify file information h: Display the installation progress with
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
The upgrade mode will install the updated version specified by the user and delete the version already installed in the system The same software package, the upgrade package command is as follows: rpm –Uvh wu-ftpd-2.6.2-8.i386.rpm –Uvh: upgrade parameters
In update mode, the rpm command will check whether the software package specified in 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; conversely, if there is no older version of the specified software package in the system, the rpm command will not install the software package. In upgrade mode, the rpm command will install the specified software regardless of whether there is an older version in the system. Package.
rpm –Fvhwu-ftpd-2.6.2-8.i386.rpm -Fvh: Update parameters
To obtain relevant information about RPM software 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)
Okay, that’s it for today. I think it’s good. If you find it useful, you can bookmark it first!
The above is the detailed content of Summary of the 600 most powerful Linux commands. For more information, please follow other related articles on the PHP Chinese website!