The Command Line Interface (CLI) is a powerful tool for interacting with your computer’s operating system. Understanding CLI basics can significantly enhance your productivity, especially as a developer. Here’s a guide to get you started with the CLI, including common commands, usage examples, and resources for further learning.
1. What is CLI?
The Command Line Interface (CLI) allows you to interact with your computer using text-based commands. It provides a more direct and often faster way to perform tasks compared to graphical user interfaces (GUIs).
2. Basic Commands
2.1 Navigating the File System
-
pwd
: Print Working Directory$ pwd /Users/username/Documents
-
ls
: List Directory Contents$ ls file1.txt file2.txt folder
cd
: Change Directory$ cd Documents $ pwd /Users/username/Documents
2.2 File Operations
-
cp
: Copy Files or Directories$ cp file1.txt file2.txt backup/
-
mv
: Move or Rename Files or Directories$ mv file1.txt file2.txt backup/
-
rm
: Remove Files or Directories$ rm file1.txt
2.3 Viewing File Content
-
cat
: Concatenate and Display File Content$ cat file1.txt
-
less
: View File Content One Page at a Time$ less file1.txt
grep
: Search for Patterns in Files$ grep "search_term" file1.txt
3. Managing Processes
-
ps
: Display Information About Running Processes$ ps aux
-
top
: Display a Dynamic View of System Processes$ top
-
kill
: Terminate Processes$ kill 1234
4. Permissions and Ownership
-
chmod
: Change File Permissions$ chmod 755 file1.txt
-
chown
: Change File Owner and Group$ chown user:group file1.txt
5. Creating and Managing Archives
-
tar
: Archive Files$ tar -cvf archive.tar file1.txt file2.txt
-
zip
: Compress Files into a ZIP Archive$ zip archive.zip file1.txt file2.txt
6. Useful Resources
6.1 YouTube Tutorials
6.2 GitHub Repositories
- CLI Basics - Examples and Tutorials
- Awesome CLI Tools - A collection of command line tools and tips.
6.3 Articles and Guides
7. Demo: Creating and Listing Files
# Create a directory
$ mkdir demo_directory
# Change into the directory
$ cd demo_directory
# Create a file
$ touch demo_file.txt
# List files
$ ls
demo_file.txt
With these basics, you’re well on your way to becoming proficient with the CLI. As you continue to use these commands, you’ll discover even more powerful ways to interact with your system.
Happy coding!