Introduction
Welcome to the world of Linux command line! 🌍 In this guide, you’ll learn essential Linux commands, file operations, and how to navigate the Linux system using the terminal. Whether you're new to Linux or just brushing up, this guide has you covered.
Remember, if you ever need more detailed information on a command, you can use man to access its manual page (for example, man ls for the ls command). Let’s get started! 🚀
- Navigating the File System 🗂️
The first step in mastering the Linux command line is learning to navigate the file system.
-
pwd
: Prints the current working directory.- Example: Run
pwd
in any directory. Output might be/home/username/Documents
.
- Example: Run
-
ls
: Lists the contents of a directory.- Example:
ls -l /home/username
displays detailed contents of theusername
directory. - Extra:
ls -a
shows hidden files starting with.
.
- Example:
-
cd <directory>
: Changes the current directory.- Example:
cd /home/username/Documents
takes you to the Documents directory. - Tip:
cd ..
moves up one directory level.
- Example:
- Managing Files and Directories 📁
Get hands-on with creating, moving, and deleting files and directories.
-
touch <filename>
: Creates a new empty file.- Example:
touch notes.txt
creates an empty file namednotes.txt
in the current directory.
- Example:
-
mkdir <directory>
: Creates a new directory.- Example:
mkdir Projects
creates a new directory calledProjects
.
- Example:
-
cp <source> <destination>
: Copies files or directories.- Example:
cp notes.txt Projects/
copiesnotes.txt
into theProjects
folder. - Extra:
cp -r Documents/ Archives/
copies the entireDocuments
directory toArchives
.
- Example:
-
mv <source> <destination>
: Moves or renames files or directories.- Example:
mv notes.txt ideas.txt
renamesnotes.txt
toideas.txt
.
- Example:
-
rm <filename>
: Deletes files.- Example:
rm ideas.txt
removesideas.txt
. - Extra:
rm -r OldProjects
deletes theOldProjects
directory.
- Example:
- Viewing and Editing Files 📄
Quickly view or edit file contents directly in the terminal.
-
cat <filename>
: Displays the content of a file.- Example:
cat notes.txt
shows the contents ofnotes.txt
.
- Example:
-
nano <filename>
: Opens a file in the Nano text editor.- Example:
nano ideas.txt
opensideas.txt
for editing.
- Example:
-
less <filename>
: Views a file page-by-page without editing.- Example:
less bigfile.txt
lets you scroll throughbigfile.txt
one page at a time.
- Example:
- System Information and Management 🖥️
Check system information, view processes, and manage users.
-
uname -a
: Displays system information.- Example:
uname -a
might output details likeLinux mypc 5.4.0-42-generic ...
.
- Example:
-
top
: Shows a list of running processes, updated in real time.- Example: Run
top
to monitor CPU and memory usage. Pressq
to quit.
- Example: Run
-
ps aux
: Displays a snapshot of currently running processes.- Example:
ps aux | grep firefox
shows iffirefox
is running.
- Example:
-
whoami
: Prints the current username.- Example: Run
whoami
, and you might seeusername
.
- Example: Run
- Managing Permissions 🔐
Set secure access by managing file permissions.
-
chmod <permissions> <filename>
: Changes the permissions of a file.- Example:
chmod 755 script.sh
gives read, write, and execute permissions to the user.
- Example:
-
chown <user>:<group> <filename>
: Changes the ownership of a file.- Example:
chown newuser:staff document.txt
changes the owner tonewuser
and group tostaff
.
- Example:
- Finding Files and Directories 🔍
Quickly locate files or directories on Linux.
-
find <directory> -name <filename>
: Searches for a file by name in a specified directory.- Example:
find /home -name notes.txt
searches fornotes.txt
in/home
.
- Example:
-
grep <text> <filename>
: Searches for specific text within a file.- Example:
grep "error" /var/log/syslog
finds lines with "error" in the system log.
- Example:
- Working with Package Managers 📦
Easily install, update, or remove software packages.
-
Debian/Ubuntu:
sudo apt update
andsudo apt install <package-name>
- Example:
sudo apt install vim
installs the Vim editor.
- Example:
-
Fedora/CentOS:
sudo dnf install <package-name>
- Example:
sudo dnf install nano
installs the Nano editor.
- Example:
-
Arch Linux:
sudo pacman -S <package-name>
- Example:
sudo pacman -S git
installs Git on Arch.
- Example:
- Basic Network Commands 🌐
Test network connections and configure network settings.
-
ping <hostname/IP>
: Tests network connectivity.- Example:
ping google.com
checks if Google’s server is reachable.
- Example:
-
ifconfig
(orip a
): Displays network interface configurations.- Example: Run
ifconfig
to view IP addresses and network details for each interface.
- Example: Run
-
netstat
: Shows network statistics and active connections.- Example:
netstat -an
displays all open ports and connections.
- Example:
-
curl <URL>
: Transfers data from or to a server.- Example:
curl http://example.com
fetches data fromexample.com
.
- Example:
Conclusion 🎉
Mastering these Linux commands will set a strong foundation for your journey into the Linux world. Keep practicing, try out new commands, and remember that the terminal is your friend! If you’d like to dive deeper into more advanced Linux skills, keep exploring and experimenting. Happy coding! 🐧
Top comments (0)