Day 5 of 100 days: Mastering Command Line Basics and Key Linux Directories
Today’s focus is on understanding the command line’s power and the core Linux directories. Command-line proficiency can significantly enhance productivity, giving you control and flexibility over your tasks.
Why Use the Command Line?
- Efficient Task Management
Using the command line lets you quickly complete tasks without navigating through multiple windows. Imagine needing to check a directory’s contents or move files: with a simple command, you save time and minimize interruptions.
Key Directories in Linux
Understanding the main Linux directories helps you navigate the system efficiently:
/bin: Essential programs needed to boot the system and run in single-user mode.
/etc: Configuration files for the system and installed software.
/home: Default directory for user files; each user has a subdirectory here.
/var: Stores variable data, including logs and spooled files.
/usr: Contains user-installed software and libraries.
/tmp: A temporary directory for files meant to be deleted after a short period.
Navigating the Filesystem
To explore the Linux filesystem, use these basic commands:
pwd
: Displays the current directory path.cd
: Changes the current directory.ls
: Lists files in the current directory.mkdir
: Creates a new directory.
Understanding File Permissions
Permissions are central to Linux security, determining who can access or modify files. These permissions are assigned to three user types:
Owner: The file creator.
Group: Users with specific shared permissions.
Others: All remaining users.
Permission Types
Each file and directory permission can be set to one of these types:
Read (r): Allows reading the file's content.
Write (w): Permits modifications or deletions.
Execute (x): Allows the file to be executed if it’s a script or binary.
Permissions are represented by letters or dashes, for example: -rw-r--r--
.
In this example:
Owner: Can read and write (
rw-
)Group: Can read only (
r--
)Others: Can read only (
r--
)
This layout shows that the owner has more control over the file, while group members and other users have limited access, ensuring basic security.
Changing Permissions Using chmod
To modify file permissions, use the chmod
command with permission numbers. Each number represents different levels of access:
7: Read, write, execute
6: Read, write
5: Read, execute
4: Read only
Here are some examples:
chmod 755
script.sh
- Owner can read, write, execute; others can read, execute.
chmod 644 document.txt
- Owner can read, write; others can read only.
chmod 700 private_folder
- Owner has full access; others have no access.
chmod 600 secrets.txt
- Owner can read, write; others have no access.
chmod 777 public_
script.sh
- Everyone can read, write, and execute.
chmod 555 read_only_
file.sh
- All can read, execute; no one can write.
chmod 400 view_only_config.conf
- Owner can read; no other access allowed.
These examples provide a quick way to control file access and safeguard sensitive files.
Conclusion
Today’s dive into command-line basics and Linux directories shows just how essential command-line skills are in DevOps. With tools like chmod
and cd
, managing Linux systems becomes seamless, while understanding directory structures allows you to navigate and organize files efficiently. Mastering these basics will be invaluable as we delve deeper into DevOps concepts.