0% found this document useful (0 votes)
29 views72 pages

UNIT 9 (Commands Set1)

Uploaded by

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

UNIT 9 (Commands Set1)

Uploaded by

vegow58383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 72

Unit-9

Unix Commands

Subject Code: 3140702


Subject Name: Operating System

cd (Change Directory) Command


• The cd command is used to change the current directory (i.e., the
directory in which the user is currently working)

▪ Syntax :
cd [-Options] [Directory]

▪ Example :
Option Use
cd .. Change Current directory to parent directory
cd ~ Move to users home directory from anywhere
cd lab_1 Change from current working directory to lab_1
cd ../downloads If we are currently in /home/username/documents then
we would be placed in /home/username/downloads.

cd Command Example
cd .. Change Current directory to parent directory
3

cd Command Example
cd ~ Move to users home directory from anywhere

cd Command Example
cd lab_1 Change from current working directory to lab_1
5

cd Command Example
cd ../downloads If we are currently in /home/student/documents then
we would be placed in /home/student/downloads

6
ls Command
• List directory contents.

▪ Syntax :
ls [Options] [file|dir]

▪ Example :
Option Use
ls -l To show long listing information about the file/directory
ls -a List all files including hidden file starting with '.'
ls -r List in reverse order
ls -t Sort by time & date
ls -s Sort by file size
7
name of the file/dir
ls Command $ ls -l
specifies owner of the
/etc/hosts

Output:
file/dir

-rw-r--r-- 1 root root 337 Oct 4 11:31 /etc/hosts

-rw- r-- r--


pu o
number of links for dir/file
files o

r
date and time modification
specifies the of the last of the file
re

g
sr

h
w

o
specifies group of the indicates the file/dir size in
8
file/dir bytes.
ls Command Example
ls -l To show long listing information about the file/directory
10

ls Command Example
ls -a List all files including hidden file starting with '.'
11

ls Command Example
ls -r List in reverse order
12

man Command
• It is the interface used to view the system's reference manuals.

▪ Syntax :

man [command name]

▪ Example
13

echo Command
• Display a line of text/string on standard output or a file.

▪ Syntax :

echo [option] [string]

▪ Example :
Option Use
echo -n Do not output a trailing newline
echo -e Enable interpretation of backslash escape sequences

Option Use
\b It removes all the spaces in between the text
\n It creates new line from where it is used
\t It create horizontal tab spaces

14

echo Command Example

echo -n Do not output a trailing newline


15

echo Command Example


echo -e Enable interpretation of backslash escape sequences

\b It removes all the spaces in between the text


\n It creates new line from where it is used
\t It create horizontal tab spaces
16

cal Command
• Displays a simple, formatted calendar in your terminal.

▪ Syntax :

cal [options] [[[day] month] year]

▪ Example :
Option Use
cal -1 Display single month output. (This is the default.)
cal -3 Display three months spanning the date.

cal -s Display Sunday as the first day of the week.

cal -m Display Monday as the first day of the week.


Use day-of-year numbering for all calendars. These are also called
cal -j
ordinal days. Ordinal days range from 1 to 366.
cal –y Display a calendar for the whole year

17

cal Command Example


Cal or cal -1 Display single month output. (This is the default.)
18

cal Command Example


cal -3 Display three months spanning the date.
19

cal Command Example


cal -s Display Sunday as the first day of the week.
20

cal Command Example


cal -m Display Monday as the first day of the week.
21

cal Command Example


cal -j Use day-of-year numbering for all calendars. These are also called
ordinal days. Ordinal days range from 1 to 366.
22

cal Command Example


cal –y Display a calendar for the whole year
23

date Command
• Print or set the system date and time.

▪ Syntax :
date [OPTION]... [+FORMAT]

▪ Example :
Option Use
date +%a The abbreviated weekday name (e.g., Sun)
date +%A The full weekday name (e.g., Sunday)
date +%b The abbreviated month name (e.g., Jan)
date +%B Locale's full month name (e.g., January)
date +%C The current century; like %Y, except omit last two digits
(e.g., 20)
date +%w day of week (0..6); 0 is Sunday

24

date Command
Option Use
date +%d Display the day of the month
date +%m Displays the month of year (01 to 12)
date +%y Displays last two digits of the year(00 to 99)
date +%Y Display four-digit year.
date +%T Display the time in 24 hour format as HH:MM:SS
date +%H Display the hour
date +%M Display the minute
date +%S Display the seconds
date +%V ISO week number, with Monday as first day of week
(01..53)
date +%P locale's equivalent of either AM or PM
25

