Cheatography
https://cheatography.com
Linux commands for DevOps
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Basic info
pwd |
show present working directory |
uname |
show name of the kernel |
uname -r |
show kernel version |
cd |
change directory |
clear |
clear the screen |
whoami |
show current login user name |
history |
show list of previously used commands |
date |
show time and date |
echo "Hello" |
display Hello text |
sudo |
run commands as super user |
Working with directory and files
mkdir dir |
create single directory dir |
mkdir dir1 dir2 |
create multiple directories dir1 dir2 |
mkdir -p dir/a/b/c |
create nested directory dir/a/b/c |
mkdir dir{1..10} |
created 10 numbered directories from dir1 to dir10 |
rm -r dir |
remove dir recursively |
touch file |
create empty file file |
touch file1 file2 |
create multiple files file1 file2 |
touch file{1..10} |
create 10 numbered files from file1 to file10 |
cp -rf /dir/file1 /dir2 |
copy file file1 to dir2 directory recursively and forcefully |
mv /dir/file1 /dir2 |
move file file1 to dir2 directory |
rm file1 |
remove file file1 |
ls -al |
show files - both regular & hidden files and their permissions |
cat file1 |
display contents of file1 |
find /dir1 -name file1 |
find file1 under /dir1 directory |
find /dir1 -perm 664 |
find all files/directories with read, write permission to owner and group, read permission for others in directory dir1 |
find /dir1 -empty -exec rm -r {}** |
find and remove all empty files/directories from /dir1 |
wc -l file1 |
count the number of lines in file1 |
wc -w file1 |
count the number of words in "file1* |
head file1 |
display top 10 lines of file1 |
head -n 20 file1 |
display top 20 lines of file1 |
tail file1 |
display last 10 lines of file1 |
tail -n 20 file1 |
display last 20 lines of file1 |
Networking
ifconfig or ip addr |
show ip address |
nmcli con show |
show list of connections |
nslookup |
queries the DNS server for information about a domain name or IP address |
iptables |
sets up, maintains, and inspects the tables of IPv4/IPv6 packet filter rules in the Linux kernel firewall |
ping host |
send packets to host to check the connectivity |
ping -c 5 host |
send 5 packets to host |
curl |
facilitates the transfer of data to or from a server, using any of the protocols it supports |
netstat |
Displays network connections and network statistics, such as active sockets, routing tables, and network interface statistics |
ss-keygen |
Creates a pair of public and private authentication keys |
ssh user@host |
connect user to host using ssh |
scp file1 user1@host:/dir |
copy file1 from local to remote host host to /dir location |
System and process monitoring
uptime |
show current uptime |
df |
show disk usage |
du |
show directory space usage |
free |
show memory and swap usage |
ps |
show all current active processes |
top |
task manager program displays information about CPU and memory utilization |
kill pid |
kill process with process id pid |
bg |
list stopped or background jobs |
lsof |
Lists all files opened by any process of a system |
lsof -u user1 |
Lists all files opened by user1 |
|
|
File permissions
chmod [symbolic] file1 |
change file permissions of file file1 based on [symbolic] code |
chmod u+r file1 |
add read permission to owner for file1 |
chmod g+rw file1 |
add read, write permission to group for file1 |
chmod o-r file1 |
remove read permission to others for file1 |
chmod [octal] file1 |
change file permissions of file file1 based on [octal] code |
chmod 777 file1 |
add read, write, execute permission to owner, group, others for file1 |
chmod 754 file1 |
add read, write, execute persmission to owner, read and execute permission to group, read permission to others for file1 |
chown user1 file1 |
change ownership of file1 to user1 |
chgrp group1 file1 |
change group ownership of file1 to group1 |
setfacl -m u:user1:rwx file1 |
add read, write, execute permission to user user1 for file1 |
setfacl -x u:user1: file1 |
remove all permissions for user1 for file1 |
setfacl -b file1 |
remove all acl permissions for file1 |
User and Group Management
useradd user1 |
create user1 user account |
passwd user1 |
create password for user1 user |
su |
switch user account |
exit |
logout user |
userdel user1 |
delete user account user1 |
usermod -l user2 user1 |
change user1 login name to user2 |
groupadd group1 |
add group group1 |
groupdel group1 |
delete group group1 |
gpasswd -a user1 group1 |
add single user user1 to group group1 |
gpasswd -M user1,user2 group1 |
add multiple users user1 user2 to group group1 |
gpasswd -d user1 group1 |
remove user user1 from group group1 |
gpasswd -A user1 group1 |
make user1 as admin of group1 |
Text search and manipulation
grep text file1 |
display the lines that contains text in file1 |
grep -ni text file1 |
ignore the case and display line numbers of the matched lines |
awk -F',' '{print $1"@"$3}' |
print col1@col3 |
awk -F'\t' '/str/ {print $0}' |
print line with str |
Compress and archive
tar -cf /dir1/backup.tar /dir2 |
create tar archive file /dir1/backup.tar for /dir2 |
tar -xvf /dir1/backup.tar -C /dir2/ |
extract tar archive file /dir1/backup.tar to /dir2/ |
cron jobs
at time |
schedule command to run at time |
atq |
view pending jobs |
atrm 2 |
remove job 2 from the scheduled commands |
crontab -e |
set cron jobs |
0 2 * * * /dir1/script.sh |
run script /dir1/script.sh at 2pm daily |
crontab -l |
show the list the cron jobs of current user |
Package management
apt update |
update the local package index with the latest changes made in the repositories |
apt upgrade |
upgrade installed packages |
apt install package |
install package |
apt remove package |
remove installed package |
systemctl start service |
start service |
systemctl status service |
check the status of service |
systemctl stop service |
stop service |
systemctl enable service |
enable the service to start at system startup |
|