Linux 指令整理

1.【su - 用户名】 是完整的切换到一个用户环境,【su 用户名】只切换用户,不改变系统环境。如下

mes-79:~ # su oracle
oracle@mes-79:/root> ls
ls: cannot open directory .: Permission denied
oracle@mes-79:/root> cd
oracle@mes-79:~> sqlplus /nolog
If 'sqlplus' is not a typo you can run the following command to lookup the package that contains the binary:
    command-not-found sqlplus
bash: sqlplus: command not found
oracle@mes-79:~> 

2  .代表当前的目录,也可以使用 ./ 来表示; .. 代表上一层目录,也可以 ../ 来代表。

3. 28 Feb 11 15:14为源文件的创建时间,test03是cp过来的。

[root@sesprd testcp]# ls -l
total 4
-rw-r--r--. 1 oracle dba 28 Feb 11 15:14 test03
[root@sesprd testcp]# ^C [root@sesprd testcp]# ls -l --time=a total 4 -rw-r--r--. 1 oracle dba 28 Feb 12 09:51 test03

 4.硬链接(hard link)与软连接(symbolic link)

来看一段语句,ln为制作连接档指令,ln不加参数即为硬连接,ln -s 为创建软连接。硬链接不同于文件的复制,源文件的数据并没有得到复制,类似一个别名的概念,都指向相同的inode与block,这里inode为393218.硬连接不占用inode与block,而软连接二者都会占用,因为其所建立的档案为独立的新的档案。软连接相当于window系统下的快捷方式。除硬连接二者同步外,如果修改test.so,test03的内容会同样改变。

注:cp命令也可以,cp -l 硬连接,cp -s 软连接。

[root@sesprd testcp]# ln test03 testln
[root@sesprd testcp]# ll -il
total 8
393218 -rw-r--r--. 2 oracle dba 28 Feb 11 15:14 test03
393218 -rw-r--r--. 2 oracle dba 28 Feb 11 15:14 testln
[root@sesprd testcp]# cat testln
ppppwwrrrrrrrrr:rrrrrrrooor
[root@sesprd testcp]# cat test03
ppppwwrrrrrrrrr:rrrrrrrooor
[root@sesprd testcp]# ln -s test03 test.so
[root@sesprd testcp]# ls
test03  testln  test.so
[root@sesprd testcp]# cat test.so
ppppwwrrrrrrrrr:rrrrrrrooor
[root@sesprd testcp]# rm test03
rm: remove regular file ‘test03’? y
[root@sesprd testcp]# cat test.so
cat: test.so: No such file or directory
[root@sesprd testcp]# cat testln
ppppwwrrrrrrrrr:rrrrrrrooor
[root@sesprd testcp]# ls -il
total 4
393218 -rw-r--r--. 1 oracle dba  28 Feb 11 15:14 testln
393219 lrwxrwxrwx. 1 root   root  6 Feb 12 10:24 test.so -> test03
[root@sesprd testcp]# 

 5.fsck命令

用来检查与修正硬盘错误的指令。注意:通常只有身为 root 且你的系统有问题的时候才使用这个指令,否则在正常状况下使用此一指令, 可能会造成对档案的危害!通常使用这个指令的场合都是在系统出现极大的问题,导致你在 Linux 开机的时候得进入单人单机模式下进行维护的行为时,才必须使用此一指令! 另外,如果你怀疑刚刚格式化成功的硬盘有问题的时后,也可以使用 fsck 来检查一下硬盘呦!其实就有点像是 Windows 的 scandisk 啦!此外,由于 fsck 在扫瞄硬盘的时候,可能会造成部分 filesystem 的损坏,所以『执行 fsck 时, 被检查的 partition 务必不可挂载到系统上!亦即是需要在卸载的状态喔!』 常常我们会发现,在比较老旧的机器上 ( 例如鸟哥的 p-166 ),如果主机不正常的关机 (例如跳电啰!),那么硬盘很可能会出现错误的状况!这个时候 Linux 就无法正常的开机!这个时候就需要输入 root 的密码,以登入单人维护模式 (run level 1),然后下达 fsck -y /dev/hdxxx 来检查你的硬盘!等到确认成功之后,就使用 reboot 来重新启动吧!(鸟哥的linux私房菜 第274页)

6.pwd命令 建议加上-P

[root@linux ~]# pwd [-P]
参数:
-P :显示出确实的路径,而非使用连结 (link) 路径。
范例:
[root@linux ~]# pwd
/root <== 显示出目录啦~
[root@linux ~]# cd /var/mail
[root@linux mail]# pwd
/var/mail
[root@linux mail]# pwd -P
/var/spool/mail <== 怎么回事?有没有加 -P 差很多~
[root@linux mail]# ls -l /var/mail
lrwxrwxrwx 1 root root 10 Jun 25 08:25 /var/mail -> spool/mail
# 看到这里应该知道为啥了吧?因为 /var/mail 是连结档,连结到 /var/spool/mail
# 所以,加上 pwd -P 的参数后,会不以连结文件的数据显示,而是显示正确的完整路径啊!

 7.head 命令

更多命令可以使用head --help 查看

head -c 8 表示查看档案前8个字节。head -c -8 表示显示该档案除了最后8个字节以外的内容。

head -n 2 表示查看档案前2行数据。head -n -2 表示查看档案除最后2行之外的数据

head -v 显示文件名

这里注意一下head -c 8 和head  -c 9显示值,linux下换行符是 ,占一个字节。window系统下换行为 .

[root@sesprd tmp]# cat test02
ganggang
nishuo
hhhjjjjj
[root@sesprd tmp]# head  -c 8  test02
ganggang[root@sesprd tmp]# head  -c 9  test02
ganggang
[root@sesprd tmp]# head  -n 2 test02
ganggang
nishuo

[root@sesprd tmp]# head -c -9 test02
ganggang
nishuo
[root@sesprd tmp]# head -n -2 test02
ganggang
[root@sesprd tmp]#

[root@sesprd tmp]# head -v test02
==> test02 <==
ganggang
nishuo
hhhjjjjj

 

8.关于减号 - 的用途

管线命令在 bash 的连续的处理程序中是相当重要的!另外,在 log file 的分析当中也是相当重要的一环, 所以请特别留意!另外,在管线命令当中,常常会使用到前一个指令的 stdout 作为这次的 stdin , 某些指令需要用到文件名称 (例如 tar) 来进行处理时,该 stdin 与 stdout 可以利用减号 "-" 来替代,

举例来说:[root@linux ~]# tar -cvf - /home | tar -xvf -
上面这个例子是说:『我将 /home 里面的档案给他打包,但打包的数据不是纪录到档案,而是传送到 stdout; 经过管线后,将 tar -cvf - /home 传送给后面的 tar -xvf - 』。后面的这个 - 则是取用前一个指令的 stdout, 因此,我们就不需要使用 file 了!这是很常见的例子喔!注意注意!

原文地址:https://www.cnblogs.com/gudaozi/p/8443702.html