Linux is a powerful and flexible operating system used by developers, system administrators, and enthusiasts worldwide. If you're new to Linux, learning basic commands is essential to navigating a system efficiently. This guide covers fundamental Linux commands that will help you manage files, processes, users, and more.
1. Basic Commands
pwd
- Print working directory (show the current directory).
ls
- List files and directories in the current directory.
cd <directory>
- Change directory.
- Example:
cd Documents
- moves into the Documents directory.
mkdir <directory>
- Create a new directory.
rmdir <directory>
- Remove an empty directory.
rm <file>
- Remove a file.
rm -r <directory>
- Remove a directory and its contents.
cp <source> <destination>
- Copy files or directories.
- Example:
cp file.txt /home/users/Documents
mv <source> <destination>
- Move or rename files.
- Example:
mv oldname.txt newname.txt
touch <filename>
- Create a new empty file.
2. File Viewing Commands
cat <file>
- Displays the content of a file.
less <file>
- View a file one page at a time.
head <file>
- Show the first 10 lines of a file.
tail <file>
- Show the last 10 lines of a file.
tail -f <file>
- Monitor a file in real-time(useful for logs).
3. File Permissions & Ownership
ls -l
- List files with details including permissions.
4. Process Management
ps
- Show running processes.
top
- Display real-time system resource usage.
5. Disk & Storage
df -h
- Show disk usage in a human-readable format.
6. User Management
id
- Show user and group IDs
adduser <username>
- Add a new user
passwd <username>
- Change a user's password
7. Package Management
apt update
- Update package lists.
apt upgrade
- Upgrade all installed packages.
apt install <package>
- Install a package
apt remove <package>
- Remove a package.
8. Searching content in a File
grep "text" <file>
- Search for text in a file.
9. Detailed Files Viewing Commands
ls -a
- Displays hidden files
ls -lh
- List files and their sizes in a human-readable format.
10. Other Useful Commands
echo "Hello World!"
- Print text to the terminal.
history
- Show command history
clear
- Clear the terminal screen.
man <command>
- Show the manual for a command.
Conclusion
Mastering these basic Linux commands will help you navigate and manage your system more efficiently. As you become more comfortable, you can explore more advanced commands and scripting techniques to automate tasks. Keep practicing, and soon, working with Linux will become second nature. Happy coding!
Top comments (0)