(Commands used in day to day activities)
Mostly used Commands:
whoami: This command outputs current logged-in user.
ls: This command list the all files and directory in current directory.
The ls -l command lists files and directories with detailed information like permissions, owner, size, and modification date.
pwd: This command prints the current working directory path.
cat: This command in Linux is used to display the contents of a file.
touch: This command is used to create an empty file or update the timestamp of an existing file.
echo: This command in Linux prints text or variables to the terminal.
uname: This command in Linux displays system information such as the kernel name and version.
date: This command is used to display or set the date and time
file: This command determines and displays the type of a file based on its content.
mkdir: This command is used to creates a new directory.
rm: This command in Linux removes (deletes) files or directories.
cp: This command in Linux copies files or directories from one location to another.
mv: This command in Linux moves or renames files and directories.
cd: This command changes current working directory to specified working directory.
rmdir: This command in Linux removes empty directories.
Grep: This command searches for a particular string/ word in a text file. This is similar to âCtrl+Fâ but executed via a CLI.
This would print would print all of the lines in âfile1â that contain the word âDevOps".
- nano: This command in Linux opens the Nano text editor, allowing you to create and edit text files.
In Nano, the most commonly used modes and keybindings include:
Edit Mode: The default mode for editing text. You can type, delete, and modify text directly.
Navigation:
Arrow Keys: Move the cursor around the text.
Ctrl + A: Move the cursor to the beginning of the line.
Ctrl + E: Move the cursor to the end of the line.
Ctrl + Y: Move up one page.
Ctrl + V: Move down one page.
Saving and Exiting:
Ctrl + O: Save the current file.
Ctrl + X: Exit Nano (prompts to save if changes are made).
Cutting and Pasting:
Ctrl + K: Cut (or delete) the current line or selected text.
Ctrl + U: Paste the cut text.
Searching:
- Ctrl + W: Search for text within the file.
Help:
- Ctrl + G: Display the help menu.
These key bindings help streamline the editing process and make navigation and file management in Nano more efficient.
- vim: is a text editor used in Linux for creating and editing text files, offering various modes for efficient text manipulation.
Modes in vim:
Normal Mode: Used for navigation and text manipulation. You start in this mode.
- Example: Use dd to delete a line.
Insert Mode: Used for inserting text.
- Example: Press i to start typing text.
Visual Mode: Used for selecting text.
- Example: Press v to select text character by character.
Command-Line Mode: Used for executing commands like saving and quitting.
- Example: Press esc then : and then type wq to save and quit.
ping: This command in Linux checks the network connectivity between your system and a specified host by sending ICMP echo requests and measuring the response time.
lsof: This command in Linux lists open files and the processes that opened them.
sudo: This command executes only that command with superuser privileges.
su: command in Linux switches the current user to another user account, typically used to switch to the superuser (root).
awk: This command is a powerful text-processing tool in Linux. It allows you to perform a variety of operations on text files, such as pattern scanning, data extraction, and reporting.
awk '{print $1}' filename.txt : Used to print 1st column of your file.
awk '/myapp/' filename.txt: Used to print lines containing myapp
- sed: This command is a stream editor in Linux. It is commonly used for searching, finding and replacing, inserting, or deleting specific lines in text files.
sed âs/MyApp/newApp/gâ file1: Replace all the occurrences of âMyAppâ with ânewAppâ in each line.
sed -n '3p' file1: Print only 3rd line.
ifconfig: This command in Linux is used to configure, control, and query the network interfaces on a system.
ip: This command in Unix/Linux is part of the iproute2 package and is a more modern and powerful alternative to the older ifconfig command. It is used for managing and displaying network interfaces, routing, IP addresses, and more.
hostname: This command is used to display or set the system's hostname in Linux.
ps: command in Unix/Linux is used to display information about active processes running on the system.
a: Displays information about processes from all users.
u: Gives detail info about each process like cpu, memory usuage, process ID and start time.
x: Include process that are not connected to a terminal.
find: This command in Linux is used to search for files and directories in a directory hierarchy based on various criteria such as name, type, size, modification time, and more.
head: This command is used to print first 10 lines of yours file.
tail: This command is used to print last 10 lines of yours file.
du -h: This command in Unix/Linux displays the disk usage of files and directories in a human-readable format (e.g., KB, MB, GB).
df -h: This command in Unix/Linux displays the available disk space on all mounted filesystems in a human-readable format (e.g., KB, MB, GB).
free: This command in Unix/Linux displays the amount of free and used memory (RAM and swap) in the system.
fuser: This command in Linux identifies processes using files, directories, or sockets.
top: This command in Unix/Linux displays real-time information about system processes, including CPU and memory usage, making it useful for monitoring system performance.
uptime: This command in Linux shows how long the system has been running, along with the current time, the number of users logged in, and the system's load averages for the past 1, 5, and 15 minutes.
which: This command in Linux displays the full path of the executable file for a given command.
sort: This command Linux displays the full path of the executable file for a given command.
history: This command in Linux displays the list of previously executed commands in the terminal session.
man: This command in Linux displays the manual (help) pages for other commands, providing detailed information on usage, options, and examples.
chmod: This command Linux changes the permissions of files or directories.
chown: This command Linux changes the ownership of files or directories, allowing you to specify a new owner and optionally a new group.
getfacl: This command in Linux displays the file access control list (ACL) for a specified file or directory, showing detailed permissions for users and groups beyond the basic owner/group/others model.
setfacl: This command in Unix/Linux is used to set or modify file access control lists (ACLs) for files and directories, allowing for more granular permission settings.
wc: This command in Linux is used to count the number of lines, words, and characters in a file or input.
cut: This command is used to extract specific fields or columns from a file or standard input.
nslookup: This command in Linux is used to query DNS servers to obtain domain name or IP address mapping information.
diff: This command is used to find the difference between two files.
50) ssh user@host: connect to the host as a user.
ssh-keygen: This command is used to generate a public/private authentication key pair.
- apt-get: This command in Linux is used to handle packages and install, update, or remove software on Debian-based distributions.
apt-get update: Fetches the latest package lists from the repositories to ensure youâre getting the latest versions and updates.
apt-get upgrade: Upgrades all installed packages to their latest versions based on the updated package list.
apt-get install <package_name>: Installs a new package specified by <package_name> from the repository.
apt-get remove <package_name>: Completely removes the specified package along with its configuration files.
apt-get clean: Removes downloaded package files from the cache to free up disk space.
apt-get purge <package_name>: Searches for packages in the repository that match the <package_name> keyword.
- echo $?: command in Linux prints the exit status of the last executed command. An exit status of 0 typically indicates that the command was successful, while any non-zero value indicates an error or issue.
Conclusion
In conclusion, mastering Linux commands is essential for any DevOps engineer. These commands form the backbone of daily operations, enabling efficient system management, automation, and troubleshooting. From basic file manipulation to advanced network configuration and process monitoring, a solid understanding of these commands enhances productivity and ensures smooth system performance. By continually practicing and expanding your command-line skills, you can streamline workflows, improve system reliability, and contribute more effectively to your DevOps team.