linux—命令汇总

pwd                   # 显示当前工作目录
cd /tmp             # cd切换工作目录
pwd
cd ./dir01                      # .当前工作目录
cd ../dir02                     # ..上层工作目录
cd -                              # -前一个工作目录
cd ~                             # ~当前用户的家目录
cd ~   用户名               # 用户的家目录
pwd

mkdir /tmp/sampledir                  #创建名为sampledir的目录
cd /tmp/sampledir
pwd
cd ..
mkdir -p /tmp/dirlevel01/dirlevel0101             # -p创建嵌套目录
pwd
rmdir /sampledir                                            # 删除sampledir目录
cd sampledir
cd /sampledir
rmdir dirlevel01                                            # rmdir只能删除空目录

cd /tmp
ls /etc/passwod                                           # ls列出文件
ls /etc                                                          # 列出目录下的所有文件
ls                                                                 # 列出当前目录下所有文件
ls -a                                                            # 列出所有文件,包括隐藏文件
ls -l                                                             # 以长格式列出文件
ls -al
nano ./hello.sh                                          # nano打开文件
./hello.sh
su - nboocer01                                        # su切换用户
cd /tmp
ls -l
ls -l /tmp
chmod 700 hello.sh                               # chmod修改文件属性
ls -l ./hello.sh
su - root
chown nbcc:stu hello.sh                       # chown修改文件拥有者和从属用户组
chown stu hello.sh
chown :stu hello.sh

cd ~
ls
cp /tmp/file01 ~                             # cp拷贝文件
ls
cp /tmp/file01 ~/file01_bak
ls
cp /tmp/file02 /tmp/file03 /tmp/file04 ~
cp -r /tmp/dir01 ~                                                          # cp -r 拷贝目录
\cp -f /tmp/file02 /tmp/file03 /tmp/file04 ~                     # \cp -f拷贝时强制覆盖所用同名文件
ls -l /tmp/sample.sh ~
cp /tmp/sample.sh ~nbcc
ls -l ~nbcc/sample.sh
cp -p /tmp/sample.sh ~nbcc                                       # cp -p 不改变文件属性。(登录用户对该文件有写权限才能使用该命令)
mv                                                                              # mv移动文件,与cp类似。不加参数。强制覆盖重名文件是mv -f。
mv ./file08 ./file08_rename                                        #  mv用于重命名文件,Linux没有专门的重命名文件命令
ls 
rm                                                                              # rm删除文件
rm ./file01 ./file02
rm -R ./dir01                                                              # rm -R 删除目录
rm -fR ./dir02/                                                            # rm -fR 不询问,直接删除文件
cd /tmp
ls
touch ./empty                                                          # touch 创建空文件
ls
touch ./sample.sh                                                  # sample.sh 为原有文件,则会改变时间戳属性
ls -l ./sample.sh

ls -l /tmp/hello.sh
ln -s /tmp/hello.sh ./hello_slink                             # ln -s 创建链接。为hello.sh创建一个名为hello_slink的符号链接。
ls -l ./hello_slink
rm /tmp/hello.sh
ls -l ./hello_slink
./hello_slink
ls -il #ls -i 列出文件的inode-number
ln                                                                         # ln 创建硬链接
ln /tmp/sample.txt ./sample_hl01
ls -il /tmp/sample.txt ./sample_hl01
ln /tmp/sample.txt ./sample_hl02
ls -il /tmp/sample.txt ./sample_hl01 ./sample_hl02
rm /tmp/sample.txt
ls -il
cat ./sample_hl01 #
cat ./sample_hl02

ls -l /tmp
tar -cf samplefile.tar /tmp/file01 /tmp/file02 /tmp/file03 /tmp/file04 /tmp/file05 #tar 打包文件
ls -l /tmp
tar -cf samp;edir01.tar /tmp/sampledir01 #tar打包目录
ls -l
tar -tf ./samplefile.tar                                                                        # tar -tf查看打包的文件
tar -f ./samplefile.tar --delete tmp/file05                                           # 删除打包文件中的一个文件
tar -f ./samplefile.tar
tar -f ./sampledir01.tar -A ./samplefile.tar                                        # 合并打包文件(后到前中)
tar -tf .sampledir01.tar
tar -f ./sampledir01.tar -r ~/fileA.txt                                                 # 向打包文件添加一个新文件
tar -tf .sampledir01.tar
ls
ls ./sampledir
tar -xf ./sampledir01.tar -C ./sampledir                                          # 解包文件,默认解包到到当前目录,-C解包到指定目录
ls -Rl ./sampledir

ls -l
gzip ./sampledir.tar                                                                       # gzip压缩文件 只能压缩单个文件,不能压缩目录或多个文件,因此常与tar连用
ls -l
gzip -d ./sampledir.tar.gz                                                             # 解压文件
ls -l
gzip -9 samplefile01                                                                   # 压缩比9
gzip samplefile01                                                                       # 默认压缩比6
gzip -1 samplefile01                                                                   # 压缩比1
tar -caf sample.tar.gz /tmp/samplefile01 /tmp/samplefile02 /tmp/samplefile03 #打包时同时压缩
ls -l
tar -xzf sample.tar.gz                                                               # 解包时同时解压缩
ls -l

locate .tar #locate查找文件
updatedb #更新文件数据库
find / -name password #find查找文件,-name文件名
find /bin -type l #-type 根据文件类型查找
date
find /tmp -mtime -3 -ls #在/tmp目录下查找3天之内内容改变过的文件
find /tmp -mtime +7 -ls #在/tmp目录下查找7天前内容改变过的文件
find /tmp -mtime 4 -ls #在/tmp目录下查找4天前那一天内容改变过的文件
find /tmp -size -3k -ls #在/tmp目录下查找小于3k字节的文件
find /tmp -size +100c -ls #在/tmp目录下查找大于100k字节的文件
find /tmp -size 10M -ls #在/tmp目录下查找大小正好为10M字节的文件
find /tmp -user root -ls #在/tmp目录下查找拥有者为root的文件
find /tmp -uid 500 -ls #在/tmp目录下查找拥有者id为500的文件
find /tmp -group stu -ls #在/tmp目录下查找从属于stu用户组的文件
find /tmp -gid 0 -ls #在/tmp目录下查找从属于gid为0的用户组的文件
find /tmp -perm 754 -ls #查找754权限的文件
find /tmp \(-size +lk -a -size -10M -a -mmin -30 -a -type f \) -ls #多个条件查找。-a与,-o或,!非。
find /tmp \(-size +lk -a -size -10M \) -exec rm -rf {} \; #-exec 对查找到的文件进行操作。相同功能-OK,每次执行前都提示

ls /tmp
rm -f /tmp/*.txt # 通配符*,表示任意长度字符串(包括0长度)
ls -l /bin/??sh # 通配符?,表示单个字符串
ls ~
cp /tmp/file[0-9].txt ~ #通配符[],匹配[]内任意单一字符
chmod 700 /tmp/script[a,1,x].sh
ls -l /tmp
rm -rf {jiaoben,script}*.sh #通配符{},
tar -cf file .tar /tmp/file[!0-9].txt #通配符!,取反。

cat /etc/password #cat 查看文件
less /var/log/messages #less 查看文件。 之后键入/root,可以找到root,用n跳转到下一个root处,N跳转到上一个root处,q退出less,回到命令行
head/tail -n 20 /var/log/messages #查看messages文件前/后20行。不跟-n和参数,默认显示前/后10行

猜你喜欢

转载自www.cnblogs.com/Lengjie/p/9590805.html