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
pwdin any directory. Output might be/home/username/Documents.
- Example: Run
-
ls: Lists the contents of a directory.- Example:
ls -l /home/usernamedisplays detailed contents of theusernamedirectory. - Extra:
ls -ashows hidden files starting with..
- Example:
-
cd <directory>: Changes the current directory.- Example:
cd /home/username/Documentstakes 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.txtcreates an empty file namednotes.txtin the current directory.
- Example:
-
mkdir <directory>: Creates a new directory.- Example:
mkdir Projectscreates a new directory calledProjects.
- Example:
-
cp <source> <destination>: Copies files or directories.- Example:
cp notes.txt Projects/copiesnotes.txtinto theProjectsfolder. - Extra:
cp -r Documents/ Archives/copies the entireDocumentsdirectory toArchives.
- Example:
-
mv <source> <destination>: Moves or renames files or directories.- Example:
mv notes.txt ideas.txtrenamesnotes.txttoideas.txt.
- Example:
-
rm <filename>: Deletes files.- Example:
rm ideas.txtremovesideas.txt. - Extra:
rm -r OldProjectsdeletes theOldProjectsdirectory.
- 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.txtshows the contents ofnotes.txt.
- Example:
-
nano <filename>: Opens a file in the Nano text editor.- Example:
nano ideas.txtopensideas.txtfor editing.
- Example:
-
less <filename>: Views a file page-by-page without editing.- Example:
less bigfile.txtlets you scroll throughbigfile.txtone page at a time.
- Example:
- System Information and Management ๐ฅ๏ธ
Check system information, view processes, and manage users.
-
uname -a: Displays system information.- Example:
uname -amight output details likeLinux mypc 5.4.0-42-generic ....
- Example:
-
top: Shows a list of running processes, updated in real time.- Example: Run
topto monitor CPU and memory usage. Pressqto quit.
- Example: Run
-
ps aux: Displays a snapshot of currently running processes.- Example:
ps aux | grep firefoxshows iffirefoxis 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.shgives read, write, and execute permissions to the user.
- Example:
-
chown <user>:<group> <filename>: Changes the ownership of a file.- Example:
chown newuser:staff document.txtchanges the owner tonewuserand 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.txtsearches fornotes.txtin/home.
- Example:
-
grep <text> <filename>: Searches for specific text within a file.- Example:
grep "error" /var/log/syslogfinds lines with "error" in the system log.
- Example:
- Working with Package Managers ๐ฆ
Easily install, update, or remove software packages.
-
Debian/Ubuntu:
sudo apt updateandsudo apt install <package-name>- Example:
sudo apt install viminstalls the Vim editor.
- Example:
-
Fedora/CentOS:
sudo dnf install <package-name>- Example:
sudo dnf install nanoinstalls the Nano editor.
- Example:
-
Arch Linux:
sudo pacman -S <package-name>- Example:
sudo pacman -S gitinstalls Git on Arch.
- Example:
- Basic Network Commands ๐
Test network connections and configure network settings.
-
ping <hostname/IP>: Tests network connectivity.- Example:
ping google.comchecks if Googleโs server is reachable.
- Example:
-
ifconfig(orip a): Displays network interface configurations.- Example: Run
ifconfigto view IP addresses and network details for each interface.
- Example: Run
-
netstat: Shows network statistics and active connections.- Example:
netstat -andisplays all open ports and connections.
- Example:
-
curl <URL>: Transfers data from or to a server.- Example:
curl http://example.comfetches 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)