The usefull linux commands

Introduction


Master essential Linux command-line operations with this comprehensive guide. Learn practical tips for managing log files, executing commands efficiently, and optimizing your system administration skills.
 
Welcome to our guide on mastering essential command-line operations and system management tasks! Whether you're a beginner or an experienced user, these techniques will help you navigate the command line with ease. In this blog post, we'll explore practical tips and tricks to streamline your workflow and boost productivity. Join us as we dive into managing log files, executing commands efficiently, and optimizing your system administration skills for success.

How to Find and Delete Log Files Older Than 30 Days

One of the key tasks in system administration is managing log files. Over time, these files can accumulate and consume significant disk space. Here's how you can find and delete log files that are older than 30 days: 
# find /path/to/log/ -type f -name \*.log\* -mtime +30 -exec rm {} \; > /dev/null 2>&1

How to Find and Delete Log Files Less Than 30 Days Old

Similarly, you might need to find and delete log files that are less than 30 days old. The following command will help you do just that:

# find /path/to/log/ -type f -name \*.log\* -mtime -30 -exec rm {} \; > /dev/null 2>&1

Create a Directory and Move into It at the Same Time

Creating directories and navigating into them is a common task. Here’s a one-liner that allows you to create a directory and move into it at the same time:

# mkdir test-dir && cd $_

Display the Size of a Folder

Knowing the size of directories is crucial for managing disk space. You can display the size of a folder with the following command:

# du -csbh /path/to/folder

Display Output as a Table

Displaying data in a tabular format can make it easier to read. Use the following command to format the /etc/passwd file as a table:

# cat /etc/passwd | column -t -s: 

Run the Last Command as Root

Sometimes, you may need to re-run the last command with root privileges. Instead of typing the entire command again, you can simply use:

# sudo !!

Return to the Previous Directory

If you need to quickly navigate back to the previous directory, this command will save you time:

# cd -

Add a Passphrase to Your id_rsa File

For enhanced security, you can add a passphrase to your id_rsa file using the ssh-keygen command:

#ssh-keygen -f id_rsa -p

Combine wget and tar in One Command

Downloading and extracting files can be done in one step. Here’s how you can combine wget and tar in a single command:

# wget -qO- http://link-download | tar xvz

Combine find and xargs Commands

To perform actions on files found by the find command, you can combine it with xargs:

# find /home/huupv -name *.jpg | xargs -d '\n' ls -ll

Match All IP Addresses in a Log File with grep

To find all IP addresses in a log file, use the following grep command with a regular expression:

grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"

Check for Duplicate Files

To identify duplicate files in a directory, use this combination of find and md5sum:

find /home/huupv/ -type f -print0 | xargs -0 md5sum | sort | uniq -D -w 32

Determine Your Public IP Address

To quickly find your public IP address, use one of these commands:

curl ipinfo.io/ip
or
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

Conclusion

In conclusion, this blog post offers a comprehensive guide to managing log files and executing essential command-line operations efficiently. From deleting old logs to creating directories, displaying folder sizes, and performing various commands, readers gain valuable insights into streamlining their workflow and optimizing system management tasks. Whether you're a beginner or an experienced user, these tips and tricks will enhance your productivity and proficiency in handling system administration tasks. I hope this is helpful to you. Thank you for reading the huuphan.com page!

Comments

Popular posts from this blog

Bash script list all IP addresses connected to Server with Country Information

zimbra some services are not running [Solve problem]

Whitelist and Blacklist domain in zimbra 8.6