Linux command tips tricks

In this tutorial, I wrote the Linux command tips tricks. The day by day I working on a Linux platform. My collection for Linux system admin. Linux the essential for DevOps Roles.

Linux command tips tricks

How to return to the previous directory

$ cd -

The display headers and footers in FileName.

$ cat filename | sed -e '$d' | awk 'NR > 1 {print}'

Search files under arbitrary directories

$ find ./ -name '*'|xargs grep 'devopsroles.com'

Empty the file.

$ cat /dev/null > filename.txt

Move to thereafter create the folder

$ mkdir dir_name ; cd $_

To count the number of files in any directory.

$ ls -F |grep -v / |wc -l

or count the number of folders in any directory.

$ ls -F |wc -l

Convert all extensions

$ for filename in *.txt; do mv $filename ${filename%.txt}.txt.old; done
Linux command tips tricks

To create serial number files.

$ touch foo_{1..4}.csv
$ touch {A..X}.csv

Delete “.DS_store” in bash

$ find . -name '.DS_Store' -type f -ls -delete

How to delete the last slash of the path.

$ MYDIR=${MYDIR%/}

Extract processes that use a lot of physical memory

$ ps aux | sort -n -k 6 | tail -n 10

Find processes with high CPU utilization

$ vmstat 1 | awk '{print strftime("%y/%m/%d %H:%M:%S"), $0}

lsof command list of ports in Listen

$ lsof -Pan -i tcp -i udp

Generate random passwords using head command and tr command.

$ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''

Extract a character string

$ echo 'devopsroles.com' | awk '{print substr($0, 2)}'

mount command the display formatting with column

$ mount | column -t

To See CPU utilization per user

$ ps aux | awk  '{if (NR> 1) {p [$1] +=$3; n [$ 1] ++}} END {for (i in p) print p [i], n [i], i }'

How much RAM is installed on this system?

[huupv@huupv devopsroles]$ sudo dmidecode -t 17 | grep "Size.*MB" | awk '{s+=$2} END {print s / 1024 "GB"}'

Awk command line

Character count (wc – c)

$ awk '{n+=length($0)} END{print n}' filename

Word count (wc – w)

$ awk '{n+=NF} END{print n}' filename

Row count (wc – l)

$ awk 'END{print NR}' filename

Display from specified line to specified line

$ awk 'NR==3,NR==10'

Kill bulk by process name

$ kill $(ps aux | grep  "jenkins" | awk '{print $2;}')

Conclusion

Thought the article, You use Linux command tips tricks as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.