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

1. OSL 01

It is good for students

Uploaded by

daniya212123
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)
2 views

1. OSL 01

It is good for students

Uploaded by

daniya212123
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/ 6

Practical: 01

Title: Hands on Unix / Linux command

1. Is:
The ls command is commonly used to identify the files and directories in the working directory. This
command is one of the many often-used Linux commands that you should know.
$ls
Output:

2. pwd :
The pwd command is mostly used to print the current working directory on your terminal. It is also one
of the most commonly used commands.
$pwd
Output:

3. mkdir :
This mkdir command allows you to create fresh directories in the terminal itself. The default syntax is
mkdir <directory name> and the new directory will be created.
$mkdir mgmu
Output:

4. cd:
The cd command is used to navigate between directories. It requires either the full path or the directory
name, depending on your current working directory. If you run this command without any options, it will
take you to your home folder. Keep in mind that it can only be executed by users with sudo privileges.
$pwd
$cd <directory name>
$pwd
Output:

5. rmdir:
The rmdir command is used to delete permanently an empty directory. To perform this command the user
running this command must be having sudo privileges in the parent directory.
$ls
$rmdir <directory name>
$ls
Output:c

6. cp:
The cp command of Linux is equivalent to copy-paste and cut-paste in Windows.
$cp Src_file Dest_file
$gedit a.txt ( Insert some text in file and save)
$gedit b.txt (Leave bank and same file)
$cat a.txt (see content of a.txt)
$cat b.txt (no content in b.txt)
$cp a.txt b.txt (copy of a.txt to b.txt)
$cat a.txt (see content of a.txt)
$cat b.txt (see content of b.txt)
Output:

7. mv:
The mv command is generally used for renaming the files in Linux.
$mv [options(s)] [source_file_name(s)] [Destination_file_name]
Here,
source_file_name(s) = The name of the files that we want to rename or move.
Destination_file_name = The name of the new location or the name of the file.
$ls
$ touch first.txt ( To create file first.txt)
$mv first.txt renamed.txt
$ls
Output:

8. rm:
rm command in Linux is generally used to delete the files created in the directory.
$rm [OPTION]... FILE...
Let us consider 5 files having name a.txt, b.txt and so on till e.txt.

$touch a.txt b.txt c.txt d.txt e.txt


$ ls
a.txt b.txt c.txt d.txt e.txt
Removing one file at a time
$ rm a.txt
$ ls
b.txt c.txt d.txt e.txt
Removing more than one file at a time
$ rm b.txt c.txt
$ ls
d.txt e.txt
Output:

9. uname:
The uname command is used to check the complete OS information of the system.
uname [OPTIONs]
Options :
-a or --all : Displays all available information.
-s or --kernel-name : Shows the kernel name.
-n or --nodename : Displays the network (domain) name of the machine.
-r or --kernel-release : Shows the kernel release.
-v or --kernel-version : Displays the kernel version.
-m or --machine : Shows the machine hardware name.
-p or --processor : Displays the processor type or “unknown.”
-i or --hardware-platform :Shows the hardware platform or “unknown.”
-o or --operating-system: Displays the operating system.
$uname -a
$uname -s
$uname -n
$uname -r
$uname -v
$uname -m
$uname -p
Output:

10. locate:
The locate command is generally used to locate the files in the database. Use an asterisk (*) to search for
content that contains two or more words.
locate [OPTION]... PATTERN...
$locate "*.html" -n 20 (It will show 20 results for the searching of file ending with .html.)
$locate -c .txt (It will count files ending with .txt.)
$ locate -i *SAMPLE.txt* ( Ignore Case Sensitive Locate Outputs Using locate Command)
Output:

11. touch:
The touch command creates an empty file when put in the terminal in this format as touch <file name>
touch [options] file_name
Options :
-a :This option changes the access time only.
-c : Suppresses file creation if the file does not exist.
-d : Sets the access and modification times using the specified STRING.
-m : This option changes the modification time only.
-r : Uses the access and modification times from the reference file.
$touch -a filename
$touch -c filename
$touch -c-d filename
Output:

12. ln:
The ln command is used to create a shortcut link to another file. This is among the most important Linux
commands to know if you want to operate as a Linux administrator.

$mkdir demo
$mkdir Linked
$ln -s demo Linked
Output:

