Linux Administration Commands
Basic Linux Commands
Linux commands are used to perform basic tasks like navigating directories, managing files,
monitoring processes, and more. These commands form the foundation of system
administration and daily Linux use.
File & Directory Commands
Commands used to navigate and manage files and folders:
pwd : Prints the current working directory you are in.
ls : Lists the contents of the current directory.
ls -l : Displays detailed information about each file and directory.
cd directory_name : Changes the current directory to the specified directory.
mkdir directory_name : Creates a new directory.
rmdir directory_name : Removes an empty directory.
touch filename : Creates an empty file or updates the timestamp of an existing file.
cp source destination : Copies files or directories from source to destination.
mv source destination : Moves or renames files or directories.
rm filename : Deletes a specified file.
rm -r directory : Recursively deletes a directory and its contents.
find /path -name filename : Searches for files with the specified name.
Viewing Files
Used to read and monitor the content of files:
cat filename : Displays the contents of a file.
head filename : Shows the first 10 lines of a file.
tail filename : Shows the last 10 lines of a file.
tail -f filename : Monitors a file in real-time as new lines are added (commonly used for
logs).
less filename : Opens a file for scrolling through its content.
Permissions & Ownership
Manage who can read, write, or execute files:
chmod 755 filename : Changes permissions to allow read, write, and execute for the
owner, and read and execute for others.
chown user file : Changes the owner of a file.
chgrp group file : Changes the group ownership of a file.
stat filename : Displays detailed metadata about a file, including its permissions and
inode number.
User Management
Commands to manage users:
useradd username : Creates a new user account.
passwd username : Sets or changes the password for a user.
usermod options username : Modifies user account details, like home directory, shell, etc.
userdel username : Deletes a user account.
id username : Displays the user ID (UID), group ID (GID), and groups of a user.
Group Management
Commands to manage user groups:
groupadd groupname : Creates a new group.
groupdel groupname : Deletes a group.
usermod -aG groupname username : Adds a user to a supplementary group.
groups username : Displays all groups a user belongs to.
Process Management
Used to monitor and manage running processes:
ps aux : Lists all running processes.
top : Opens an interactive view of running processes with real-time updates.
kill PID : Terminates a process using its process ID (PID).
killall process_name : Terminates all processes with the specified name.
bg / fg : Moves a process to the background or foreground.
UMASK Commands
Defines the default permissions for new files and directories.
umask : Shows the current umask value (default permission mask).
umask 022 : Sets umask to 022, which removes write permissions for group and others.
ACL (Access Control List) Commands
Provides more granular control over permissions beyond traditional user/group/other:
getfacl filename : Retrieves ACL entries for a file.
setfacl -m u:username:rw filename : Grants read and write permissions to a specific user.
setfacl -x u:username filename : Removes a specific user's ACL permissions.
setfacl -b filename : Removes all ACL entries from a file.
Inode Commands
Inodes store metadata about files (location, permissions, etc.):
ls -i filename : Displays the inode number of a file.
stat filename : Provides detailed inode and file information.
find . -inum inode_number : Finds files by their inode number.
Hard Link Commands
Hard links create a direct reference to the same inode as the original file:
ln existingfile hardlinkname : Creates a hard link pointing to the existing file.
Soft Link (Symbolic Link) Commands
Symbolic links act as shortcuts to files or directories:
ln -s targetfile symlinkname : Creates a symbolic link pointing to the target file.
Archiving Commands (tar)
Used to collect files into a single archive for easy storage or transfer:
tar -cvf archive.tar files/ : Archives files into a single .tar file.
tar -xvf archive.tar : Extracts files from a .tar archive.
Compression Commands
Used to reduce file size for storage or transfer:
gzip filename : Compresses a file using gzip.
gunzip filename.gz : Decompresses a .gz file.
zip archive.zip files : Compresses files into a .zip archive.
unzip archive.zip : Extracts files from a .zip archive.
Archiving + Compression (tar.gz)
Combines archiving and compression for efficient packaging:
tar -czvf archive.tar.gz files/ : Archives and compresses files into a .tar.gz file.
tar -xzvf archive.tar.gz : Extracts files from a .tar.gz archive.
Crontab Commands
Used to schedule repetitive tasks automatically:
crontab -e : Opens the crontab file for editing to schedule tasks.
crontab -l : Lists all scheduled cron jobs.
crontab -r : Removes all scheduled cron jobs.
Basic Linux Networking Commands
Commands to manage network configurations and connectivity:
ip addr : Displays network interfaces and IP addresses.
ping hostname : Sends ICMP echo requests to check network connectivity.
traceroute hostname : Displays the path packets take to reach a host.
netstat -tuln / ss -tuln : Lists open ports and listening services.
curl url : Transfers data from or to a server.
wget url : Downloads files from the web.
scp file user@host:/path : Securely copies files to a remote server.
ssh user@host : Logs into a remote machine securely.
Process Priority & Nice Value
Prioritize CPU usage of processes:
nice -n priority command : Runs a command with a specified priority.
renice priority -p PID : Changes the priority of an already running process.
ps -eo pid,ni,comm : Lists process IDs, nice values, and command names.