20CS2036 – Operating System Lab URK20CS1020
Ex. No. 1 Basic Unix and Linux Commands
Date of Exercise 13/12/2021 https://youtu.be/Te9tyOkujJA
Aim
To execute basic UNIX and Linux commands.
Description
Sl. Command Name Meaning options
No.
1. ls List files and/or directories. -a, --all
do not ignore
entries starting with .
-A, --almost-all
do not list
implied . and ..
--author
with -l, print the
author of each file
-b, --escape
print C-style
escapes for nongraphic
characters
--block-size=SIZE
2. Who am i This command reveals the user who -a, --all =same as -b -d --
is currently logged in. login -p -r -t -T -u
-b, --boot
time of last
system boot
-d, --dead
print dead processes
-H, --heading
print line of
column headings
-l, --login
print system
login processes
--lookup
attempt to canonicalize
hostnames via DNS
3. pwd prints the absolute path to -L, --logical
1
20CS2036 – Operating System Lab URK20CS1020
current working directory use PWD from
environment, even if it
contains symlinks
-P, --physical
avoid all
symlinks
4. cal Displays the calendar of the current -1, --one
month Display single
month output. (This is
the default.)
-3, --three
Display
prev/current/next
month output.
-s, --sunday
Display Sunday
as the first day of the
week.
-m, --monday
Display Monday
as the first day of the
week.
-j, --julian
Display Julian
dates (days one-based,
numbered from January
1) -y, --year
5. echo This command will echo -n do not output the
whatever you provide it. trailing newline
-e enable
interpretation of
backslash escapes
-E disable
interpretation of
backslash escapes
(default)
6. date Displays current time and date. -d, --date=STRING
display time
described by STRING,
not 'now'
-f, --file=DATEFILE
2
20CS2036 – Operating System Lab URK20CS1020
like --date once for
each line of DATEFILE
7. tty Displays current terminal.
8. id This command prints user and -a ignore, for
groups (UID and GID) of the compatibility with other
current user. versions
-Z, --context
print only the
security context of the
current user
-g, --group
print only the
effective group ID
-G, --groups
print all group
IDs
-n, --name
print a name instead of a
number, for
-ugG
9. clear This command clears the screen.
10. man To show manual page
11. cd Change the current working
directory to the directory provided
as argument.
12. mkdir To create a directory, the ‘mkdir’
command is used.
13. touch For creating an empty file, use the
touch command.
14. cp Copy files and directories
15. mv Move files or directories. The 'mv'
command works like 'cp' command,
except that the original file is
removed. But, the mv command can
be used to rename the files (or
directories).
16. rmdir command removes any empty
directories, but cannot delete a
3
20CS2036 – Operating System Lab URK20CS1020
directory if a file is
present in it.
17. file The file command determines the file
type of a given file.
18. cat The 'cat' command is
actually a concatenator but can be
used to view the
contents of a file.
19. head Displays the first few lines of a file.
By default, the ‘head’ command
displays the first 10 lines of a file.
20. tail the ‘tail’ command shows the last 10 -c, --bytes=[-]K
lines by default print the first K bytes of
each file
-n, --lines=[-]K
print the first K lines
instead of the first 10
-q, --quiet, --silent
never print headers giving
file names
21. wc This command counts lines, words
and letters of the input
given to it.
22. grep The ‘grep’ command searches for a
pattern in a file (or standard
input).
23. vi Visual editor
24. alias The ‘alias’ is another name for a
command.
25. history shows the commands you have
entered on your terminal so far.
26. passwd To change your password
27. help With almost every command, ‘--help’
option shows usage summary for that
command.
28. chmod The chmod command lets you change
access permissions for a file.
29. stat To check the status of a file. This -L, --dereference
provides more detailed information follow links
about a file than ‘ls -l’ output. -f, --file-system
4
20CS2036 – Operating System Lab URK20CS1020
display file system
status instead of file status
-c --format=FORMAT use
the
specified FORMAT
instead of the default;
output a newline after
each use of FORMAT
--printf=FORMAT
30. ln command is used in linux to create
links.
Questions:
1. List the contents of user & home directory including the hidden files.
5
20CS2036 – Operating System Lab URK20CS1020
2. List the content of /var directory?
3. Create two directories named dir1 & dir2
4. Create a hidden directory with your name?
5. Display Julian dates (days one-based, numbered from January 1).
6
20CS2036 – Operating System Lab URK20CS1020
6. Display the calendar of 2020.
7
20CS2036 – Operating System Lab URK20CS1020
7. Display Sunday as the first day of the week in the calendar.
8. Display Julian dates (days one-based, numbered from January) in the calendar.
8
20CS2036 – Operating System Lab URK20CS1020
9. Today’s date
10. Display your current terminal.
11. Display the user and groups (UID and GID) of the current user.
9
20CS2036 – Operating System Lab URK20CS1020
12. Copy the file /etc/passwd file to current directory with sample.txt as the filename
13. Create a file with your own name. (.sh – extension)
14. Change directory into dir2 directory
15. Create an empty txt file and check whether the created file is present their
16. Rename the file sample.txt to new.txt and check whether sample.txt is there or not?
17. Remove directory
18. Display last 3 lines of the file test1.txt
10
20CS2036 – Operating System Lab URK20CS1020
19. Display all the commands you have executed so far and save the list into a file named todays
history.txt
20. How many files are present under your home directory?
Result
The basic commands of UNIX and Linux are successfully executed and verified.
11