Linux & Git-GitHub commands I learned :
#90DaysOfDevOps Day 12th
Basic Commands
Command
Description
ls
Show all files and directories present in the working directory
ls -l
Show all files and directories along with details like ownership, size, and when they were last modified
ls -t
Sort the output of ls
by last modified date
pwd
List the path of the current working directory
cd directory
Switch to a different working directory
cd ..
Move up one directory level
cd /
Switch to the root directory
clear
Wipe out all the text from the terminal screen
history
Print out all the previously executed commands in the current session
touch filename
Create a new file
vi filename
Open a file for editing
cat filename
Display the contents of a file
hostnamectl
List system information, including kernel, release, architecture, and virtualization etc.
ifconfig
Show the network interfaces, IP addresses, and MAC address of the system
date
Print the current system date and time
top
List all the running processes on the system
free -m
Show memory usage stats
head filename
Display the first 10 lines of a file
tail filename
Display the last 10 lines of a file
mv file /new/file/path
Move the file to a different location
mv filename new_filename
Rename a file
cp filename new_filename
Copy a file
man command_name
List helpful information regarding a command
rm filename
Delete a file
rm –rf directory_name
Remove a directory and its contents
sudo
For regular users to run commands with elevated privileges
mkdir directory_name
Create a new directory
kill pid
Kill a process using its process ID
reboot
Restart the system
shutdown –h now
Turn off the system
Networking Commands
Command
Description
dig domain_name
Show the DNS related information of the given domain name
dig -x host
Perform a reverse lookup for a host
host domain_name
Perform DNS lookup of the given domain name which prints out the IP address
whois domain_name
For more information about a domain
ping ip
Check the connectivity between your host and the given IP address
ssh username@ip
To securely log in as the specified user on another server
wget file
Download a file
wget -c file
Continue a stopped download
traceroute domain_name
Trace the route a packet will take when travelling from your machine to a host
telnet domain_name port
Connect to a remote host on a specific port
netstat –pnltu
Display all currently listening ports
route
Display the routing table for your machine
arp
View the contents of the ARP (address resolution protocol) table
cat /etc/resolv.conf
See the DNS servers that your machine is currently using
tcpdump -i eth1 'port 80'
Log and monitor all incoming traffic on port 80
nmap ip
Network discovery of the given IP. Find out whether the host is up, which ports are open etc.
Search Commands
Command
Description
locate keyword
Search for a file or directory in a pre-compiled cache. Much faster than find
but many not show all results
find keyword
Search for a file or directory in the real system. Much slower than locate
but is always up-to-date
find /home -name *.ext
Search for the given extension in the /home
directory and all its sub-directories
find / -type f ! -perm xxx
List all files that don’t have the specified permission
find / -perm /u=r
Display all the read-only files
grep keyword filename
Search for the specified keyword/pattern in the given file
grep keyword *
Search for the specified keyword/pattern across all files in the current directory
grep -i keyword *
To ignore case while searching
grep -r keyword *
Perform a recursive search, i.e. include the sub-directories in the search
grep -x 'what to match' *
Print all the lines where a match was found
grep -c keyword *
Count the number of matches
Permissions Commands
Command
Description
chmod xxx filename
Assign the specified permissions to a file
chmod –R xxx directory
Assign the specified permissions to a directory, and all its sub-directories
chmod –x filename
Remove the execution permissions from a file
chown username filename
Change the ownership of the specified file
chown username:groupname filename
Change the ownership and the group ownership of a file
chown username:groupname filename1 filename2 filename3
Change the ownership and the group ownership of multiple files
chown --from=bob alice filename
Change the ownership of a file only if it’s owned by a specific user (added after --from=
)
chown -h usergroup symbolic_link
Forcefully change the owner and group of a symbolic link
Storage Commands
Command
Description
df –h
List storage related information of all partitions, including overall size, free space, and used space etc.
mount
unmount
Mount or unmount an ISO file or a storage device
du -h /home/directory_name
Find the directory size in a human readable format
du -sh /home/directory_name
To get the total size of a directory
du -ah --exclude='*.xxx' /home/directory_name
Display the disk usage of all files in a directory, excluding files with the given extension
du -ha --time /home/directory_name
Display disk usage of a directory by modification time
fdisk -l
Show disk size along with partitioning information
sudo du -x / | sort -nr | head -20
List the top 20 directories that are overconsuming resources
User Management Commands
Command
Description
adduser username
Add a new user
userdel -r 'username'
Delete a user
passwd -l 'username'
Change the password of a user
whoami
See the currently logged in user
usermod -c 'This user will be deleted tomorrow' username
To add a comment to a user account
cat /etc/passwd
Display a list of all users with additional info
usermod -d /home/test username
Change the home directory of a user
sudo deluser username group_name
Remove a user from a group
usermod -a -G group_name username
Add a user to a group
groupadd group_name
Create a new group
groupdel group_name
Delete a group
id
Display the user ID, group ID, and groups for the current user
Git & GitHub Commands:
Thank You So All,