Tips: Handy Linux commands

This is a post that will no doubt be updated as and when we find new useful commands. If you have any suggestions just let us know in the comments :)

 

File Related


# List all users with UIDs
less /etc/passwd

# Check partition sizes
df -h

# Check directory size
du -s -h /var/log/

# Check every directory and file sizes under a dir
du -s -h /var/log/*

# Check individual size size
du -s -h /var/log/lastlog

# List processes and their associated ports
sudo lsof -i

# Use ls to obtain only directories
ls -d */

# Show number of files in a directory
ls | wc -l
<em>OR</em>
ls | wc -l

# Make a symlink
ln -s <em>targetdir linkname</em>

Apt


# List installed packages on debian based OS for php in this example
dpkg --get-selections | grep php

Yum


# Find out which yum packages provide a certain file or library
yum provides \*/

MySQL


# Backup a database
mysqldump -u root -p dbname &gt; outputfile.sql

Scripts


# Create individual tar.gz archives for multiple folders in a directory. Create the following bash script and chmod +x it.

for d in *; do
[[ -d "$&;d" ]] || continue
tar cvzf "$&;d.tar.gz" "$&;d"
done

 

Tags

Like this Article? Share it!

About the Author

Author Gravatar
Andy

Andy has been in IT support in the academic industry for over 7 years now, with an in-depth knowledge of both Windows and Unix based systems.

Related Posts

Leave a Comment