Pages

Wednesday, April 5, 2017

Linux Command - TIPS

1) VIM 


a) dgg - will delete everything from your current line to the top of the file.


d is the deletion command, and gg is a movement command that says go to the top of the file, so when used together, it means delete from my current position to the top of the file.

2) LS

ls - To list complete path of the file in output

Normally ls won't list the complete file path in ls -l output. Complete path may be required while doing some automation. Blow is the command which will display the complete path in the ls output.

# ls - lrt -d -1 test/*

Sample Output
drwx------ 3 mo607 users 4096 Jun 30  2016 test/opt
-rw------- 1 mo607 users  393 Jun 30  2016 test/findfiles.sh
-rw------- 1 mo607 users   39 Jan 25 05:37 test/Type1_20160705.xml.gz
-rw------- 1 mo607 users   39 Jan 25 05:37 test/Type1_20160704.xml.gz
-rw------- 1 mo607 users   39 Jan 25 05:37 test/Type1_20160703.xml.gz
drwx------ 2 mo607 users 4096 Jan 25 05:50 test/one
-rw------- 1 mo607 users  421 Jan 25 05:50 test/tn
-rw------- 1 mo607 users 1001 Jan 25 05:59 test/itf

3) TAIL

Tail to display the content’s of multiple files with filenames

Cat *.txt will display the contents of all text files but it won't display the file names. To display the contents with file names then we need to use below command.

# tail -n +1 -- *.txt

4) How to backup and restore File permissions using FACL

Backup and Restore file permissions

We can use getfacl and setfacl to backup and restore permission. Below is the example.

# getfacl -R . >permissions.facl

# setfacl --restore=permissions.facl

5) How to check exit codes of all commands piped


[XXXX@server2 ~]# ls -l | grep upkar

[XXXX@server2 ~]# echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"

0 1

6) ldd command



6) 


blockdev --getsize64 /dev/sdb


17179869184


  --getsize64


              Print device size in bytes

Even fdisk will give the same output.


fdisk -l /dev/sda


Disk /dev/sda: 17.2 GB, 17179869184 bytes

4) grep "MDT-IT-OPS-DC-NON WINTEL L1" $OPFILE | sed -e "s/MDT-IT-OPS-DC-NON WINTEL L1/\x1b[7m&\x1b[0m/"

5) to export a function 

export -f

pwdx <PID>
dirname
basename
rev

6)
dmidecode -t processor | grep HTT

7)

tar command 2> error.log 1> out.log
getconf _NPROCESSORS_ONLN
16

No comments:

Post a Comment