2.1 Command Line Basics (Weight: 3)
📘Linux Essentials (LPI 010-160)
The shell is a program that lets you interact with the Linux operating system. The most common shell is Bash. You type commands into the shell, and the system executes them. Basic shell commands are the building blocks of Linux administration.
Here’s a detailed guide:
1. Navigating the File System
Linux stores files in a hierarchical structure, starting from the root directory /. To work effectively, you must know commands for moving around and listing files.
a) pwd – Print Working Directory
- Shows the current folder you are in.
- Example:
$ pwd
/home/pooja
This tells you that you are in the /home/pooja directory.
b) ls – List Files
- Shows files and folders in the current directory.
- Common options:
ls -l→ long listing (permissions, size, date)ls -a→ shows hidden files (starting with.)
- Example:
$ ls -la
drwxr-xr-x 2 pooja pooja 4096 Mar 3 12:00 .
-rw-r--r-- 1 pooja pooja 23 Mar 2 10:00 file.txt
This shows all files with details like permissions and size.
c) cd – Change Directory
- Moves between directories.
- Example:
$ cd /etc
$ pwd
/etc
cd ..→ go one level upcd ~→ go to your home directory
IT Example: A sysadmin might cd /var/log to check server logs.
2. Creating, Viewing, and Managing Files
a) touch – Create an empty file
$ touch report.txt
b) cat – Display file content
$ cat report.txt
c) less or more – View large files
- Useful for logs (
/var/log/syslog) so you don’t flood the terminal.
$ less /var/log/syslog
d) cp – Copy files
$ cp report.txt backup_report.txt
e) mv – Move or rename files
$ mv report.txt archive_report.txt
f) rm – Remove files
$ rm archive_report.txt
IT Example: Backing up configuration files before making changes.
3. Working with Directories
a) mkdir – Create a directory
$ mkdir projects
b) rmdir – Remove an empty directory
$ rmdir old_projects
c) rm -r – Remove a directory with files
$ rm -r temp_folder
IT Example: Creating directories for different servers or virtual machines, then organizing configuration files.
4. Getting Help
Linux commands come with built-in help. Two main ways:
a) man – Manual
$ man ls
Shows full documentation of the ls command.
b) --help – Quick help
$ ls --help
Displays options quickly.
IT Example: Checking the options for tar when archiving server backups.
5. Finding Files
a) find – Search for files
$ find /etc -name "*.conf"
Searches for all .conf files in /etc.
b) locate – Fast search using database
$ locate sshd_config
- Faster but might need
updatedbto refresh the database.
IT Example: Locating configuration files for a web server like Apache.
6. Viewing System Information
Basic commands help you know your system state:
uname -a→ Kernel and system infodf -h→ Disk usagefree -h→ Memory usageuptime→ How long the system has been running
IT Example: Checking server resources before starting a resource-heavy task.
7. Using Command History and Autocomplete
history→ Shows previously typed commands.- Use the up arrow to scroll through previous commands.
- Use Tab for autocomplete folder and file names.
IT Example: Saves time when managing multiple servers or scripts.
8. Redirection and Pipes
Redirect output or input for commands:
>→ Send output to a file (overwrite)
$ echo "Hello Linux" > hello.txt
>>→ Append output
$ echo "Another line" >> hello.txt
|→ Pipe output of one command to another
$ cat /var/log/syslog | grep "error"
IT Example: Filtering log files for specific errors on a web server.
9. Permissions and Ownership (Basic)
ls -lshows permissions like-rw-r--r--chmodchanges permissions
$ chmod 644 report.txt
chownchanges ownership
$ chown pooja:pooja report.txt
IT Example: Making sure only the admin can modify critical configuration files.
✅ Summary – Key Commands to Know for the Exam
| Task | Command Example |
|---|---|
| Show current folder | pwd |
| List files | ls -l |
| Move folders | cd /var/log |
| Create file | touch file.txt |
| View file | cat file.txt / less file.txt |
| Copy file | cp file.txt backup.txt |
| Move/Rename file | mv file.txt newname.txt |
| Remove file | rm file.txt |
| Create directory | mkdir myfolder |
| Remove directory | rmdir folder or rm -r folder |
| Search file | find / -name "*.conf" |
| View system info | uname -a, df -h, free -h |
| Help | man command, command --help |
| Redirect output | >, >> |
| Pipe commands | ` |
| Permissions | chmod, chown |
These are all the essential commands you need to know for using the Linux shell in the LPI 010-160 exam. Understanding what each command does, its common options, and examples will give you a solid foundation.
