Key Takeaways
1. Accessing Linux: Multiple Avenues to Get Started
In order to start learning your way around and putting your newfound knowledge to the test, you're going to need access to a Linux system.
Immediate Access. The quickest way to dive into Linux is through web-based command-line interfaces like SimpleShell.com, offering immediate access to a Linux server without setup. These are ideal for short sessions and trying out commands, but remember that your data is temporary.
Web Hosting. If you host a website, you might already have SSH access to a Linux server. Check your hosting provider's documentation for "SSH" or "shell access." Shared web hosting is an affordable option for gaining persistent shell access. Some providers include:
- 1and1.com
- BlueHost.com
- DreamHost.com
- HostGator.com
- Site5.com
Virtualization. For a more comprehensive experience, use VirtualBox to run a pre-installed Linux image on your Windows, Mac, or Linux system. Download VirtualBox and a CentOS or Ubuntu image from virtualboxes.org. This provides a personal Linux environment for in-depth exploration.
2. Connecting to a Linux Server: SSH and Telnet Explained
SSH stands for Secure Shell and it provides a way to connect to a server over a network, like the Internet.
Secure Shell (SSH). SSH is the primary protocol for connecting to Linux servers, offering encrypted communication for secure remote access. You'll need a username, password (or SSH key), server name/IP address, and potentially a port number.
SSH Clients. For Windows, PuTTY is a popular SSH client. Macs have a built-in Terminal application. The basic SSH command format is ssh -p port_number username@servername
. If no port is specified, the default port 22 is used.
SSH Keys. SSH keys provide a password-less login option, enhancing security. Generate keys using ssh-keygen
(Mac/Linux) or PuTTYgen (Windows). Share the public key with the server administrator and keep the private key secure.
3. Navigating the Shell: Your Command-Line Interface
The shell is nothing more than a program that accepts your commands and executes those commands.
Shell Interface. The shell is your primary interface for interacting with the Linux system. It interprets your commands and executes them. The shell prompt typically displays your username, server name, and whether you're a normal user ($) or superuser (#).
Basic Commands. Essential commands include:
ls
: Lists directory contentscd
: Changes directorypwd
: Displays the current directorycat
: Displays file contentsecho
: Displays argumentsman
: Displays command documentation
Learning by Doing. Use the man
command to learn about other commands. The PATH
environment variable lists directories where executable commands are located. Use which command
to find the exact location of a command.
4. Understanding the Linux Directory Structure: A Map of the System
Understanding the directory structure will help you in the future when you are searching for components on the system.
Root Directory. The root directory (/
) is the starting point of the file system hierarchy. It's not related to the root user account.
Common Directories. Key directories include:
/bin
: Essential binaries/etc
: System configuration files/home
: User home directories/opt
: Optional software/tmp
: Temporary files/usr
: User-related programs/var
: Variable data, like log files
Application Structure. Applications often follow a similar directory structure within /opt
or /usr/local
, with subdirectories for binaries, configuration, libraries, and logs.
5. Essential Linux Commands: Your Toolkit for Basic Operations
In Linux, commands are case-sensitive and more often than not they are entirely in lowercase.
Core Commands. A handful of commands can get you far:
ls
: List files and directoriescd
: Change directoriespwd
: Print working directorycat
: Display file contentecho
: Display textman
: Access the manualexit
: End sessionclear
: Clear the screen
Directory Navigation. Use .
for the current directory and ..
for the parent directory. The command cd -
takes you to the previous directory.
Command Execution. To execute a program in the current directory, use ./program
.
6. File Permissions: Understanding and Managing Access
The first character in the permissions string reveals the type.
Permission String. The ls -l
command displays a permission string like -rw-r--r--
. The first character indicates the file type (e.g., -
for file, d
for directory, l
for link). The next nine characters represent read (r
), write (w
), and execute (x
) permissions for the user, group, and others.
User Categories. Permissions apply to the user (owner), group, and others. Use the groups
command to see your group memberships.
Changing Permissions. Use chmod
to change permissions. Symbolic mode (e.g., chmod g+w file
) adds or removes permissions. Octal mode (e.g., chmod 755 file
) sets permissions directly using numeric values (4 for read, 2 for write, 1 for execute).
7. Finding Files: Locating What You Need
If you ever need to locate a file or directory you can use the find command.
The find
Command. The find
command is a powerful tool for locating files and directories based on various criteria. The basic syntax is find [path...] [expression]
.
Common Options. Useful options include:
-name pattern
: Finds files matching the pattern (case-sensitive)-iname pattern
: Finds files matching the pattern (case-insensitive)-ls
: Performs anls
on found files-mtime num_days
: Finds files modifiednum_days
ago-size num
: Finds files of sizenum
-exec command {} \;
: Executes a command on found files
The locate
Command. The locate
command is faster than find
because it searches a pre-built database. However, the database may not be up-to-date.
8. Viewing and Editing Files: Interacting with Content
Here are some simple commands that display the contents of files to the screen.
Viewing Files. Commands for viewing file content include:
cat
: Displays the entire filemore
: Browses a file page by pageless
: Likemore
, but allows backward movement and searchinghead
: Displays the beginning of a filetail
: Displays the end of a filetail -f
: Displays data as it's written to the file in real-time
Editing Files. nano
is a simple, user-friendly text editor. vi
and emacs
are more powerful but have a steeper learning curve.
The file
Command. Use the file
command to determine a file's type.
9. File Management: Manipulating Files and Directories
Eventually you will get tired of all the old files you created just laying around, cluttering up your home directory, and taking up precious space.
Removing Files. Use the rm
command to remove files. Use rm -r
to remove directories recursively. Be careful, as there is no "trash" and deleted files are gone.
Copying Files. Use the cp
command to copy files. Use cp -r
to copy directories recursively.
Moving and Renaming Files. Use the mv
command to move or rename files and directories.
Archiving and Compression. Use the tar
command to create archives. Use gzip
to compress files. Modern tar
versions support gzip compression with the -z
option (e.g., tar zcf archive.tar.gz directory
).
10. Customizing Your Shell: Making Linux Your Own
As you have seen in the "Welcome To Shell" chapter, default prompts can vary from system to system.
Customizing the Prompt. Customize your shell prompt by setting the PS1
environment variable (for bash, ksh, sh) or prompt
(for csh, tcsh, zsh). Use format strings like \u
(username), \h
(hostname), and \w
(current directory).
Creating Aliases. Create shortcuts for frequently used commands with the alias
command (e.g., alias ll='ls -l'
). Add aliases to your personal initialization files (e.g., .bash_profile
, .bashrc
) to make them persistent.
Interactive vs. Non-interactive Sessions. Understand the difference between interactive and non-interactive shell sessions. Ensure your configuration is loaded in both types of sessions by sourcing .bashrc
from .bash_profile
.
11. Processes and Job Control: Managing Running Programs
To display the currently running processes use the ps command.
Listing Processes. Use the ps
command to display running processes. Common options include -e
(all processes), -f
(full format), and -u username
(processes for a specific user).
Foreground and Background Processes. Run commands in the background by adding an ampersand (&
) to the end. Use jobs
to list background jobs, fg
to bring a job to the foreground, and bg
to background a suspended job.
Killing Processes. Use Ctrl-c
to kill a foreground process. Use the kill
command to send signals to processes, including the TERM
(15) and KILL
(9) signals.
12. Automating Tasks: Scheduling Jobs with Cron
If you need to repeat a task on a schedule, you can use the cron service.
Cron Service. The cron service schedules tasks to run automatically at specified times.
Crontab Format. Cron jobs are defined in crontab files. Each line specifies the schedule (minute, hour, day of month, month, day of week) and the command to execute.
Crontab Command. Use the crontab
command to manage cron jobs:
crontab -l
: List cron jobscrontab -e
: Edit cron jobscrontab -r
: Remove all cron jobs
Last updated:
Review Summary
Linux for Beginners receives mostly positive reviews, with an average rating of 4.02/5. Readers appreciate its beginner-friendly approach, comprehensive coverage of basic Linux commands, and additional resources for further learning. Some find it helpful for refreshing knowledge or learning new commands. However, criticisms include dated content, lack of depth in certain areas, and insufficient background information. The book is praised for its practical, hands-on approach but some feel it could benefit from more interactive elements and expanded explanations of abstract concepts.
Similar Books
Download PDF
Download EPUB
.epub
digital book format is ideal for reading ebooks on phones, tablets, and e-readers.