0% found this document useful (0 votes)
2 views8 pages

Simple Linux Commands Guide

This guide provides beginner-friendly explanations of essential Linux terminal commands, including navigation, file management, and script creation. Each command is accompanied by a simple meaning and example usage. The document also includes tips, warnings, and practice tasks to reinforce learning.

Uploaded by

nokutenda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Simple Linux Commands Guide

This guide provides beginner-friendly explanations of essential Linux terminal commands, including navigation, file management, and script creation. Each command is accompanied by a simple meaning and example usage. The document also includes tips, warnings, and practice tasks to reinforce learning.

Uploaded by

nokutenda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SIMPLE LINUX COMMANDS GUIDE

Beginner-Friendly Notes for Cramming and Practice


Based on the uploaded Linux Tutorial PDF

This guide explains the Linux terminal commands in simple English. Each command has a meaning,
example, and short warning where necessary.

Simple Linux Commands Guide


1. Basic Navigation Commands
These commands help you move around folders and see where you are in the Linux file system.

Command Simple Meaning Example


pwd Shows your current location/folder pwd
Lists files and folders in the current
ls ls
folder
ls -a Lists all files, including hidden files ls -a
ls -l Lists files with more details ls -l
cd foldername Moves into a folder cd unixstuff
cd .. Moves one folder back/up cd ..
cd Returns to your home folder cd
cd ~ Also returns to your home folder cd ~

pwd
ls
mkdir unixstuff
cd unixstuff
pwd
cd ..

Exam tip: If you are lost in Linux, type cd to go back to the home directory, then type pwd to confirm your
location.

2. Creating and Removing Directories


Command Simple Meaning Example
mkdir foldername Creates a new folder mkdir backups
rmdir foldername Deletes an empty folder rmdir tempstuff
Deletes a folder and everything inside
rm -r foldername rm -r oldfolder
it

mkdir backups
mkdir tempstuff
rmdir tempstuff

Warning: Use rm -r carefully because it deletes permanently in the terminal.

3. Copying, Moving, Renaming and Deleting Files


Command Simple Meaning Example
cp file1 file2 Copies file1 and names the copy file2 cp [Link] [Link]
cp file . Copies a file into the current folder cp /path/[Link] .
cp -R folder1 folder2 Copies a folder and all its contents cp -R tutorial backup
mv file folder/ Moves a file into a folder mv [Link] backups/
mv oldname newname Renames a file or folder mv file1 file2
rm filename Deletes a file rm [Link]

cp [Link] [Link]
mv [Link] backups/
Simple Linux Commands Guide
rm [Link]

Remember: mv can mean move OR rename depending on how you use it.

4. Viewing File Contents


Command Simple Meaning Example
cat file Displays the whole file cat [Link]
less file Displays a long file page by page less [Link]
head file Shows the first 10 lines head [Link]
head -5 file Shows the first 5 lines head -5 [Link]
tail file Shows the last 10 lines tail [Link]
tail -15 file Shows the last 15 lines tail -15 [Link]
clear Clears the terminal screen clear

Inside less Meaning


Spacebar Move to the next page
q Quit less
/word Search for a word
n Go to the next search result

5. Searching Inside Files


Command Simple Meaning Example
grep word file Finds lines containing the word grep science [Link]
Searches without caring about capital
grep -i word file grep -i science [Link]
letters
grep -n word file Shows matching line numbers grep -n science [Link]
grep -c word file Counts matching lines grep -c science [Link]
Shows lines that do NOT contain the
grep -v word file grep -v science [Link]
word

grep -i 'spinning top' [Link]

Important: grep is case sensitive by default. Use -i when you want to ignore capital and small letters.

6. Counting Lines, Words and Characters


Command Simple Meaning Example
wc -w file Counts words wc -w [Link]
wc -l file Counts lines wc -l [Link]
wc -m file Counts characters wc -m [Link]

7. Redirection: Sending Output to Files


Redirection means sending command output somewhere else, usually into a file instead of the screen.

Symbol/Command Simple Meaning Example


Simple Linux Commands Guide
Writes output to a file and replaces old
> echo "Hello" > [Link]
content
>> Adds output at the end of a file echo "kiwi" >> biglist
< Uses a file as input sort < biglist
2> Sends error messages to a file command 2> [Link]

echo "Hello" > [Link]


echo "World" >> [Link]
cat [Link]

Main difference: > overwrites the file, but >> appends/adds to the file.

8. Pipes
A pipe uses the output of one command as the input of another command. The pipe symbol is |

Command Simple Meaning


who Shows users currently logged in
who | sort Sorts the list of logged-in users
who | wc -l Counts login sessions
who | grep username Finds sessions for one user

who | wc -l

9. Wildcards
Wildcard Meaning Example
* Matches any number of characters ls *.txt
? Matches exactly one character ls ?ouse
{1,2} Matches selected options ls list{1,2}

ls *.txt
mkdir newdir{1,2,3}

10. Getting Help


