Practical Linux Commands with Options for Real Life

Hands On Linux Commands for Real Life

Practical Linux Commands
In this series I will be discussing practical Linux commands you use in real life with it's parameters and options, I will
go through the options and clarify them without digging deep and turn simple stuff into rocket science.

Also will not go through the command in specific order because this course is meant to be for people who are
refreshing their memory or starting to learn the commands so it will be good to go back to the command and see different
options from time to time.

Thank you and hope you will like this series.

Delete all files except specific ones

rm -rf !(notme.txt.txt) "delete all files except notme.txt"
rm -f !(*.mp3 | *.java) "Delete all except java and mp3 files"

If you are getting an error that bash not recognizing '!' then run below:

shopt -s extglob

 

Find Files Which Are Consuming The Most Of The Storage

In below example we are using the below following parameters:

'/'  -- To search from root including all sub folders.
'-xdev' -- Excluding all network storage.
'-type f' -- Searching files only.
'-size +100M' -- Finding only files which are more than 100 Megabytes.
'-exec du-sh' -- Will keep going through all files and find size.
'sort -r' -- Will sort the files and reverse the list.
'head -n 10' -- This will output only the top 10 big files.

find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -r | head -n 10

 

Kill All Running Processes Contains 'text'

pkill -f text

Kill all apache processes:

pkill -f httpd

 

Yum History and Undo Certain Action

This command was always useful for me whenever i find that someone has installed a package which was incompatible or it did corrupt anything, using below commands you can check the history of installs, find who did it and rollback to certain point.

yum history list all "List all history"
yum history info 4 "Get info about certain history"
yum history undo 4" Undo/Rollback to ID 4"

 

Search All Man Pages

Sometimes you want to do a certain task but you don't know even what command to use, Apropos can help you with that.

Apropos kill "Will search for all kill keyword in all man pages"

Ex.: Searching for commands which are editing text.

Apropos text | grep -i edit

 

Locate Files and Shot Info

locate filename | xargs ls -la

 

Check all Crons for All users

Sometimes you want to know all the cron jobs are running in the system but you don't want to check all users, by running below command you can know all users which have jobs in their crontab.

ls -la /var/spool/cron

After that you can use below command to check certain user crontab:

crontab -eu user


Subscribe to
for video tutorials updates

One thought on “Practical Linux Commands with Options for Real Life

  1. Pingback: Practical Linux Commands for Real Life - Part 2

Comments are closed.