美文网首页
shell命令

shell命令

作者: 低吟浅唱1990 | 来源:发表于2019-03-04 22:24 被阅读0次

文件目录相关

  • cd 命令
cd destinaton 
destinaton用于指定想切换的目录名。
可使用绝对文件路径,另一种相对文件路径
cd /usr/bin  切换到/usr/bin目录下

cd ..  返回上一级目录

  • pwd命令 显示shell会话的当前目录
pwd
/usr/bin
  • ls 命令显示当前目录下的文件和目录
ls
Desktop Downloads Music Pictures Templates Videos
Documents examples.desktop my_script Public test_file
  • ls -F 命令区分文件和目录
Desktop/ Downloads/ Music/ Pictures/ Templates/ Videos/
Documents/ examples.desktop my_script* Public/ test_file
  • ls -a 把隐藏文件也显示出来
ls -a
. .compiz examples.desktop Music test_file
.. .config .gconf my_script Videos
.bash_history Desktop .gstreamer-0.10 Pictures .Xauthority
.bash_logout .dmrc .ICEauthority .profile .xsession-errors
.bashrc Documents .local Public .xsession-errors.old
.cache Downloads .mozilla Templates
  • ls -F -R 显示当前目录下包含的子目录中的文件

  • ls -l 显示长列表格式的输出

drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Desktop
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Documents
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Downloads
-rw-r--r-- 1 christine christine 8980 Apr 22 13:36 examples.desktop
-rw-rw-r-- 1 christine christine 0 May 21 13:44 fall
-rw-rw-r-- 1 christine christine 0 May 21 13:44 fell
-rw-rw-r-- 1 christine christine 0 May 21 13:44 fill
-rw-rw-r-- 1 christine christine 0 May 21 13:44 full
drwxr-xr-x 2 christine christine 4096 May 21 11:39 Music
-rw-rw-r-- 1 christine christine 0 May 21 13:25 my_file
-rw-rw-r-- 1 christine christine 0 May 21 13:25 my_scrapt
-rwxrw-r-- 1 christine christine 54 May 21 11:26 my_script
-rw-rw-r-- 1 christine christine 0 May 21 13:42 new_file
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Pictures
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Public
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Templates
-rw-rw-r-- 1 christine christine 0 May 21 11:28 test_file
drwxr-xr-x 2 christine christine 4096 Apr 22 20:37 Videos
  • touch 创建空文件
touch test_one
ls -l test_one
-rw-rw-r-- 1 christine christine 0 May 21 14:17 test_one
  • cp source destination 复制文件到另一个位置
cp test_one test_two
ls -l text_*
-rw-rw-r-- 1 christine christine 0 May 21 14:35 test_one
-rw-rw-r-- 1 christine christine 0 May 21 15:15 test_two
  • cp -i source destination 强制shell询问是否需要覆盖已有文件
cp -i test_one test_two
cp:是否覆盖'test_two.txt'? y

  • mv 重命名文件
mv test_two.txt test_three.txt
ls
test_one.txt  test_three.txt
  • rm 删除文件
rm -i test_three.txt  // -i 强制询问是否删除
rm:是否删除普通空文件 'test_three.txt'? y
ls
test_one.txt

  • mkdir 创建目录
mkdir new_dir
ls -F
new_dir/  test_one.txt

  • rmdir 删除目录 默认情况下只删除空目录
rmdir new_dir
ls
test_one.txt
  • file 查看文件类型
file test_one.txt
test_one.txt: ASCII text
  • cat 显示文本文件中所有数据
cat test_one.txt
hello

this is a test file

That we'll use to test the cat command

  • cat -n test_one.txt
     1  hello
     2  
     3  this is a test file
     4  
     5  That we'll use to test the cat command

  • cat -b test_one.txt
     1  hello

     2  this is a test file

     3  That we'll use to test the cat command

相关文章

网友评论

      本文标题:shell命令

      本文链接:https://www.haomeiwen.com/subject/rwswuqtx.html