ls -l # 详细列出目录内容【包括权限、所有者、大小等】ls -a # 显示隐藏文件
cd .. # 返回上一层目录cd ~ # 切换到用户主目录cd / # 切换到根目录cd Documents/Projects # 切换到当前目录下的Documents/Projects
mkdir new_folder # 创建一个新目录mkdir -p /path/to/new/folder # 递归创建多级目录mkdir dir1 dir2 dir3 # 一次创建多个目录
rmdir empty_dir # 删除一个空目录rmdir -v empty_dir # 删除目录并显示详细信息
cp file.txt /path/to/destination # 复制文件到指定目录cp -r dir1 /path/to/destination # 复制目录及其内容cp file1 file2 # 复制并重命名文件cp -a /source/* /destination/ # 保留属性复制所有文件,但不包含隐藏文件
mv file.txt newfile.txt # 重命名文件mv file.txt /path/to/newlocation # 移动文件到新位置mv dir1 dir2 # 移动目录并重命名mv -i file.txt existingfile.txt # 移动时提示覆盖
rm file.txt # 删除文件rm -r directory # 递归删除目录及其内容rm -f file.txt # 强制删除文件(不提示)rm -i file.txt # 删除时提示确认
cat file.txt # 显示文件内容cat file1 file2 > combined.txt # 合并文件内容cat -n file.txt # 显示行号cat /dev/null > file.txt # 清空文件内容
less file.txt # 分页显示文件内容less -N file.txt # 显示行号less file.txt | grep 'keyword' # 在分页中搜索关键词
more file.txt # 分页显示文件内容more file.txt | head -n 10 # 显示前10行more -d file.txt # 显示进度+操作提示
head -n 10 file.txt # 显示文件前10行head -c 100 file.txt # 显示文件前100个字节head file.txt # 默认显示前10行
tail -f file.log # 实时查看日志文件tail -n 20 file.txt # 显示文件最后20行
grep 'error' log.txt # 在文件中搜索'error'grep -i 'error' log.txt # 忽略大小写搜索grep -r 'error' /var/log # 递归搜索目录中的文件grep -E 'error|warning' log.txt # 搜索多个关键词
find / -name "file.txt" # 查找名为file.txt的文件find . -type d -name "dir*" # 查找以dir开头的目录find /home -user user1 # 查找属于user1的文件find . -mtime -1 # 查找1天内修改的文件
chmod 755 script.sh # 设置文件权限为755chmod -R 755 directory # 递归设置目录权限chmod u+x file.sh # 增加文件的执行权限chmod o-rwx file.txt # 删除其他用户的读写执行权限