0% found this document useful (0 votes)
3 views29 pages

Unix Basic Commands

This document provides an introduction to basic Linux commands, the shell, and the kernel, detailing how to execute commands in the Linux terminal. It explains the functions of the kernel, the role of the shell as a command interpreter, and lists essential commands for file management, process management, and system navigation. Additionally, it covers command syntax, special characters, and provides examples for using various commands effectively.

Uploaded by

guptaadi197
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)
3 views29 pages

Unix Basic Commands

This document provides an introduction to basic Linux commands, the shell, and the kernel, detailing how to execute commands in the Linux terminal. It explains the functions of the kernel, the role of the shell as a command interpreter, and lists essential commands for file management, process management, and system navigation. Additionally, it covers command syntax, special characters, and provides examples for using various commands effectively.

Uploaded by

guptaadi197
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
You are on page 1/ 29

Introduction to basic Linux Commands,

Shell and Kernel

By:
Dr. H. K. Azad
Assistant Professor
SCOPE
Email: [email protected]
Linux Commands
• The Linux command is a utility of the Linux operating system. All basic
and advanced tasks can be done by executing commands. The commands
are executed on the Linux terminal. The terminal is a command-line
interface to interact with the system, which is similar to the command
prompt in the Windows OS.
• Commands in Linux are case-sensitive.
• Linux provides a powerful command-line interface compared to other
operating systems such as Windows and MacOS.
• Linux commands can be very simple one-word commands, or they can
take a number of additional arguments (parameters) as part of the
command. In general, a Linux command has the following form:
command options(s) filename(s)
• The command is the name of the utility or program that we are going to
execute.
• In Linux, the command is almost always entered in all lowercase
characters.
Introduction to Linux Shell and Kernel
• What is Kernel?

The kernel is a computer program that is the core of a computer’s


operating system, with complete control over everything in the system.
It manages following resources of the Linux system –
• File management
• Process management
• I/O management
• Memory management
• Device management etc
It is often mistaken that Linus Torvalds has developed Linux OS, but
actually he is only responsible for development of Linux kernel.
Complete Linux system = Kernel + GNU system utilities and libraries +
other management scripts + installation scripts.
What is Shell?
• A shell is special user program which provide an interface to user to
use operating system services.
• Shell accept human readable commands from user and convert them
into something which kernel can understand.
• It is a command language interpreter that execute commands read
from input devices such as keyboards or from files.
• The shell gets started when the user logs in or start the terminal.

Shell is broadly classified into two categories –


• Command Line Shell
• Graphical shell
What the ~*&?!

~ “tilde” indicates your home directory: /home/you


