Lecture # 3,4 (Basic Shell Command, Ubento)
Lecture # 3,4 (Basic Shell Command, Ubento)
Lecture # 3,4
Basic Shell Commands
Today's Agenda
● Shell & Commands Basics
● Basic Commands
● Getting Help (Using Man Pages)
● Absolute and Relative Path
● More Commands
● Practising Commands
Basic Commands
Basic Commands
ls - list directory contents
SYNOPSIS
ls [OPTIONS]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by
default). Sort entries alphabetically by default.
Options:
-l display in long listing format (8 x columns)
-a do not ignore entries starting with a dot (i.e., hidden files)
-i show inode number of each file (used with long listing only)
-h show file size in human readable, i.e. In KBs (used with long listing only)
-t sort by modification time
-S, sort by size
-F adds a / in front of directory, an * in front of executable
DESCRIPTION
Print the full filename of the current working directory.
Example of pwd
DESCRIPTION
A regular user can change his own password only. However the
administrator can change the password of any user by preceding the
name of the user after the command passwd.
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Examples of mkdir
Examples
DESCRIPTION
Remove the DIRECTORY(ies), if they are empty.
Options:
-p, Create/Remove DIRECTORY and its ancestors. E.g., rmdir -p
a/b/c is similar to rmdir a/b/c a/b a
Example of rmdir
DESCRIPTION
Update the access and modification times of each FILE to the
current time.
Example of touch
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to
DIRECTORY.
Options:
-r, Recursively copies directory including files and subdirectories to
destination
-p, Preserves file access modes and time stamps on copied files
DESCRIPTION
Rename SOURCE to DEST, or move SOURCE(s) to
DIRECTORY. Do not require -r flag for directories. More so, this
command is also used to rename files and directores
Options:
-i Prompt user before ovwrwriting destination
DESCRIPTION
rm removes each specified file. By default, it does not remove
directories.
Options:
-r, -R, --recursive remove directories and their contents recursively
To avoid prompts
use -f along with
other options
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
Options:
-n, Print line # with each line of the file (for display only)
-ev, Print $ sign, at the end of each line
DESCRIPTION
More is a filter for paging through text one screenful at a time.
Example of more
DESCRIPTION
Echo the STRING(s) to standard output.
Options:
-e enable interpretation of backslash escapes
Getting Help
of the help pages, so you can use all techniques that you have
learnt for navigation and searching in the less program.
patterns of 'pwd'
Directory Tree:
/
More Commands
DESCRIPTION
Which takes one or more arguments. It searches an executable or
script in the directories listed in the environment variable PATH
Option:
-a Print all matching executables in PATH, not just the first
Example of which
DESCRIPTION
whereis locates source/binary and manuals sections for specified
files. Whereis then attempts to locate the desired program in a list of
standard Linux places.
Options:
-b Search only for binaries
-m Search only for manual sections
-s Search only for sources
● Executable
● Data
More Commands:
find - search for files in a directory hierarchy
SYNOPSIS
find [OPTIONS] [path...] [expression]
DESCRIPTION
GNU find searches the directory tree rooted at each given file
name by evaluating the given expression from left to right, according
to the rules of precedence.
Example of find
1.Search for a file named file1 from /home/arif
find /home/arif/ -name file1
2.Search for a file named file1 in your entire file system
find / -name file1
DESCRIPTION
Display the current time in the given FORMAT, or set the system
date.
Examples of date
To display the current date and time
date
To change the date and time
date MMDDhhmmYY
DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current
month is displayed. The options are as follows:
Options:
-s Display Sunday as the first day of the week. (This is the default.)
-1 Display single month output. (This is the default.)
-3 Display prev/current/next month output.
-y Display a calendar for the current year.
DESCRIPTION
Compare files line by line.
Options:
-i Ignore case differences in file contents
-E Ignore changes due to tab expansion
-b Ignore changes in the amount of white space
-B Ignore changes whose lines are all blank
DESCRIPTION
grep searches the named input FILEs (or standard input if no
files are named, or if a single hyphen-minus (-) is given as file name)
for lines containing a match to the given PATTERN. By default,
grep prints the matching lines.
Options:
-f FILE, Obtain patterns from FILE, one per line. The empty file
contains zero patterns, and therefore matches nothing.
-i, Ignore case distinctions in both the PATTERN and the input
files. (-i is specified by POSIX.)
DESCRIPTION
Write sorted concatenation of all FILE(s) to standard output.
Options:
-r, reverse the result of comparisons
Examples of sort
DESCRIPTION
GNU `tar' (tape archive) saves many files/directories together
into a single tape or disk archive, and can restore individual files
from the archive.
Options:
-c, create a new archive
-r, append files to the end of an archive
-t, list the contents of an archive
-x, extract files from an archive
-f, use archive file or device ARCHIVE
-v, verbosely list files processed
-z, filter the archive through gzip
Punjab University College of Information Technology (PUCIT) 52
Instructor: Arif Butt.
TA: Dilawer Hussain.
Following tar command will extract the original files/dirs from the
archive mywork.tar. Before extraction, your pwd must be the target
directory, because tar always extracts to current directory
$tar xvf mywork.tar
● Advantages
● Not readable
Wild Cards
Wild Cards
When you give the shell abbreviated filenames that contain special
characters, also called metacharacters, the shell can generate
filenames that match the names of existing files. These special
characters are also referred to as wildcards because they act as the
jokers do in a deck of cards.
Special Characters:
● ?
● *
● []
Wild Cards(cont..)
The ? Special Character
The question mark (?) causes the shell to generate filenames.
It matches any single character in the name of an existing file.
Example:
Wild Cards(cont..)
The [] Special Character
Using [], pair of brackets the shell matches all the characters
with the file name that is included in the pair of brackets.
Examples:
From page1-page6, we just
want to list page2, page3, page6
Things to do!