Linux常用命令<按字母排序...>之A,B,C

A

alias:为自设的命令设别名

  alias ls='ls -al'
  #将ls设置为ls -al的别名

  ls  
  #执行ls -al的功能

  unalias ls
  #取消alias对ls='ls -al'的设置

-------------------------------------------------------------------------------------------------------------------

awk: awk既是命令,也是一种编程语言,awk可在文件或字符串中基于指定的规则浏览和抽取信息

语法:
命令形式: awk '/pattern/ {actions}' filename

#匹配pattern进行文本处理

Examples:

guest@NAT8897:~$ cat data.txt
8921 Alex Oracle 15
55941 Bob UNIX 5
30803 Chris .NET 7
213103 Dan Library 3
guest@NAT8897:~$ awk '{print}' data.txt   //Just actions
8921 Alex Oracle 15
55941 Bob UNIX 5
30803 Chris .NET 7
213103 Dan Library 3
guest@NAT8897:~$ awk '/A/{print}' data.txt   //Pattern and actions
8921 Alex Oracle 15
guest@NAT8897:~$ awk '{print $2,$4}' data.txt //$2,$4---print field 2 and field 4
Alex 15
Bob 5
Chris 7
Dan 3
guest@NAT8897:~$

文件形式:script.awk
#!/usr/bin/awk
#script.awk
BEGIN{
#initialization
...
}
{
#actions
...
}
END{
#results
...
}

awk -f script.awk filename

#执行awk脚本

Examples:<文件>

guest@NAT8897:~$ cat script.awk
#!/usr/bin/awk
#script.awk
{
        print $1,$2,$3,$4;
}
guest@NAT8897:~$ awk -f script.awk data.txt
8921 Alex Oracle 15
55941 Bob UNIX 5
30803 Chris .NET 7
213103 Dan Library 3
guest@NAT8897:~$ cat script.awk
#!/usr/bin/awk
#script.awk
BEGIN{
count=0;
}
{
count++;
print $0,$1*$4;
}
END{
printf("Total number of records:%d\n", count);
}
guest@NAT8897:~$ awk -f script.awk data.txt
8921 Alex Oracle 15 133815
55941 Bob UNIX 5 279705
30803 Chris .NET 7 215621
213103 Dan Library 3 639309
Total number of records:4

NF,NR

NF: 当前处理行的字段数

NR: 当前处理行的行号

***********************************************************

B

bzip2: 压缩为bz2文件

  bzip2 -z file

  #压缩成.bz2的文件

  bzip2 -d file.bz2

  #解压.bz2的文件

***********************************************************

C

cal

  #打印当前日历

--------------------------------------------------------------------------------------

cat: 显示文件内容或将显示内容进行重定向

  cat textfile  

  #查看文件textfile的内容

  cat –n  textfile1 > textfile2  

  #将textfile1的内容重定向到textfile2中<如果textfile2为非空,会先被清空>  

  cat –n textfile1 >> textfile2 

  #将textfile1的内容重定向到textfile2中<如果textfile2为非空,会将textfile1的内容增加到textfile2的内容之后>

-----------------------------------------------------------------------------------------------

cd: 切换目录

  几个特殊的目录切换:

  cd / 

  #到根目录  

  cd .. 

  #返回上层目录

  cd - 

  #返回前一个工作目录

  cd ~ 

  #到当前用户的home目录

-----------------------------------------------------------------------------------------------

chgrp: 更换文件目录的所属用户组

  chgrp user /path/filename 

  #将 /path/filename的所属用户组更改为user

-----------------------------------------------------------------------------------------------

chmod: 更改文件属性

[权限级别: user(u), group(g), others(o)]

[+:add permission; -: remove permission]

[r: readable; w: writable; x:executable]

[r=4; w=2; x=1]

  chmod ugo+r file     

  #give user, group and others with the permission – read

  chmod a+r file        

  #give all with the permission – read

  chmod –R a+r *      

  #give all with the permission – read to all the files under the current directory [-R: include the folder and all the files in this folder]

  chmod 777 file 

  #give all with all the permissions – read, write, execute to file

 -----------------------------------------------------------------------------------------------

chown: 更改文件所属用户

  chown user filefolder/filename 

  #将filefolder/filename的拥有者更改为user

-----------------------------------------------------------------------------------------------

cp: Copy

  cp ../filefolder1/file ../filefolder2

  #将文件或目录从filefolder1下复制到filefolder2下

  cp -f ../filefolder1/file ../filefolder2

  #若filefolder2下也有file,则可用参数-f 强制覆盖

  cp -a ../filefolder1 ../filefoldern

  #将filefolder1下面的全部内容复制到filefoldern中,参数-a 全部复制

  cp -s file1 file2

  #为file1建立一个名为file2的快捷方式

  cp -l file1 file2

  #使file2连接到file1,相当于建立连接

-----------------------------------------------------------------------------------------------

crontab: 任务调度,可以使得命令在特定的时间运行

  crontab -e

  #编辑一个crontab

  crontab -l

  #显示当前用户所设定的crontabs

  crontab -r

  #取消某个crontab,需要用某个crontab的ID

Examples: 在今天下午5:30显示"It's time for the day "by 5:30 pm today."

原文地址:https://www.cnblogs.com/enjoytesting/p/2548017.html