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

LinuxCommandsFatma

The document provides an overview of basic Unix commands including their purposes, examples, and outputs. Key commands covered include echo, date, cal, who, uname, cat, clear, history, pwd, mkdir, ls, cd, rmdir, ps, and chmod. Each command is explained with its functionality and usage in a terminal environment.

Uploaded by

tanweerjamal833
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

LinuxCommandsFatma

The document provides an overview of basic Unix commands including their purposes, examples, and outputs. Key commands covered include echo, date, cal, who, uname, cat, clear, history, pwd, mkdir, ls, cd, rmdir, ps, and chmod. Each command is explained with its functionality and usage in a terminal environment.

Uploaded by

tanweerjamal833
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment 1: Basic Unix Commands

1.echo
Purpose: The echo command outputs the text or strings and results of
computations to the terminal.
Example: fatma@Fatma:~$ echo "Hello"
Output: Hello

Echo command recognizes some escape characters like:


i. Backslash: ‘\\’
Purpose: Escapes the next character, treating it as literal or special.
Example: fatma@Fatma:~$ echo "This is a backslash: \\"
Output: This is a backslash: \

ii. Backspace: ‘\b’


Purpose: Represents a backspace in a string.
Example: fatma@Fatma:~$ echo -e "Hello\b World"
Output: Hell World

iii. Horizontal tab: ‘\t’


Purpose: Inserts a horizontal tab.
Example: fatma@Fatma:~$ echo -e "Hello\tWorld"
Output: Hello World

iv. New Line: ‘\n’


Purpose: Inserts a new line.
Example: fatma@Fatma:~$ echo -e "Hello\nWorld"
Output: Hello
World

v. Vertical tab: ‘\v’


Purpose: Inserts a vertical tab.
Example: fatma@Fatma:~$ echo -e "Hello\vWorld
Output: Hello
World

Page | 1
2.date
Purpose: The date command displays the current date and time.
Example: fatma@Fatma:~$ date
Output: Wed Nov 27 11:21:30 IST 2024

Specifiers like %m, %b, %y, etc., are used to customize formatting.
i. “date +%m”
Purpose: Displays the current month (numeric)
Example: fatma@Fatma:~$ date +%m
Output: 11

ii. “ date +%b ”


Purpose: Displays the current month (abbreviation)
Example: fatma@Fatma:~$ date +%b
Output: Nov

iii. “date +%y”


Purpose: Displays the last two digits of the current year
Example: fatma@Fatma:~$ echo -e date +%y
Output: 24

iv. “date +%I%P”


Purpose: Inserts a new line.
Example: fatma@Fatma:~$ echo -e date +%I%P
Output: 11am

v. ” date +%d ” "


Purpose: Insert a vertical tab.
Example: fatma@Fatma:~$ echo -e date +%d ”
Output: 27
vi. date '+%Y-%m-%d'
Example: fatma@Fatma:~$ date '+%Y-%m-%d'
Output: 2024-12-03
vii. date “+%T”
Example: fatma@Fatma:~$ date “+%T”
Output: 2024-12-03

Page | 2
3.cal
Purpose: Displays a calendar for the current month
Example: fatma@Fatma:~$ cal
Output:
November 2024
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

 “cal 2024” displays the full calendar of the year 2024

4.who
Purpose: The who command displays the information of users currently logged
into the system. It returns the user’s ID/name, terminal, and the time at which he
or she logged in.
Example: fatma@Fatma:~$ who
Output: fatma :0 2024-12-03 11:21 (: 0)

i. “who -u”
Purpose: Displays information about currently logged-in users along with their
idle time and process ID (PID).
Example: fatma@Fatma:~$ who -u
Output: fatma :0 2024-12-03 08:30 00:25 5678 (: 0)

ii. “ whoami”
Purpose: Displays the name of the current user.
Example: fatma@Fatma:~$ whoami
Output: fatma

5.uname
Purpose: Using this command, we can know the details of the system. Certain
options like r, v, m, and a can be used with this command.
Example: fatma@Fatma:~$ uname
Output: Linux
i. uname -r
Page | 3
Purpose: Displays the kernel release version.
Example: fatma@Fatma:~$ uname -r
Output: 5.10.16.3-microsoft-standard-WSL2

ii. uname -m
Purpose:  Displays the machine hardware architecture.
Example: fatma@Fatma:~$ uname -m
Output: x86_64

iii. uname -v
Purpose: Displays the kernel version and build information.
Example: fatma@Fatma:~$ uname -v
Output: #1 SMP Fri Apr 2 22:23:49 UTC 2021

iv. uname -a
Purpose: Displays all system information in the following order:
Kernel name, network node hostname, kernel release date, kernel version,
machine hardware, hardware platform, operating system.

Example: fatma@Fatma:~$ uname -a


Output: Linux Fatma 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2
22:23:49 UTC 2021 x86_64 GNU/Linux

6.cat
Purpose: Used to create small files and display the content of that file content.
i. cat > file_name.txt
Purpose: Creates the file.
Example: fatma@Fatma:~$ cat > test.txt
This is a text file created using 'cat'
^C
fatma@Fatma:~$

ii. cat test.txt


Purpose: Displays the content.
Example: fatma@Fatma:~$ cat test.txt
Output: This is a text file created using 'cat'
7.clear

