Essential Linux Commands for Developers: A Beginner's Guide
Written on
Chapter 1: Introduction to Linux Commands
Linux is a widely used operating system among developers, making it beneficial to familiarize oneself with essential commands.
In this article, we’ll explore several key Linux commands that every developer should know.
Section 1.1: Understanding the uname Command
The uname command is useful for displaying information about the current operating system and the machine it’s running on.
- Use the -m option to display the hardware name.
- The -p option shows the processor architecture.
- To get the OS name, use the -s switch.
- The -r option reveals the release version, while -v provides the version number.
- Finally, -n displays the node network name, and -a prints all available information.
Section 1.2: Accessing Manual Pages with man
The man command allows you to access the help documentation for any command.
You can simply type man <command> to view its manual. Man pages are categorized into seven sections:
- User commands
- Kernel system calls
- C library functions
- Devices
- File formats and filesystems
- Games
- Miscellaneous commands and conventions
- Superuser and system administrator commands
Chapter 2: Searching and Filtering with grep
The grep command is a powerful tool for searching text using patterns.
For example, to find the word "document" in index.md, you would run:
grep -n document index.md
The -n option will display the line numbers where the keyword appears. Additionally, you can combine grep with other commands. For instance:
less index.md | grep -n document
This command opens index.md with less and pipes the output to grep to search for "document". To exclude a specific string from your results, use the -v option.
This video, "The 50 Most Popular Linux & Terminal Commands - Full Course for Beginners," provides an extensive overview of commonly used commands.
Section 2.1: Setting Permissions with umask
The umask command is essential for establishing default file permissions.
Running umask without any arguments will show the current permission mask, represented as an octal number.
For a more understandable format, use:
umask -S
The permission digits represent:
- 0 — read, write, execute
- 1 — read and write
- 2 — read and execute
- 3 — read-only
- 4 — write and execute
- 5 — write-only
- 6 — execute only
- 7 — no permissions
You can set a new permission mask by providing an argument, such as:
umask 002
Or specify permissions by role:
umask g+rdu
Section 2.2: Managing Disk Usage with du
The du command helps calculate the disk space used by files and directories.
For instance, to view the sizes of items in a directory, simply run:
du -a
You can sort the results using:
du -h | sort -nr
Chapter 3: Viewing Command History
The history command allows you to view previously executed commands.
You can repeat a command by referencing its number from the history list. To clear your command history, just run:
history -c
The video "Linux Command Options and History" offers insights into command options and managing command history effectively.
Conclusion
Through the use of various Linux commands, you can efficiently manage files, search outputs, and keep track of your command history. Familiarizing yourself with these commands will enhance your productivity as a developer.