Introduction to Lin...
 
Notifications
Clear all

Introduction to Linux Command Line Basics


(@ejohnson)
Distro Dabbler Open Sourcerer
Joined: 11 months ago
Posts: 7
Topic starter  

One of the key strengths of Linux is its command line interface (CLI), which allows for efficient and precise control over the system. Whether you're new to Linux or just looking to brush up on your command line skills, this post will guide you through some essential command-line utilities and commands that are fundamental to navigating and managing a Linux environment.


Navigating the File System

1. The ls Command

The ls command lists the contents of a directory. By default, it will show the contents of the current directory.

Example:

$ ls
Desktop Documents Downloads Music Pictures Videos

2. The cd Command

The cd (change directory) command is used to move from one directory to another.

Example:

$ cd Documents
This command will move you into the "Documents" directory.

3. The pwd Command

The pwd (print working directory) command displays the path of the current directory you're in.

Example:

$ pwd
/home/username/Documents

Managing Files and Directories

4. The cp Command

The cp command is used to copy files or directories from one location to another.

Example:

$ cp file.txt /home/username/Desktop

This command copies "file.txt" to the Desktop.

5. The mv Command

The mv command moves files or directories from one location to another. It can also be used to rename files or directories.

Example:

$ mv file.txt newfile.txt

This command renames "file.txt" to "newfile.txt".

6. The rm Command

The rm (remove) command is used to delete files or directories.

Example:

$ rm unwanted_file.txt

This command deletes "unwanted_file.txt".


Text Processing

7. The cat Command

The cat (concatenate) command is used to display the content of a file.

Example:

$ cat file.txt
Hello, this is a text file.

8. The grep Command

The grep command is used to search for a specific pattern within files.

Example:

$ grep "Linux" file.txt
I love Linux command line.

This command searches for the word "Linux" in "file.txt".

9. The find Command

The find command is used to search for files and directories within a given directory.

Example:

$ find . -name "*.txt"
./file.txt
./newfile.txt

This command finds all ".txt" files in the current directory and its subdirectories.


System Information

10. The df Command

The df command displays information about disk space usage on all mounted filesystems.

Example:

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 15G 32G 30% /

11. The free Command

The free command shows the amount of free and used memory in the system.

Example:

$ free -h
total used free shared buff/cache available
Mem: 7.7G 1.2G 4.8G 123M 1.7G 6.0G
Swap: 2.0G 0B 2.0G

Personal Suggestions

  • Explore Man Pages: For any command, you can type man <command> to view its manual page, which contains detailed information about how the command works and its options.
  • Customize Your Environment: Learn about .bashrc or .bash_profile to customize your command line environment. Aliases can save you a lot of time!

Example in Ubuntu Terminal

Let's combine some of the commands we've learned in a simple session in the Ubuntu terminal:

$ pwd
/home/username
$ ls
Desktop Documents Downloads Music Pictures Videos
$ cd Documents
$ ls
file1.txt file2.txt project
$ cat file1.txt
This is file 1.
$ grep "file" file2.txt
This is file 2, which mentions file.
$ cd ..
$ find . -name "*.txt"
./Documents/file1.txt
./Documents/file2.txt

In this session, we navigated through directories, listed their contents, displayed the content of a file, searched for a pattern in another file, and used the find command to locate all ".txt" files within the home directory.

Conclusion

The Linux command line is a powerful tool that, once mastered, can significantly enhance your productivity and understanding of your system. The commands covered in this blog are just the beginning. As you become more comfortable with these basics, you'll discover that there's much more you can achieve with the command line.


I hope you found my dive into the Linux Command Line Basics both enlightening and enjoyable. But now, it's your turn to shine! Do you have a favorite command that feels like a secret superpower? Or maybe a nifty trick that makes the command line your playground? Spill the beans! Let's turn this thread into a treasure trove of command line gems, curated by none other than you, our savvy readers.


   
Quote
Share: