操作目录命令
ls
-a 显示所有文件及目录 (ls内定将文件名或目录名称开头为"."的视为隐藏档,不会列出)
-l 除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出
-r 将文件以相反次序显示
-d 只看当前目录的信息
-t 将文件依建立时间之先后次序列出
-A 同 -a ,但不列出 "." (目前目录) 及 ".." (父目录)
-F 在列出的文件名称后加一符号;例如可执行档则加 "*", 目录则加 "/"
-R 若目录下有文件,则以下之文件亦皆依序列出
列出当前目录下所有的文件:
# ls
查看当前目录的详细信息:
# ls -d
列出根目录(\)下的所有目录:
# ls /
列出当前目录下的所有文件的详细信息(单位以K、M、G显示):
# ls -lh
列出当前目录下所有的隐藏文件:
# ls -la
列出目前工作目录下所有名称是 s 开头的文件,越新的排越后面 :
# ls -ltr s*
当我们敲 la 时,实现ls -a命令:
# alias la="ls -a"
# la
当我们敲 lss 时,实现 ls -ltr s*命令:
# alias lss="ls -ltr s*"
# lss
cd
cd -:返回之前的目录
cd ..:返回到上一级目录 “.”表示当前目录,“..”表示上一级目录
cd ~:到用户所在的家目录
pwd 查看当前位置
[root@compute 1]# pwd
/root/1
du 查看目录/文件大小
-b或-bytes 显示目录或文件大小时,以byte为单位。
-k或--kilobytes 以KB(1024bytes)为单位输出。
-m或--megabytes 以MB为单位输出。
-s或--summarize 仅显示总计,只列出最后加总的值。
-h或--human-readable 以K,M,G为单位,提高信息的可读性。
[root@compute ~]# du -bsh interersting/
12K interersting/
mkdir 创建目录
-m --mode=模式,设定权限<模式> (类似 chmod),而不是 rwxrwxrwx 减 umask
-p --parents 递归创建目录
--help 显示此帮助信息并退出
[root@compute ~]# mkdir -p IG/{theshy/korea,ning/china,rookie/korea,jackeylove/china,baolan/china,duke/korea}
[root@compute ~]# ls IG/
baolan duke jackeylove ning rookie theshy
[root@compute ~]# ls IG/theshy/
korea
rm 删除目录
-d --directory 删除可能仍有数据的目录 (只限超级用户)
-f --force 略过不存在的文件,不显示任何信息
-i --interactive 进行任何删除操作前必须先确认
-r/R --recursive 同时删除该目录下的所有目录层
-v --verbose 详细显示进行的步骤
--help 显示此帮助信息并离开
--version 显示版本信息并离开
rm -rf 以递归的模式强制删除目录
[root@compute ~]# ls
1 anaconda-ks.cfg install.log.syslog test test2
3 install.log interersting test1 test3
[root@compute ~]# rm -rf test*
[root@compute ~]# ls
1 3 anaconda-ks.cfg install.log install.log.syslog interersting
cp 复制目录
cp -r 以递归的模式复制目录
-a:此选项通常在复制目录时使用,它保留链接、文件属性,并复制目录下的所有内容。其作用等于dpR参数组合。
-d:复制时保留链接。这里所说的链接相当于Windows系统中的快捷方式。
-f:覆盖已经存在的目标文件而不给出提示。
-i:与-f选项相反,在覆盖目标文件之前给出提示,要求用户确认是否覆盖,回答"y"时目标文件将被覆盖。
-p:除复制文件的内容外,还把修改时间和访问权限也复制到新文件中。
-r:若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件。
-l:不复制文件,只是生成链接文件。
[root@compute ~]# cp -r IG EDG
[root@compute ~]# ls
1 3 anaconda-ks.cfg EDG IG install.log install.log.syslog interersting
[root@compute ~]# cd EDG/&&ls
baolan duke jackeylove ning rookie theshy
[root@compute EDG]#
mv 移动目录或重命名
-b 若需覆盖文件,则覆盖前先行备份。
-f force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;
-i 若目标文件 (destination) 已经存在时,就会询问是否覆盖!
[root@compute ~]# ls interersting/
1 lily
[root@compute ~]# mv -b 1 interersting/
mv: overwrite `interersting/1'? y
[root@compute ~]# ls
3 anaconda-ks.cfg EDG IG install.log install.log.syslog interersting
[root@compute ~]# ls interersting/
1 1~ lily
mv 重命名
[root@compute interersting]# ls
1 1~ lily
[root@compute interersting]# mv 1~ 2
[root@compute interersting]# ls
1 2 lily