Linux command tips and tricks

Introduction

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

Begin with an engaging introduction that explains the importance of mastering Linux commands for DevOps professionals. Highlight how these commands enhance productivity and streamline operations in a Linux environment.

Linux command tips and 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 the 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)}'

the 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

Throughout this article, we’ve explored various Linux command tips and tricks. I hope you find these insights useful for your tasks. Thanks for visiting the DevopsRoles page.

, ,

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. 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.