13. cat:
The cat command is the simplest command to use when you want to see the contents of a particular file.
The only issue is that it simply unloads the entire file to your terminal. If you want to navigate around a
huge file, should use less command alternatively.
cat [OPTION] [FILE]
1. View the Content of a Single File in Linux : $cat file_name
2. View the Content of Multiple Files in Linux : $cat file_name1 file_name2
3. View Contents of a File preceding with Line Numbers in Linux : $cat -n file_name
4. Create a file and add content in Linux Using `cat` Command : $cat > newfile_name
5. Copy the Contents of One File to Another File in Linux : $cat file1.txt file2.txt > merged_file.txt
Output:

14. clear:
The clear command is a standard command to clear the terminal screen
Clearing our terminal using `clear -x` in Linux System : $clear -x
Using `reset` command to clear our terminal in Linux System : $reset
Output:

15. ps:
ps command in Linux is used to check the active processes in the terminal.
ps [options]
Simple process selection : Shows the processes for the current shell : $ ps
To view all running processes, use either of the following options with the `ps` command: $ps -A
View all processes except both session leaders and processes not associated with a terminal : $ps -a
A session leader is a process that initiates other processes. View processes except session leaders: $ps -d
List All Processes Associated with this Terminal in Linux :$ps -T
Output:

16. man:
The man command displays a user manual for any commands or utilities available in the Terminal,
including their name, description, and options.
man [option] [command]
Options:
man [command]: Display the manual page for the specified command.
-f, –whatis: Display a concise one-line description of the command.
-k, –apropos: Search for commands related to a given keyword.
-a, –all: Display all matching manual pages for the specified command.
Spacebar: Move forward one page in the manual.
Enter: Move forward one line in the manual.
B: Move backward one page in the manual.
Q: Quit the manual viewer.
$man ls
$man 2 intro
$man -f ls
Output:

17. grep:
The grep command is used to find a specific string in a series of outputs. For example, if you want to find
a string in a file, you can use the syntax: <Any command with output> | grep “<string to find> “
$cat Files.txt | grep “new”
Case insensitive search : $grep -i "UNix" mgmfile.txt
Displaying the Count of Number of Matches Using grep :$grep -c "unix" mgmfile.txt
Output:

18. echo:
echo command in Linux is specially used to print something in the terminal
$echo [string]
$echo "MGM University"
Output:

19. wget:
The wget command in the Linux command line allows you to download files from the internet. It runs in
the background and does not interfere with other processes.
Here is the basic syntax: $wget [option] [url]
$wget http://sample.com/sample-menu.php
Output:

20. whoami:
The whoami command provides basic information that is extremely useful when working on multiple
systems. In general, if you are working with a single computer, you will not require it as frequently as a
network administrator.
$whoami
$whoami --help
$whoami --version
$whoami -u
$whoami -e
Output:

21. sort :
The sort command is used generally to sort the output of the file. Let’s use the command and see the
output.
$cat multiple.txt
$sort multiple.txt
Here first we checked the file content using the cat command and then we sorted it alphabetically using
the sort command.
Output:

22. cal :
The cal command is not the most famous command in the terminal but it functions to view the calendar
for a particular month in the terminal. Let’s see how this works.
$cal [ [ month ] year]
$cal June 2024
$cal : Shows current month calendar on the terminal with the current date highlighted.
$cal -y : Shows the calendar of the complete current year with the current date highlighted.
$cal 08 2000 : Shows calendar of selected month and year.
4cal 2018 : Shows the whole calendar of the year.
Output:

23. whereis:
whereis command in Linux is generally used to see the exact location of any command typed after this.
Let’s see how this performs.
$whereis [options] filename...
$whereis printf
Output:

24. df :
df command in Linux gets the details of the file system.
$df -h
Output:

25. wc :
wc command in Linux indicates the number of words, characters, lines, etc using a set of options.
wc -w shows the number of words
wc -l shows the number of lines
wc -m shows the number of characters present in a file
$touch file.txt
$echo -e "This file has only six words" > file.txt
$wc -w file.txt
Here we used the touch command to create a text file and then used the echo command to input a
sentence that contains six words and we used the wc -w command to calculate the number of words in it.
Output:

Conclusion :

Name of Student -

Class-
Batch-

Roll no-

You might also like