Linux Basic Commands
LINUX Commands
Troubleshooting is crucial for DevOps engineers managing Linux environments!
Here’s an expanded list of commonly used troubleshooting commands with more examples:
- dmesg: Kernel messages for hardware and system errors.
- Example:
dmesg | grep -i error
- top/htop: Real-time system resource monitoring.
- Example:
htop
- free: Memory usage overview.
— Example: free -m
- df: Disk space usage analysis.
- Example:
df -hT
- netstat: Network connections and routing tables.
- Example:
netstat -tuln
,netstat -s
- ping: Testing network connectivity.
— Example: ping -c 4 google.com
- traceroute/mtr: Tracing network routes and latency.
- Example:
mtr google.com
- ifconfig/ip: Network interface configuration.
- Example:
ip addr show
,ifconfig -a
- journalctl: Viewing system logs.
— Example: journalctl -u sshd.service
- lsof: Checking open files and associated processes.
- Example:
lsof -i :port\_number
- ps: Process status and information.
— Example: ```ps
- Ef | grep process_name```
- systemctl: Managing systemd services.
- Example:
systemctl start/restart/stop service\_name
13.grep: Searches for patterns in files.
— Example: grep "pattern" file.txt, grep -r "pattern" directory/
Here are some Linux commands that are commonly used on a daily basis along with examples:
- ls: Lists files and directories in the current directory.
- Example:
ls
,ls -l
,ls -a
- cd: Changes the current directory.
— Example: cd Documents
, cd ..
(moves up one directory)
- pwd: Prints the current working directory.
- Example:
pwd
- mkdir: Creates a new directory.
- Example:
mkdir new\_folder
- rm: Removes files or directories.
- Example:
rm file.txt
,rm -r directory
- cp: Copies files or directories.
- Example:
cp file.txt new\_location/
- mv: Moves or renames files or directories.
— Example: mv file.txt new\_location/
, mv old\_name.txt new\_name.txt
- touch: Creates a new empty file.
- Example:
touch new\_file.txt
- grep: Searches for patterns in files.
— Example: grep “pattern” file.txt
, grep -r “pattern” directory/
- cat: Displays the contents of a file.
- Example:
cat file.txt
- nano or vim: Text editors for creating and editing files.
- Example:
nano file.txt
,vim file.txt
- chmod: Changes file permissions.
— Example: chmod +x script.sh
(gives execute permission to a script)
- sudo: Executes a command with superuser privileges.
- Example:
sudo apt update
,sudo rm protected\_file
- apt or yum: Package managers for installing, updating, and removing software packages.
— Example: sudo apt install package\_name
, sudo yum install package\_name
- find: Searches for files in a directory hierarchy.
— Example: find . -name “\*.txt”
Some other commands along with examples:
- clear: Clears the terminal screen.
- Example:
clear
- man: Displays the manual pages for a command.
- Example:
man ls
(displays the manual for thels
command)
- history: Displays the command history of the current session.
- Example:
history
- date: Prints the current date and time.
— Example: date
- sleep: Delays execution for a specified amount of time.
- Example:
sleep 5
(pauses for 5 seconds)
- uptime: Displays system uptime and load average.
- Example:
uptime
- whoami: Prints the current username.
— Example: whoami
- id: Displays user and group information for the current user or specified user.
- Example:
id
- groups: Lists the groups the current user belongs to.
— Example: groups
- passwd: Allows users to change their passwords.
- Example:
passwd
- who: Shows who is logged on.
— Example: who
- last: Displays a list of last logged in users.
- Example:
last
- kill: Sends a signal to terminate a process.
- Example:
kill PID
(where PID is the process ID)
- cat: Concatenates and displays the content of files.
- Example:
cat file.txt
- more: Displays the content of a file one page at a time.
- Example:
more file.txt
- rm: Removes files or directories.
— Example: rm file.txt
- ln: Creates links between files.
- Example:
ln -s /path/to/file /path/to/link
- hostname: Prints or sets the system’s hostname.
- Example:
hostname
,hostname new\_host\_name
These commands are fundamental for managing and interacting with a Linux system. Experiment with them to get familiar with their functionalities!