Linux Commands

File System
df -h
  – Show file system usage

du -hs
  – Show current folder disc space usage

du -a -h --max-depth=1 | sort -rh
  – List 1st-level subfolders and files with size

fdisk -l | grep Disk
  – Display total harddisk size

ls -lZ
  – Display the security context associated with files or directories

ls | wc -l
  – List number of files and directories for the current folder

dd if=/dev/zero of=<filename> bs=1024k count=10
  – Create a 10MB file (file size = bs x count)

tar -zxvOf filename.tar.gz somepath/yourfile.txt
  – Print a text file in an archive to stdout
 

User and Group
grep ^groupname /etc/group
  – List all user of a group

groupadd groupname
  – Create new group

groups
  – List all groups of the current user

htpasswd -c passwdfile username
  – Create password file with username or truncate and rewritten if exists

passwd username
  – Change the password of an exiting user

useradd username
  – Create user

useradd -m -s /bin/bash username
  – Create user with default home folder and bash as default shell

usermod -a -G groupname username
  – Add existing user to an existing group
 

System Inforamtion
uname -mrs
  – Linux kernal version and microprocessor architecture

dmesg
  – Display the boot msg

ps aux OR ps -ef
  – Show running process

netstat -r
  – Show the IP routing table including gateway address

netstat -tuna
  – List the listening port

netstat -tulpn | grep :<port>
  – Find the process which occupies a specific port

grep -i –color “model name” /proc/cpuinfo
  – Find the number of CPU cores
 

Hard Disk & Partition
e2fsck
  – Checkdisk

fdisk
  – Fixdisk

mke2fs
  – Format hard disk

tune2fs
  – Edit the parameters of the partition
 

Cron Job
crontab -e
  – Edit cron jobs

crontab -l
  – List all cron jobs

select-editor
  – Select text editor for crontab

3 thoughts on “Linux Commands”

Leave a comment

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

Dream BIG and go for it =)