date Command Example


date +%a The abbreviated weekday name (e.g., Sun)
date +%A The full weekday name (e.g., Sunday)

26

date Command Example


date +%b The abbreviated month name (e.g., Jan)
date +%B Locale's full month name (e.g., January)

27

date Command Example


date +%c Full date with IST timing
date +%C The current century; like %Y, except omit last two digits
(e.g., 20)
28

date Command Example


date +%d Display the day of the month
date +%m Displays the month of year (01 to 12)
date +%y Displays last two digits of the year(00 to 99)
29

date Command Example


date +%y Displays last two digits of the year(00 to 99)
date +%Y Display four-digit year.
30

date Command Example


date +%T Display the time in 24 hour format as HH:MM:SS
date +%H Display the hour
date +%M Display the minute
date +%S Display the seconds

31
date Command Example
date +%V ISO week number, with Monday as first day of week
(01..53)

32

date Command Example


date +%P locale's equivalent of either AM or PM
33

clear Command
• Clear the terminal screen.
• If you take a detailed look after running the clear command, you'll
find that it doesn't really clear the terminal. The tool just shifts the
text upwards, out of the viewable area.

▪ Syntax :
clear
34

clear Command Example

35

cat Command
• It is used to create, display and concatenate file contents.

▪ Syntax :

cat [OPTION] [FILE]

▪ Example :
Option Use
cat -b Omits line numbers for blank space in the output
cat -E Displays a $ (dollar sign) at the end of each line
cat -n Line numbers for all the output lines
cat -s Suppress repeated empty output lines
cat -T Displays the tab characters as ^I in the output

36
cat Command
▪ Example :
$ cat > file1.txt
• It creates file1.txt and allow us to insert content for this file.
• After inserting content you can use ctrl+c to exit the file.
$cat file.txt > newfile.txt
• Read the contents of file.txt and write them to newfile.txt,
overwriting anything newfile.txt previously contained. If
newfile.txt does not exist, it will be created.
$cat file.txt >> newfile.txt
• Read the contents of file.txt and append them to the end of
newfile.txt. If newfile.txt does not exist, it will be created.
37

cat Command
▪ Example :
cat file1.txt file2.txt
• It will read the contents of file1.txt and file2.txt and display the
result in the terminal.
cat file1.txt file2.txt > combinedfile.txt
• It will concatenate the contents of file1.txt and file2.txt and write
them to a new file combinedfile.txt using the (>) operator. • If the
combinedfile.txt file doesn’t exist the command will create it.
Otherwise it will overwrite the file.
38

cat Command Example


▪ $ cat > file1.txt
• It creates file1.txt and allow us to insert content for this file. • After
inserting content you can use ctrl+c to exit the file.
39

cat Command Example


cat -b Omits line numbers for blank space in the output
cat -E Displays a $ (dollar sign) at the end of each line

40

cat Command Example


▪ $cat file.txt > newfile.txt
• Read the contents of file.txt and write them to newfile.txt,
overwriting anything newfile.txt previously contained. • If newfile.txt
does not exist, it will be created.

4
1

cat Command Example


▪ $cat file.txt >> newfile.txt
• Read the contents of file.txt and append them to the end of
newfile.txt. If newfile.txt does not exist, it will be created.
4
2

cat Command Example


▪ cat file1.txt file2.txt
• It will read the contents of file1.txt and file2.txt and display the result
in the terminal.
4
3

cat Command Example


▪ cat file1.txt file2.txt > combinedfile.txt
• It will concatenate the contents of file1.txt and file2.txt and write
them to a new file combinedfile.txt using the (>) operator. • If the
combinedfile.txt file doesn’t exist the command will create it
otherwise it will overwrite the file.
4
4

pwd (Print working directory) Command


• It prints the current working directory name with the complete path
starting from root (/).

▪ Syntax :
pwd [-OPTION]
▪ Example :
45

who Command
• It display the users that are currently logged into your Unix
computer system.

▪ Syntax :
who [-options] [filename]

▪ Example :
Optio Use
n who Display the time of the last system boot
-b
who -H Print a line of column headings
who -q Displays all login names, and a count of all logged-on users
who -a Display all details of current logged in user

46

who Command Example

who -b Display the time of the last system boot


47

who Command Example


who -H Print a line of column headings

48

who Command Example


who -q Displays all login names, and a count of all logged-on users

49

who Command Example


who -a Display all details of current logged in user
50

whoami Command
• This command prints the username associated with the current
effective user ID.

