1.2 Worksheet OS Lab-1
1.2 Worksheet OS Lab-1
ls command:
The ls command is used to view the contents of a directory. By default, this command will
display the contents of your current working directory.
if you want to see the content of other directories, type ls and then the directory’s path. For
example, enter ls /home/username/Documents to view the content of Documents.
There are variations you can use with the ls command:
ls -al will list the files and directories with detailed information like the permissions, size,
owner, etc.
ls-l:
The -l option signifies the long list format. This shows a lot more information presented to the
user than the standard command. You will see the file permissions, the number of links, owner
name, owner group, file size, time of last modification, and the file or directory name. This option
is used in conjunction with many other options on a regular basis.
Ls -p:
The ls command is one of the most commonly used commands in daily Linux/UNIX
operations. The command is used in listing contents inside a directory and is one of the few
commands beginners learn from the onset.
Man:
• It provides online documentation for all the possible options with a command and its
usages.
Clear:
TO clear the previous screen
MKDIR:
1)The “mkdir” (Make directory) command create a new directory.
2)If directory already exists, it will return an error message “cannot create folder, folder already
exists”.
Use mkdir command to make a new directory — if you type mkdir Music it will create a directory
called Music.
• To generate a new directory inside another directory, use this Linux basic command mkdir
Music/Newfile
• Use the chmod command
• Chmod is another Linux command, used to change the read, write, and execute permissions
of files and directories. As this command is rather complicated, you can read the full
tutorial in order to execute it properly.
CAT:
• It is used to create a file with content.
cd command:
To navigate through the Linux files and directories, use the cd command. It requires either the
full path or the name of the directory, depending on the current working directory that you’re in.
On a side note, Linux’s shell is case sensitive. So, you have to type the name’s directory exactly
as it is.
cp command:
Use the cp command to copy files from the current directory to a different directory. For
instance, the command cp scenery.jpg /home/username/Pictures would create a copy of
scenery.jpg (from your current directory) into the Pictures directory.
rmdir command:
If you need to delete a directory, use the rmdir command. However, rmdir only allows you to
delete empty directories.
rm command:
The rm command is used to delete directories and the contents within them. If you only want to
delete the directory — as an alternative to rmdir — use rm -r.
Note: Be very careful with this command and double-check which directory you are in. This
will delete everything and there is no undo.
grep command:
Another basic Linux command that is undoubtedly helpful for everyday use is grep. It lets you
search through all the text in a given file.
To illustrate, grep blue notepad.txt will search for the word blue in the notepad file. Lines that
contain the searched word will be displayed fully.
head command:
The head command is used to view the first lines of any text file. By default, it will show the
first ten lines, but you can change this number to your liking. For example, if you only want to
show the first five lines, type head -n 5 filename.ext.
tail command:
This one has a similar function to the head command, but instead of showing the first lines, the
tail command will display the last ten lines of a text file. For example, tail -n filename.ext.
chmod command:
chmod is another Linux command, used to change the read, write, and execute permissions of
files and directories. As this command is rather complicated, you can read the full tutorial in
order to execute it properly.