* “star”: wildcard, matches anything
? wildcard, matches any one character
! History substitution, do not use
& run a job in the background, or redirect errors
#% special characters for most crystallography programs
`\([“’ back-quote, backslash, etc. special to shell
_ underscore, use this instead of spaces!!!
What is the $ and # signs in Linux environment?

• If the screen shows a dollar sign ($) or hash (#) on the left of the blinking
cursor, you are in a command-line environment.

• $, #, % symbols indicate the user account type you are logged in to.

•Dollar sign ($) means you are a normal user


•hash (#) means you are the system administrator (root)
•In the C shell, the prompt ends with a percentage sign (%)
Who am I?

uname
Prints the kernel name

uname is a command-line utility that prints basic information about


the operating system name and system hardware.
As you already know, the name of the kernel is “Linux”
Where am I?

pwd
Print name of the “current working directory”

This is the default directory/folder where the shell program will look
first for programs, files, etc. It is “where you are” in Unix space.
What have we here?

ls
List contents of the current working directory

ls –l - long listing, with dates, owners, etc.


ls –lrt - above, but sorted by time
ls –lrt /home/yourname/something
- long-list a different directory
Go somewhere else?

cd
Change the current working directory
cd /tmp/yourname/
- go to your temporary directory
cd - - go back to where you just were
cd - no arguments, go back “home”
“home” is where your login starts
A new beginning…

mkdir
Create a new directory.

mkdir ./something - make it


cd ./something - go there
ls - check its is empty
How do I get help?

man
Display the manual for a given program

man ls - see manual for the “ls” command


man tcsh - learn about the C shell
man bash - learn about that other shell
man man - read the manual for the manual

to return to the command prompt, type “q”


Move it!

mv
Move or rename a file. If you think about it, these are the same
thing.

mv stupidname.txt bettername.txt
- change name
mv stupidplace/file.txt ../betterplace/file.txt
- same name, different directory
mv stupidname_*.img bettername_*.img
Will not work! Never ever do this!
Copy machine

cp
Copy a file. This is just like “mv”
except it does not delete the
original.
cp stupidname.txt bettername.txt
- change name, keep original
rm stupidname.txt
- now this is the same as “mv”
“Permission denied” !?

chmod
Change the “permission” of a file.
chmod a+r filename.txt
- make it so everyone can read it
chmod u+rwx filename.txt
- make it you can read/write/execute it
chmod –R u+rw /some/random/place
- make it so you can read/write everything under
a directory
Destroy! Destroy!

rm
Remove a file forever. There is no “trash” or “undelete” in unix.

rm unwanted_file.txt
- delete file with that name
rm –f /tmp/yourname/*
- forcefully remove everything in your temporary
directory.
Will not prompt for confirmation!
less is more

more
Display the contents of a text file, page by page

more filename.txt - display contents


less filename.txt - many installs now have a
replacement for “more” called “less” which has nicer search
features.

to return to the command prompt, type “q”


After the download…

gunzip
File compression and decompression

gunzip ~/Downloads/whatever.tar.gz
- decompress
gzip ~/Downloads/whatever.tar
- compress, creates file with .gz extension
Where the %$#& is it?

find
Search through directories, find files

find ./ -name ’important*.txt’


- look at everything under current working directory
with name starting with “important” and ending in “.txt”
find / -name ’important*.txt’
- will always find it, but take a very long time!
Did I run out of disk space?

df du
Check how much space is left on disks

df - look at space left on all disks


df . - look at space left in the current working
directory
du –sk . | sort –g
- add up space taken up by all files and
subdirectories, list biggest hog last
Why so slow?

ps top
Look for programs that may be eating up CPU or memory.

top - list processes in order of CPU usage


jobs - list jobs running in background of current
terminal
ps –fHu yourname
- list jobs belonging to your account in order of what
spawned what
Die Die Die!

kill
Stop jobs that are running in the background

kill %1 - kill job [1], as listed in “jobs”


kill 1234 - kill job listed as 1234 by “ps” or “top”
kill -9 1234 - that was not a suggestion!
kill -9 -g 1234 – seriously kill that job and the
program that launched it
Commands
• ls : lists the contents of a directory
• l : long directory listing
• a : lists all files, including files which are normally hidden
• F : distinguishes between directories and regular files
• h : ? Look it up using man
• pwd : prints the current working directory
• cd : changes directories
• The difference between relative and absolute paths.
• Special characters ., .., and ~.
• mkdir : creates a directory
• rmdir : removes a directory (assuming it is empty)
• If you get an error that the directory isn’t empty even though it looks
empty, check for hidden files.
Commands

• touch : creates an empty file with the specified


name, or if the file already exists it modifies the
timestamp.
• rm : removes a file.
• f : force deletion
• r : recursive deletion
• mv - moves a file, or renames a file
• f : forces overwrite, if the destination file exists
• cp - copies a file, leaving the original intact
• f : forces overwrite, if the destination file exists
• r : recursive copying of directories
Commands

• cat : shows the contents of a file, all at once


• more : shows the contents of a file, screen by screen
• less : also shows the contents of a file, screen by screen
• head : used to show so many lines form the top of a file
• tail : used to show so many lines form the bottom of a file
Commands

• lpr : prints a file


• alias : creates an alias for a command.
• Aliases can be placed in your .cshrc login script.
• Example: alias rm ‘rm –i’.
• date : shows the date and time on the current system
• who : used to print out a list of users on the current
system
• hostname : prints the hostname of the current
computer
• whoami : prints your current username
The UNIX Pipe (|)

• The pipe (|) creates a channel from one command to


another. Think of the pipe as a way of connecting the output
from one command to the input of another command.
• The pipe can be used to link commands together to perform
more complex tasks that would otherwise take multiple
steps (and possibly writing information to disk).
• Examples:
• Count the number of users logged onto the current system.
• The who command will give us line by line output of all the current users.
• We could then use the wc -l to count the number of lines...
• who | wc –l
• Display long listings in a scrollable page.
• The lpq command will give us a list of the waiting print jobs.
• lpq | less
Commands

• ps : lists the processes running on the machine.


• ps -u username lists only your processes.
• ps -a : lists all processes running on the machine.
• The PID column of the listing, provides the information
required by the kill command.
• kill : terminates a process
• kill process_id : sends a terminate signal to the process
specified by the process_id (PID).
• In cases where the terminate signal does not work, the
command "kill -9 process_id" sends a kill signal to the
process.
• nice : runs a process with a lower priority.
❖Online Ubuntu Practice Lab
• https://labex.io/courses/linux-basic-commands-practice-online

Thanks

You might also like