Command Simple Meaning Example
man command Opens full manual/help page man wc
whatis command Gives a short description whatis wc
apropos keyword Finds commands related to a keyword apropos list

11. File Permissions


Permissions control who can read, change, or run a file.

Symbol Meaning

Simple Linux Commands Guide


r Read permission
w Write/change permission
x Execute/run permission
- Permission is missing
d This item is a directory

ls -l
chmod a+rw biglist
chmod go-rwx biglist

Command Meaning
chmod a+rw biglist Give all users read and write permission
chmod go-rwx biglist Remove read, write, and execute from group and others

12. Processes and Jobs


Command Simple Meaning Example
ps Shows current processes ps
command & Runs a command in the background sleep 10 &
jobs Lists background or suspended jobs jobs
fg %1 Brings job 1 to the foreground fg %1
Continues a suspended job in the
bg bg
background
kill %1 Kills job number 1 kill %1
kill PID Kills process using its process ID kill 20077
kill -9 PID Force kills a process kill -9 20077

Shortcut Meaning
Ctrl + C Stops a running command
Ctrl + Z Suspends a running command

13. Disk Space and File Tools


Command Simple Meaning Example
df -h . Shows free disk space in readable form df -h .
du -sh * Shows file/folder sizes du -sh *
gzip file Compresses a file gzip [Link]
gunzip [Link] Uncompresses a file gunzip [Link]
file filename Shows the type of file file [Link]
history Shows commands you typed before history

History Shortcut Meaning


!! Runs the last command again
!-3 Runs the third most recent command
!grep Runs the last command that started with grep

Simple Linux Commands Guide


14. Finding Files
Command Simple Meaning Example
Finds a file from the current folder
find . -name filename find . -name file1
downwards
find . -name "file*" Finds files starting with file find . -name "file*"
locate filename Quickly searches for a file locate [Link]
Searches without caring about capital
locate -i filename locate -i science
letters

15. Variables
Variables store values. In Linux, you use $ when you want to read/use a variable.

Command Meaning
echo $USER Shows your username
echo $HOME Shows your home folder path
echo $PATH Shows where Linux searches for commands
env Shows environment variables
HISTSIZE=2000 Sets history size for the current shell
export HISTSIZE=2000 Makes the variable available to other processes

HISTSIZE=2000
echo $HISTSIZE
export HISTSIZE=2000

16. Simple Shell Scripts


A shell script is a file that contains Linux commands. It is useful for automating repeated tasks.

16.1 Basic Script


#!/bin/bash
echo "Hello $USER"

chmod +x [Link]
./[Link]

Line Meaning
#!/bin/bash Tells Linux to run the script using bash
echo "Hello $USER" Prints a greeting using your username
chmod +x [Link] Makes the script executable
./[Link] Runs the script

17. Script with Variables


#!/bin/bash
echo "Hello $USER"

Simple Linux Commands Guide


NUMLOGINS=$(who | grep $USER | wc -l)

echo "You have $NUMLOGINS login sessions"

Part Meaning
NUMLOGINS= Creates a variable called NUMLOGINS
$(command) Runs a command and stores its output
who | grep $USER | wc -l Counts how many sessions the current user has

18. Loops in Shell Scripts


A loop repeats commands many times.

#!/bin/bash

for i in 1 2 3 4 5
do
echo "loop $i"
done

#!/bin/bash

for i in {1..20}
do
echo "loop $i"
done

Meaning: The commands between do and done are repeated for each value of the variable.

19. If Statements in Shell Scripts


An if statement allows a script to make a decision.

#!/bin/bash

NUMLOGINS=$(who | grep $USER | wc -l)

if [ $NUMLOGINS -gt 1 ]
then
echo "$USER is logged in with at least 2 sessions"
else
echo "$USER has less than 2 sessions"
fi

Operator Meaning
-eq Equal to
-ne Not equal to
-gt Greater than
-ge Greater than or equal to
-lt Less than
-le Less than or equal to
Simple Linux Commands Guide
20. Fast Cramming Summary
Command Remember it as
ls List files
pwd Print where I am
cd Change directory
mkdir Make folder
cp Copy
mv Move or rename
rm Remove file
rmdir Remove empty folder
cat Show file
less Read file page by page
head First lines
tail Last lines
grep Search inside file
wc Count words, lines, or characters
chmod Change permissions
ps Show processes
kill Stop process
find Find files
history Show previous commands
> Save output
>> Add output
| Send output to another command

21. Mini Practice Tasks


1. Create a directory called practice.
2. Move into the practice directory.
3. Create a file called [Link] using echo and >.
4. Add another line into [Link] using >>.
5. Display [Link] using cat.
6. Count the number of lines using wc -l.
7. Search for one word using grep.
8. Go back to the home directory using cd.

mkdir practice
cd practice
echo "Linux is useful" > [Link]
echo "I am learning commands" >> [Link]
cat [Link]
wc -l [Link]
grep Linux [Link]
cd

Simple Linux Commands Guide

You might also like