▪ Syntax :
whoami [-OPTION]
▪ Example :
Option Use
whoami --help Display a help message, and exit
whoami --version Display version information, and exit

51

whoami Command Example


whoami --help Display a help message, and exit
52

whoami Command Example


whoami --version Display version information, and exit
53

uname (unix name) Command


• Print information about the current system.

▪ Syntax :
uname [-OPTION]
▪ Example :
Option Use
uname -s Print the kernel name
uname -n Print the network node hostname
uname -v Print the kernel version
uname -m Print the machine hardware name
uname -o Print the operating system

54

uname Command Example


uname -s Print the kernel name
55

uname Command Example


uname -n Print the network node hostname

56
uname Command Example
uname -v Print the kernel version

57

uname Command Example


uname -m Print the machine hardware name
58

uname Command Example


uname -o Print the operating system

59

passwd Command
• The passwd command is used to change the password of a user
account.
▪ Syntax :
passwd [-options] [username]
▪ Example :

mkdir Command
• This command is used to make Directories.

▪ Syntax :
mkdir [-OPTION] DIRECTORY
▪ Example :
Option Use
mkdir -v Print a message for each created directory
mkdir -p No error if existing, make parent directories as needed
mkdir -m To control the permissions of new directories

61

mkdir Command Example


mkdir -v Print a message for each created directory
62

mkdir Command Example


mkdir -p No error if existing, make parent directories as needed
63

mkdir Command Example


mkdir -m To control the permissions of new directories

64

rmdir Command
• This command removes empty directories from your filesystem.

▪ Syntax :

rmdir [-OPTION] DIRECTORY

▪ Example :
Option Use
Remove directory and its ancestors… e.g.,‘rmdir -p a/b/c’ is
rmdir -p
similar to ‘rmdir a/b/c a/b a’

65

rmdir Command Example


rmdir -p Remove directory and its ancestors…
e.g.,‘rmdir -p a/b/c’ is similar to ‘rmdir a/b/c a/b a’
66

cp(copy) Command
• This command is used to copy files and directories.

▪ Syntax :
cp [option] source destination/directory

▪ Example :
Option Use
cp -i Interactive - ask before overwrite
cp -f Force copy by removing the destination file if needed
cp -n Do not overwrite an existing file
cp -u Update - copy when source is newer than destination
cp -s Make symbolic links instead of copying
cp -R Copy directories recursively
cp -v Print informative messages

67

cp Command Example
68

cp Command Example
cp -i Interactive - ask before overwrite
69

cp Command Example
cp -v Print informative messages

70

cp Command Example
cp -s Make symbolic links instead of copying
71

mv(move) Command
• mv command is used to move files and directories.

▪ Syntax :

mv [-options] source dest

▪ Example :
Optio Use
n mv - Interactive prompt before overwrite
i
mv -f Force move by overwriting destination file without prompt
mv -n Never overwrite any existing file
mv -u Update - move when source is newer than destination
mv -v Print informative messages

72

mv Command Example
73

rm(remove) Command
• The ‘rm’ command is used to delete files and directories.

▪ Syntax :

rm [-OPTION] Filename

▪ Example :
Optio Use
n rm - Prompt before every removal
i
rm -d Delete a empty directory
rm -r Remove directories and their contents recursively
rm -f To remove the file forcefully

74

rm Command Example
rm -i Prompt before every removal
75

cut Command
• The cut command extracts a given number of characters or
columns from a file.

▪ Syntax :
cut [-options] [file]

▪ Example :
Optio Use
n cut - Select only the characters from each line as specified in LIST
c
cut -b Select only the bytes from each line as specified in LIST
cut -f Cuts the input file using list of field. The default field to be used
TAB. The default behavior can be overwritten by use of -d option
cut -d Specifies a delimiter to by used as a field. Default field is TAB and
this option overwrites this default behavior

76

cut Command Example


cut -c Select only the characters from each line as specified in LIST
77

cut Command Example


cut -b Select only the bytes from each line as specified in LIST
78

cut Command Example


cut -f Cuts the input file using list of field. The default field to be used
TAB. The default behavior can be overwritten by use of -d option
cut -d Specifies a delimiter to by used as a field. Default field is TAB
and this option overwrites this default behavior
79

paste Command
• The paste command displays the corresponding lines of multiple
files side-by-side.

▪ Syntax :
paste [-options] [file]
▪ Example :
Optio Use
n Reuse characters from LIST instead of tabs
paste -
d
paste -s Paste one file at a time instead of in parallel

80

paste Command Example


paste -d Reuse characters from LIST instead of tabs
81

You might also like