Practical 4
4. List and Explain basic Linux commands.
Basic
Linux commands are
- ls
- mkdir
- cd
- pwd
- cat
- more
- head and tail
- rm
- cp
- chmod
- grep
- date
- cal
- whoami
ls
Command
ls : This is a list
command. It will display the list of directory without any details.
ls – al : This will
display the formatted list of files and
directories along with hidden files and other details like time, date, size,
permissions etc.
ls – t : it will
display the sorted formatted list of files and directories other details like
time, date, size, permissions etc..
mkdir
command
This command is
used to create the directory.
Example:
student@abg2:$ mkdir Patel
It will create the
directory Patel
cd
command
cd: This
command will change from current directory to home directory or from current to
specified directory.
Example:
student@abg2:~$ cd Patel This
will change to Patel directory
student@abg2:~/Patel$
cd This
will change to home directory.
student@abg2:~$
pwd
Command
This command will
show the present or current working directory.
Example:
student@abg2:~/Patel$ pwd
/home/student/Patel this the path of present working
directory.
cat
command
cat command is used
to create a new file, to add the new content in an existing file at the end of
the file and view the content of existing file.
cat > sample.txt This will create a new file
sample.txt but if the file with same name already exist then it overwrites.
cat < sample.txt This
is used to view the content of the file.
cat >>
sample.txt This allow you to add
the new content at the end of the file.
more
command
This command is
used to output the content of the file.
more sample.txt
head
and tail command
head sample.txt The
head command will display the first 10 lines of the file sample.txt
tail sample.txt The tail command will display the
last 10 lines of the file sample.txt
rm
command
rm sample.txt This will remove the file
sample.txt
rm – r Patel This will remove the directory
Patel
cp
Command This is a copy command
cp file1 file2 This
command will copy the content of file1 to file2
cp sample.txt
newsample.txt Here it will copy the
content of sample.txt to newsample.txt
cp – r dir1 dir2 This
command will copy the files of dir1 to dir2. If dir2 does not exist then it create the dir2 and copy the files.
chmod command Change the permission on file for user.
•
4-read(r)
•
2-write(w)
• 1-execute(x)
Example: chmod 444
sample.txt This will set the permission on the
file that is 444, means
for all user have the
permission see/read the file but can’t go for any write or execute operations.
chmod 777
sample.txt All user will be having all the
permission that is read, write
and execute.
grep
command
This command is
used for searching the specific pattern in the file, within the files in the
directory.
grep pattern file Here it will Search for pattern in
file and display all the line in which the
pattern is found.
Example: grep Patel sample.txt This will search for the pattern in
the sample.txt and will output all the lines in which the pattern is found and
search pattern is highlighted.
grep -r pattern dir It will recursively search for the
pattern in the directory and output the line
from the different file where the
pattern is found.
Example: grep –r
Patel student This
will search for the pattern Patel in
the student directory.
System
Info Command
date command will Show the current
date and time
cal command will Show current month's calendar
whoami
command will display the current user name in which you are logged in
Comments
Post a Comment