Page | 4
Purpose: Clears all the text from the terminal screen.
Example: fatma@Fatma:~$ clear
Output: (Cleared terminal)

8.history
Purpose: It shows history if the commands used in the terminal.
Example: fatma@Fatma:~$ history
Output: 1 uname
2 uname -r
3 uname -m
4 uname -v
5 uname -a
6 cat > test.txt
7 cat test.txt
8 clear
9 pwd
10 history ….. and so on

9.pwd
Purpose: The ‘pwd’ command displays the absolute path of the current directory.
Example: fatma@Fatma:~$ pwd
Output: /home/fatma

10. mkdir
Purpose: The ‘mkdir’ command is used to create new directory.
Example: fatma@Fatma:~$ mkdir OS
Output: (Creates a directory named ‘OS’)

11. ls
Purpose: Lists the files and directories in the current or specified directory.
Example: fatma@Fatma:~$ ls
Output: OS a.out childpid.c hello.sh hello2.c killchild.c pid.c test.sh
test2.sh ShellScripts child.c hello.c hello1.c hello3.c multiply.c processId.c
12. cd

Page | 5
Purpose: Change the current working directory to the specified one.
Example: fatma@Fatma:~$ cd OS
Output: fatma@Fatma:~/OS$

 cd .. goes up one directory level


Example: fatma@Fatma:~/OS$ cd ..
Output: fatma@Fatma:~$

13. rmdir
Purpose: Removes a directory.
Example: fatma@Fatma:~$ rmdir OS
Output: (The directory ‘OS’ is removed)

14. ps
Purpose: Displays running processes for the current shell.
Example: fatma@Fatma:~$ ps
Output:
PID TTY TIME CMD
9 pts/0 00:00:00 bash
527 s/0 00:00:00 ps

15. ps -awx
Purpose: Displays running processes for the current shell.
Example: fatma@Fatma:~$ ps
Output:
PID TTY STAT TIME COMMAND
1? Sl 0:00 /init
7? Ss 0:00 /init
8? R 0:00 /init
9 pts/0 Ss 0:00 -bash
544 s/0 R+ 0:00 ps -awx
16. ls -l

Page | 6
Purpose: The ls -l command in Linux is used to list the files and directories in the
current directory with detailed information, including file permissions, ownership,
size, and timestamps.
Example: fatma@Fatma:~$ ls -l
Output:
total 88
drwxr-xr-x 2 fatma fatma 4096 Nov 23 19:35 OS
drwxr-xr-x 2 fatma fatma 4096 Nov 24 19:16 ShellScripts
drwxr-xr-x 2 fatma fatma 4096 Dec 3 20:17 Test
-rwxr-xr-x 1 fatma fatma 16176 Nov 24 17:50 a.out
-rw-r--r-- 1 fatma fatma 237 Nov 23 17:15 child7.c
-rw-r--r-- 1 fatma fatma 196 Nov 24 00:23 childpid.c
-rw-r--r-- 1 fatma fatma 116 Nov 23 16:49 hello.c
-rwxr-xr-x 1 fatma fatma 34 Nov 21 13:06 hello.sh
-rw-r--r-- 1 fatma fatma 115 Nov 23 13:24 hello1.c
-rw-r--r-- 1 fatma fatma 124 Nov 23 13:24 hello2.c
-rw-r--r-- 1 fatma fatma 133 Nov 23 13:27 hello3.c
-rw-r--r-- 1 fatma fatma 291 Nov 24 17:50 killchild.c
-rw-r--r-- 1 fatma fatma 310 Nov 23 16:57 multiply.c
-rw-r--r-- 1 fatma fatma 221 Nov 23 13:17 pid.c
-rw-r--r-- 1 fatma fatma 392 Nov 23 16:43 processId.c
-rwxrwxrwx 1 fatma fatma 111 Nov 24 18:03 test.sh
-rw-r--r-- 1 fatma fatma 40 Dec 3 19:53 test.txt
-rwxrwxrwx 1 fatma fatma 50 Nov 24 18:21 test2.sh
-rwxrwxrwx 1 fatma fatma 52 Nov 24 18:26 test3.sh

17. chmod
Purpose: The ‘chmod’ command is used to change the permissions of a file or
directory in Linux. Permissions determine who can read, write, or execute a file.

i. chmod 744 file_name


Purpose: Sets the permissions of the file so that:
 The owner has read (r), write (w), and execute (x) permissions.
 The group and others have read-only (r) permission.

Page | 7
Example: fatma@Fatma:~$ chmod 744 test.txt
(This sets the permissions for the file ‘test.txt’)

ii. chmod u+x file_name


Purpose: Adds execute (x) permission to the owner (u) of the file.
Example: fatma@Fatma:~$ chmod u+x test.txt
(Now the owner can execute the file.)

iii. chmod a-w file_name


Purpose: Removes write (w) permission for all users (owner, group, and
others).
Example: fatma@Fatma:~$ chmod a-w test.txt
(Now, no one can modify the file.)

iv. chmod g+w file_name


Purpose: Grants write (w) permission to the group (g).
Example: fatma@Fatma:~$ chmod g+w test.txt
(The group can now write to the file.)

Page | 8

You might also like