unit 4 commands
unit 4 commands
1. Is command in Linux
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.
This command can be used by itself without any arguments and it will
provide us the output with all the details about the files and the directories
in the current working directory. There is a lot of flexibility offered by this
command in terms of displaying data in the output.
Output:
Output:
You can see we used ls first to see the directories present there and
then mkdir to create another directory followed by ls to view the created
directories.
4. cd command in Linux
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.
Command:
Output:
Here we used pwd to view the current directory for reference and then we
used cd GeeksforGeeks to switch the directory and with
again pwd command we can see the output is the switched directory, i.e
– GeeksforGeeks
5. rmdir command in Linux
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.
Command:
Output:
Here we used the ls command to check the directories present there and
used rmdir <directory name> to delete the directory and again
the ls command to view the directories after deleting the same.
6. cp command in Linux
The cp command of Linux is equivalent to copy-paste and cut-paste in
Windows.
Command:
Output:
Here we used ls to view the files and then used cp to copy the files
of first.txt to second.txt and again used ls command to view the updated
files.
7. mv command in Linux
The mv command is generally used for renaming the files in Linux.
Command:
Output:
Here we used the ls command to check the directories and then used mv
<file name> <Renamed file name> to rename the files, and then again
we used the ls command to view the renamed file as you can see in the
output screenshot.
8. rm command in Linux
rm command in Linux is generally used to delete the files created in the
directory.
Command:
Output:
You can see as we wrote the ls command to view the files in the terminal
and then rm <file name> to delete the files and again we had
the ls command to check the update.
9. uname command in Linux
The uname command is used to check the complete OS information of
the system. Check out the command and the output below
Command:
Output:
Output:
We first used the rm command to delete the file and then used
the locate command to find the file in the database which in return has
given the output with a -e as the file was removed.
11. touch command in Linux
The touch command creates an empty file when put in the terminal in
this format as touch <file name>
Command:
Output:
Output:
Here we used mkdir to create two directories and then we used ln with
an -s to create a soft link in it.
13. cat command in Linux
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.
Command:
Output:
Output:
Output:
Output:
Output:
In this command, we first used cat <file name> to view the content of the
file, and then we used cat <file name> | grep “string” to check the string
in it.
18. echo command in Linux
echo command in Linux is specially used to print something in the
terminal
Command:
Output:
Output:
Command:
Output:
21. sort command in Linux
The sort command is used generally to sort the output of the file. Let’s
use the command and see the output.
Command: (We are using the cat command to see the file content)
Output:
Here first we checked the file content using the cat command and then we
sorted it alphabetically using the sort command.
22. cal command in Linux
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.
Command:
Output:
Output:
Output:
Here we have used df -h as simply typing df will return the output in bytes
which is not readable, so we add -h to make the outputs more readable
and understandable.
25. wc command in Linux
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
Let’s see one example of these options
Command:
Output:
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.