Chapter 4: Essential Linux Commands (part 2) __Linux 101 Hacks

Chapter 4: Essential Linux Commands

        __Linux 101 Hacks

Hack 23. Sort Command

Sort command sorts the lines of a text file.

    employee information in the format:

        employee_name:employee_id:department_name.

 

 
  
$ cat names.txt
Emma Thomas:
100 :Marketing
Alex Jason:
200 :Sales
Madison Randy:
300 :Product Development
Sanjay Gupta:
400 :Support
Nisha Singh:
500 :Sales

 


Sort a text file in ascending order

 

 
  
$ sort names.txt
Alex Jason:
200 :Sales
Emma Thomas:
100 :Marketing
Madison Randy:
300 :Product Development
Nisha Singh:
500 :Sales
Sanjay Gupta:
400 :Support


 

Sort a text file in descending order

 

 
  
$ sort - r names.txt
Sanjay Gupta:
400 :Support
Nisha Singh:
500 :Sales
Madison Randy:
300 :Product Development
Emma Thomas:
100 :Marketing
Alex Jason:
200 :Sales

 

 

 

Sort a colon delimited text file on 2nd field (employee_id)

 

 
  
$ sort - t: - k 2 names.txt
Emma Thomas:
100 :Marketing
Alex Jason:
200 :Sales
Madison Randy:
300 :Product Development
Sanjay Gupta:
400 :Support
Nisha Singh:
500 :Sales

 

 

 

Sort a tab delimited text file on 3rd field (department_name) and suppress duplicates

 

 
  
$ sort - t: - u - k 3 names.txt
Emma Thomas:
100 :Marketing
Madison Randy:
300 :Product Development
Alex Jason:
200 :Sales
Sanjay Gupta:
400 :Support

 

 

 

Sort the passwd file by the 3rd field (numeric userid)

 

代码
 
   
$ sort - t: - k 3n / etc / passwd | more
root:x:0:0:root:
/ root: / bin / bash
bin:x:
1 : 1 :bin: / bin: / sbin / nologin
daemon:x:
2 : 2 :daemon: / sbin: / sbin / nologin
adm:x:
3 : 4 :adm: / var / adm: / sbin / nologin
lp:x:
4 : 7 :lp: / var / spool / lpd: / sbin / nologin

Sort /etc/hosts file by ip-addres

 

 

代码
 
   
$ sort - t . - k 1 ,1n - k 2 ,2n - k 3 ,3n - k 4 ,4n / etc / hosts
127.0 . 0.1 localhost.localdomain localhost
192.168 . 100.101 dev - db.thegeekstuff.com dev - db
192.168 . 100.102 prod - db.thegeekstuff.com prod - db
192.168 . 101.20 dev - web.thegeekstuff.com dev - web
192.168 . 101.21 prod - web.thegeekstuff.com prod - web

 

Combine sort with other commands

 

代码
 
   
ps –ef | sort : Sort the output of process list

ls
- al | sort + 4n : List the files in the ascending order of the file - size. i.e sorted by 5th filed and displaying smallest files first.

ls
- al | sort + 4nr : List the files in the descending order of the file - size. i.e sorted by 5th filed and displaying largest files first.

 

 

Hack 24. Uniq Command

Uniq command is mostly used in combination with sort command, as uniq removes duplicates only from a sorted file.

1. When you have an employee file with duplicate entries, you can do the following to remove duplicates.

 

 
  
$ sort namesd.txt | uniq
$ sort –u namesd.txt

2. If you want to know how many lines are duplicates, do the following.

 

 

 
  
$ sort namesd.txt | uniq –c
2 Alex Jason: 200 :Sales
2 Emma Thomas: 100 :Marketing
1 Madison Randy: 300 :Product Development
1 Nisha Singh: 500 :Sales
1 Sanjay Gupta: 400 :Support

3. The following displays only the entries that are duplicates.

 

 

 
  
$ sort namesd.txt | uniq –cd
2 Alex Jason: 200 :Sales
2 Emma Thomas: 100 :Marketing

 

 

Hack 25. Cut Command

Cut command can be used to display only specific columns from a text file or other command outputs.

Display the 1st field (employee name) from a colon delimited file.

 

 
  
$ cut - d: - f 1 names.txt
Emma Thomas
Alex Jason
Madison Randy
Sanjay Gupta
Nisha Singh

Display 1st and 3rd field from a colon delimited file

 

 

 
  
$ cut - d: - f 1 , 3 names.txt
Emma Thomas:Marketing
Alex Jason:Sales
Madison Randy:Product Development
Sanjay Gupta:Support
Nisha Singh:Sales

Display only the first 8 characters of every line in a file

 

 
  
$ cut - c 1 - 8 names.txt
Emma Tho
Alex Jas
Madison
Sanjay G
Nisha Si

 

Misc Cut command examples

 

 

 
  
cut - d: - f1 / etc / passwd Displays the unix login names for all the users in the system.

free
| tr - s ' ' | sed ' /^Mem/!d ' | cut - d " " - f2 Displays the total memory available on the system.

 

 

 

 

Hack 26. Stat Command

Stat command can be used either to check the status/properties of a single file or the filesystem.

 

