0% found this document useful (0 votes)
39 views

Linux Commands

Linux commands are programs that perform tasks by typing them in the terminal. Common Linux commands include: - man - displays manual pages to read documentation on commands - ls - lists contents of the current directory - mkdir - creates new directories - cd - changes the current directory - pwd - prints the absolute path of the current working directory - cp - copies files and directories - mv - moves or renames files and directories - rm - removes files and directories - clear - clears the terminal screen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Linux Commands

Linux commands are programs that perform tasks by typing them in the terminal. Common Linux commands include: - man - displays manual pages to read documentation on commands - ls - lists contents of the current directory - mkdir - creates new directories - cd - changes the current directory - pwd - prints the absolute path of the current working directory - cp - copies files and directories - mv - moves or renames files and directories - rm - removes files and directories - clear - clears the terminal screen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

BASIC LINUX COMMANDS

Introduction
Linux commands are just simple programs like a
program in windows. Typing command is like
clicking an icon in windows.

Sometimes commands take some extra


parameters to do extra work, we call them
flags.
man
man means manual pages, its like reading a manual
of any home appliance. In software it means
reading documentation. Good softwares have
always a good documentation part.

$ man <command>
$ man clear
ls (list items)

● The ls command ( lowercase L and


lowercase S ) lists the contents of your
current working directory.
● ls by default does not show
hidden files
● to see all files use ls -al
● -al is flag in this case
mkdir (make directory)
● creates a directory
● use -p to create as many directories.
● $ mkdir first/second/third -p
● $ cd first/second/third
cd (change directory)
● changes the current directory
● cd . to remain inside same directory
● cd .. to go back one directory
pwd (print working directory)
For example, to find out the absolute pathname of
your home-directory, type cd to get back to your
home-directory and then type

$ pwd
it will print current directory
~ Your Home Directory
By typing cd ~ in terminal it will take you to the
home directory of current user
$ cd ~
cp (copy)
copies a file or entire directory to another path If
you want to copy files from another directory to
current directory use a . for destination
$ cp <source_file> <destination_file>
Tip: Always read the error carefully and please
don't freak out :)
mv (move file)
move command renames or move a file

use -r flag to recursively move all files

$ mv file1.txt file2.txt
rm (remove)
rm removes a file or entire directory with -r flag

$ rm <file>
$ rm <directory> -r
clear
clears your screen

$ clear
cat
displays the content of files on screen.

$ cat file.txt
less
Iess is similar to cat but it displays content one
page at a time

$ less file.txt
head
head is a short version of less command. It
prints only first 10 lines.

You can set the number of lines by giving a -


<number> flag e.x
$ head -5 file.txt
tail
tail is opposite to head, it shows last 10 lines of the
file.
searching within text
You can use less command to search within
text. Do you remember what less command do?
After executing the less command use / and
type your required text to search
$ less file.txt
/science
grep (don't ask what that’s called :) )
This command search a file for specific word or a
pattern. for example
grep Science file.txt will search string Science in
file.txt

grep command by default is case sensitive


wc (word count)
counts number of words in a given file.

to find number of lines set the -l flag

$ wc -l file.txt
Writing input to output
type the cat command without file name. It will
start taking your text into output memory. Once
you press Ctrl + d the output will be printed on
screen.
$ cat
$ alpha
$ Ctrl + d
use cat to write a file
$ cat > file.txt
This will take your input and write to a file by
name file.txt from your input until Ctrl+d is
pressed.
Pipes
Piping means passing result of one command to
another command.

You can search in first 10 lines by using head and


grep command by piping
$ head file.txt | grep science
The wildcard *
The * character is a wildcard character. It
means it will ignore the part after and before
where its used
$ ls list*
will list all files starting with string list
$ ls *list
will list all files ending with string list
UNIX File System
Type ls -l and see the result

You might also like