Using basic shell commands

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 up
  • cd ~ → 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 updatedb to 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 info
  • df -h → Disk usage
  • free -h → Memory usage
  • uptime → 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 -l shows permissions like -rw-r--r--
  • chmod changes permissions
$ chmod 644 report.txt
  • chown changes 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

TaskCommand Example
Show current folderpwd
List filesls -l
Move folderscd /var/log
Create filetouch file.txt
View filecat file.txt / less file.txt
Copy filecp file.txt backup.txt
Move/Rename filemv file.txt newname.txt
Remove filerm file.txt
Create directorymkdir myfolder
Remove directoryrmdir folder or rm -r folder
Search filefind / -name "*.conf"
View system infouname -a, df -h, free -h
Helpman command, command --help
Redirect output>, >>
Pipe commands`
Permissionschmod, 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.

Buy Me a Coffee