代码
 
   
$ stat / etc / my.cnf
File: `
/ etc / my.cnf '
Size: 346 Blocks: 16 IO Block: 4096
Device: regular file Inode:
279856 Links: 1
Access:((
0644 /- rw - r -- r -- ) Uid: (0 / root) Gid:(0 / root)
Access:
2009 - 01 - 01 02 : 58 : 30.000000000 - 0 800
Modify:
2006 - 06 - 01 20 : 42 : 27.000000000 - 0700
Change:
2007 - 02 - 02 14 : 17 : 27.000000000 - 0 800
代码
 
   
$ stat / home / ramesh
File: `
/ home / ramesh '
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h
/ 2051d Inode: 5521409 Links: 7
Access: (
0755 / drwxr - xr - x) Uid: ( 401 / ramesh) Gid: ( 401 / ramesh)
Access:
2009 - 01 - 01 12 : 17 : 42.000000000 - 0 800
Modify:
2009 - 01 - 01 12 : 07 : 33.000000000 - 0 800
Change:
2009 - 01 - 0 9 12 : 07 : 33.000000000 - 0 800

Display the status of the filesystem using option –f

 

 

 
  
$ stat - f /
File:
" / "
ID: 0 Namelen:
255 Type: ext2 / ext3
Blocks: Total:
2579457 Free: 2008027 Available: 1876998 Size: 4096
Inodes: Total:
1310720 Free: 1215892

 

 

 

Hack 27. Diff Command

diff command compares two different files and reports the difference. 

The output is very cryptic and not straight forward to read.

Syntax: diff [options] file1 file2

option -w in the diff command will ignore the white space while performing the comparison.

    In the following diff output:

        The lines above ---, indicates the changes happened in first file in the diff command (i.e name_list.txt).

        The lines below ---, indicates the changes happened to the second file in the diff command (i.e name_list_new.txt). The lines that belong to the first file starts with < and the lines of second file starts with >.

 

 
  
# diff -w name_list.txt name_list_new.txt
2c2, 3
< John Doe
---
> John M Doe
> Jason Bourne

 

 

Hack 28. Display total connect time of users

ac command will display the statistics about the user’s connect time.

Connect time for the current logged in user

option –d will break down the output for the individual days. 

Connect time for all the users

Option –p To display connect time for all the users.

 

 
  
# ac -d

# ac -p

Connect time for a specific user
To get a connect time report for a specific user, execute the following:

 
  
$ ac - d sanjay

 

 

 

Chapter 4: Essential Linux Commands (part 1) __Linux 101 Hacks

 

__ end.

转载于:https://www.cnblogs.com/way_testlife/archive/2010/09/21/1832751.html

数据中心机房是现代信息技术的核心设施,它承载着企业的重要数据和服务,因此,其基础设计与规划至关重要。在制定这样的方案时,需要考虑的因素繁多,包括但不限于以下几点: 1. **容量规划**:必须根据业务需求预测未来几年的数据处理和存储需求,合理规划机房的规模和设备容量。这涉及到服务器的数量、存储设备的容量以及网络带宽的需求等。 2. **电力供应**:数据中心是能源消耗大户,因此电力供应设计是关键。要考虑不间断电源(UPS)、备用发电机的容量,以及高效节能的电力分配系统,确保电力的稳定供应并降低能耗。 3. **冷却系统**:由于设备密集运行,散热问题不容忽视。合理的空调布局和冷却系统设计可以有效控制机房温度,避免设备过热引发故障。 4. **物理安全**:包括防火、防盗、防震、防潮等措施。需要设计防火分区、安装烟雾探测和自动灭火系统,设置访问控制系统,确保只有授权人员能进入。 5. **网络架构**:规划高速、稳定、冗余的网络架构,考虑使用光纤、以太网等技术,构建层次化网络,保证数据传输的高效性和安全性。 6. **运维管理**:设计易于管理和维护的IT基础设施,例如模块化设计便于扩展,集中监控系统可以实时查看设备状态,及时发现并解决问题。 7. **绿色数据中心**:随着环保意识的提升,绿色数据中心成为趋势。采用节能设备,利用自然冷源,以及优化能源管理策略,实现低能耗和低碳排放。 8. **灾难恢复**:考虑备份和恢复策略,建立异地灾备中心,确保在主数据中心发生故障时,业务能够快速恢复。 9. **法规遵从**:需遵循国家和地区的相关法律法规,如信息安全、数据保护和环境保护等,确保数据中心的合法运营。 10. **扩展性**:设计时应考虑到未来的业务发展和技术进步,保证机房有充足的扩展空间和升级能力。 技术创新在数据中心机房基础设计及规划方案中扮演了重要角色。例如,采用虚拟化技术可以提高硬件资源利用率,软件定义网络(SDN)提供更灵活的网络管理,人工智能和机器学习则有助于优化能源管理和故障预测。 总结来说,一个完整且高效的数据中心机房设计及规划方案,不仅需要满足当前的技术需求和业务目标,还需要具备前瞻性和可持续性,以适应快速变化的IT环境和未来可能的技术革新。同时,也要注重经济效益,平衡投资成本与长期运营成本,实现数据中心的高效、安全和绿色运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值