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

Linux

Uploaded by

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

Linux

Uploaded by

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

LAB SESSION NO.

Introduction to Linux operating system and architecture

Author: Mesum Raza


Approved By: Miss Sadia Arshad -
Lecturer CSIT

Department of Computer Science and Information Technology


Objective:

Familiarize students with fundamental Linux commands and file system


navigation.

Navigating Through File System:

1. To see the command description:

[command] -h OR man [command]

2. To print something:

echo [the string you want to print] > It will output any text
that we provide

3. To find which user we are currently logged in:

whoami

4. Listing files in our current directory:

ls (In ls command "-a" flag can be used to list all the contents
including hidden files and "-l" flag can be used for long listing)

• Listing files of any directory:

ls [path to directory]

5. Changing our current directory:

cd [directory name]

• Changing to any directory:

cd [path to directory]
• For example if there are two folders Desktop and Documents
under root directory and we want to move from this path
/root/Desktop to Documents so we can directly use command:

cd ../Documents OR cd ~/Documents

6. Outputting the contents of the file in current directory:

cat [filename]

• Outputting the contents of any file:

cat [path to the file]

7. Printing current working directory:

pwd

8. To redirect output of a command to a file:

[command] > [filename]

eg: echo hello123 > test.txt (If test.txt file already exists it will
overwrite the file)

9. Creating a file:

touch [filename]

10. Creating a directory:

mkdir [directory name]

11. To make a directory having spaces:

mkdir 'folder name'

OR

mkdir folder\ name

Back slash is used so that CLI could interpret that this space is part
of the directory name. It is called Escape Sequence.

12. Removing a file:

rm [filename]

13. Removing a directory:

rm -r [directory name]

14. Copying a file:

To another file: cp [filename] [to the file you want to copy]

15. To a directory: cp [filename] [to the path you want to copy]

16. Renaming a file or directory:

mv [current filename] [new filename]

17. Moving a file or directory:

mv [filename/directoryname] [to the path you want to move]

18. To see the file type:

file [filename]

19. Editing files using a CLI text editor:

nano [filename] (This will open a new window to edit the file)

20.Editing files using a GUI text editor:

gedit [filename] or mousepad [filename]

File Permissions:
1. Files and Permissions:

• By doing long listing (ls -l) we can see the file or directory
permissions. The permission section has total 10 bits and it looks
like:

-rwxrw-r--

Here 'r' stands for read, 'w' stands for write and 'x' stands for
executable.

• The first bit shows that if it is a file or directory. If it is file '-' will be
placed and if its directory 'd' will be placed.

The last nine bits are divided in trio. The first trio is the permission
of the owner of file. The second trio is the permission of the group
that this file belongs to and the third trio is the permission of all
the other users.

If a permission isn't given it represented by a '-'

2. Modify Permissions:

• In Linux owner is denoted by 'u', group is denoted by 'g' and other


user is denoted by 'o'

• Symbolic Format:

To add a permission:

chmod <The trio you want to give permission>+<the permission


you want to give> <file or directory path>

eg: chmod ugo+rwx myfile or chmod uo+x my file

To remove a permission:

chmod <The trio you want to give permission>-<the permission


you want to give> <file or directory path>

eg: chmod ugo-rwx myfile or chmod uo-x my file


• Numeric Format:

In numeric form 4 stands for read, 2 for write and 1 for execute.

chmod <owner permission number><group permission


number><user permission number> <file or directory path>

eg: chmod 754 myfile (This will give rwx permission to owner, rx
to group, r to users)

Common directories:

1. /etc:

This root directory is one of the most important root directories on


your system. The etc folder (short for etcetera) is a commonplace
location to store system files that are used by your operating
system.

2. /var:

The "/var" directory, with "var" being short for variable data, is
one of the main root folders found on a Linux install. This folder
stores data that is frequently accessed or written by services or
applications running on the system. For example, log files from
running services and applications are written here (/var/log), or
other data that is not necessarily associated with a specific user
(i.e., databases and the like).

3. /tmp:

This is a unique root directory found on a Linux install. Short for


"temporary", the /tmp directory is volatile and is used to store
data that is only needed to be accessed once or twice. Similar to
the memory on your computer, once the computer is restarted,
the contents of this folder are cleared out.

4. /root:
Unlike the /home directory, the /root folder is actually the home
for the "root" system user. There isn't anything more to this folder
other than just understanding that this is the home directory for
the "root" user. But, it is worth a mention as the logical
presumption is that this user would have their data in a directory
such as "/home/root" by default.

Exercise:

You've been provided with a new Linux system. Perform the following tasks:

1.Navigate to the root directory and create a new directory named


"cs_lab_[roll_number]"
2.Inside "cs_lab," create two text files: "file1.txt" and "file2.txt."
3.Use commands to display the content of "file1.txt" and "file2.txt."
4.Rename "file2.txt" to "important_file.txt."
5.Move "important_file.txt" to a directory named "important_files" within "cs_lab."

You might also like