Mastering Linux Commands: A Beginner-to-Advanced Guide

Linux is an immensely powerful operating system famous for flexibility and tuns of control through its command-line interface or CLI. This article will group essential Linux commands and provide some examples to help you better understand and use Linux commands.

1. File and Directory Management

CommandDescriptionExample

pwd

Prints the current working directory.

$ pwd/home/user/Documents

ls

Lists files and directories.

$ lsfile1.txt file2.txt folder1

cd

Changes the current directory.

$ cd folder1 → Navigates into folder1.

mkdir

Creates a new directory.

$ mkdir new_folder → Creates a directory named new_folder.

touch

Creates an empty file.

$ touch new_file.txt → Creates a file named new_file.txt.

cp

Copies files or directories.

$ cp file1.txt /backup/ → Copies file1.txt to /backup/.

mv

Moves or renames files.

$ mv file1.txt renamed_file.txt → Renames the file.

rm

Deletes files or directories.

$ rm file1.txt → Deletes file1.txt.

find

Searches for files/directories.

$ find /home -name "*.txt" → Finds all .txt files in /home.

tree

Displays directories in tree form.

$ tree → Displays a tree-like structure of direct

2. File Viewing and Editing

CommandDescriptionExample
catDisplays file content.$ cat file1.txt → Outputs the content of file1.txt.
moreViews file content one screen at a time.$ more largefile.txt → Displays largefile.txt page by page.
lessSimilar to more but allows backward scrolling.$ less largefile.txt → Lets you scroll back and forth.
nanoEdits files with a simple text editor.$ nano notes.txt → Opens notes.txt in the Nano editor.
vimAdvanced text editor.$ vim script.sh → Opens script.sh for editing in Vim.
headDisplays the first lines of a file.$ head -n 5 file1.txt → Shows the first 5 lines.
tailDisplays the last lines of a file.$ tail -n 10 file1.txt → Shows the last 10 lines.

3. User Management

CommandDescriptionExample
whoamiDisplays the current user.$ whoamijohn_doe
idShows user ID and group ID.$ iduid=1000(john_doe) gid=1000(john_doe)
adduserAdds a new user.$ sudo adduser alice → Creates a new user named alice.
passwdChanges a user's password.$ passwd → Prompts to change the password.
chmodChanges file permissions.$ chmod 755 script.sh → Grants execute permissions.
chownChanges file ownership.$ sudo chown alice:alice file1.txt → Changes ownership to user alice.

4. Process Management

CommandDescriptionExample
psDisplays running processes.$ ps → Lists active processes for the current user.
topShows real-time system usage.$ top → Displays running processes, CPU, and memory usage.
killTerminates a process by PID.$ kill 1234 → Stops the process with PID 1234.
jobsLists active jobs.$ jobs[1]+ Running sleep 100 &
bgResumes a job in the background.$ bg %1 → Resumes job 1 in the background.
fgResumes a job in the foreground.$ fg %1 → Brings job 1 to the foreground.

5. Networking Commands

CommandDescriptionExample
pingTests connectivity to a host.$ ping google.com → Sends ICMP packets to google.com.
curlTransfers data from/to a server.$ curl -O https://example.com/file.zip → Downloads file.zip.
wgetDownloads files from the web.$ wget https://example.com/file.zip → Downloads file.zip.
sshConnects to a remote server.$ ssh user@192.168.1.1 → Opens an SSH session.

6. Disk Management

CommandDescriptionExample
dfDisplays disk space usage.$ df -h → Shows disk usage in a human-readable format.
duDisplays directory size.$ du -sh /var/log → Shows the size of /var/log.
lsblkLists block devices.$ lsblk → Displays attached drives and partitions.

7. Archiving and Compression

CommandDescriptionExample
tarArchives files.$ tar -cvf archive.tar folder/ → Creates archive.tar from folder/.
gzipCompresses files.$ gzip file1.txt → Creates file1.txt.gz.
gunzipExtracts .gz files.$ gunzip file1.txt.gz → Restores file1.txt.

8. Advanced Commands

CommandDescriptionExample
grepSearches for text in files.$ grep "error" logs.txt → Finds "error" in logs.txt.
awkProcesses text patterns.$ awk '{print $1}' file.txt → Displays the first column.
sedEdits text streams.$ sed 's/old/new/g' file.txt → Replaces "old" with "new".

Conclusion

Using examples, the participants will master the necessary commands and gain greater confidence while dealing with Linux systems. Would you like to know more about an extended use of a definite command? Let us know in the comments!