50个常用的Linux命令(三)基础实例


ls
ls -a
ls -l == ll
ls -Al
drwxrwxrwx.  2 root   root       6 Dec 21 20:38 Videos
-rwxrwxrwx   1 root   root    5982 Feb 21 10:26 .viminfo


1) 第一列 drwxrwxr -x ,字母d代表目录或者文件,目录directory的意思,r表示read,w表示wirte,-表示是文件,x表示文件执行权限,一般这有三组权限,前三个rwx表示该文件拥有者的权限,中间三个rwx表示文件的所有组权限,最后三个r-x,表示对其他人访问的权限(读,执行,没有写权限)。

2) 第二列 数字2表示有多少个链接指向这个文件

3) 第三列 shiyanlou是这个文件或文件夹的拥有者

4) 第四列,表示谁是这个文件或文件夹的所有组

5) 第五列,表示以字节为单位的大小,目录的大小总是4096大小

6) 第六列,文件的最后修改时间

7) 第八列,文件名或者目录名

ls -al ,列出所有文件并长格式显示

ls / 显示根目录下文件清单,你不需要cd到根目录就可以直接查看它下的文件

ls ~ , 波浪线,这个可以显示用户的家目录

ls .. 和ls ../.. 查看父目录的文件

这里不截图, ..表示上一层,如果你要返回上一层的上一层,就  ../..表示

ls -lS, 小写的L和大写的S,表示文件大小排序,S是size的意思

cat -b file1
上面的-b表示no blank,不计算空行的情况下显示行号。

cat -n file1
行数显示,空行也计算

cat -E file
显示到每行结束部分,并在每行尾部显示$符号。

cat a.sh b.sh  >d.sh
把两个文件内容拷贝到一个新文件

mkdir -p /root/william
父目录和子目录一起创建

mkdir images/{1,2,haha}
创建三个文件夹

[root@localhost images]# ls
2  haha  pics
[root@localhost images]# rmdir 2
[root@localhost images]# ls
haha  pics

先通过mkdir -p a/b/c/d/e/

然后试试 rmdir a/b/c/d/e

再通过ls -R看看效果,发现只删除了最后一个目录e

[root@localhost images]# tree
.
└── a
    └── b
        └── c
            └── d

4 directories, 0 files
[root@localhost images]# rmdir -p a/b/c/d/
[root@localhost images]# ls
[root@localhost images]#


1) mkdir -p a/b/c/d/e

2) cd a/b

3) cat > abc.txt

4) cd 到Desktop

5) rmdir -p a/b/c/d/e

发现这里,删除了c/d/e目录,由于a/b/下还有abc.txt文件,rmdir删除不了,上面p代表父目录,v表示版本,通过v可以看到删除的历史记录,
是一个一个目录删除。

rm -r a/b 全部删除
ls -R

rm -r 强制删除一个目录下所有文件和路径

[root@localhost test_cat]# ls
a.sh  b.sh  c.sh  d.sh  images
[root@localhost test_cat]# cp a.sh b.sh c.sh images/
[root@localhost test_cat]# ls
a.sh  b.sh  c.sh  d.sh  images
[root@localhost test_cat]# cd images/
[root@localhost images]# ls
a.sh  b.sh  c.sh

[root@localhost test_cat]# tree
.
├── a.sh
├── b.sh
├── c.sh
├── d.sh
└── images
    ├── a.sh
    ├── b.sh
    └── c.sh

1 directory, 7 files
[root@localhost test_cat]# cp a.sh b.sh c.sh images/
cp: overwrite ‘images/a.sh’? y
cp: overwrite ‘images/b.sh’? y
cp: overwrite ‘images/c.sh’? y
[root@localhost test_cat]# mkdir will
[root@localhost test_cat]# touch will/test.sh
[root@localhost test_cat]# cp will/ images/
cp: omitting directory ‘will/’
[root@localhost test_cat]# cp -vR will/ images/
‘will/’ -> ‘images/will’
‘will/test.sh’ -> ‘images/will/test.sh’
[root@localhost test_cat]# tree
.
├── a.sh
├── b.sh
├── c.sh
├── d.sh
├── images
│   ├── a.sh
│   ├── b.sh
│   ├── c.sh
│   └── will
│       └── test.sh
└── will
    └── test.sh

3 directories, 9 files

原文地址:https://www.cnblogs.com/william126/p/10416253.html