In this tutorial, lets have a look at some commands to play around with the files and directories.
6. touch - This command is used to create empty text files.
You can also create multiple files in a single command.
Eg. touch test1
touch test2 test3
From the above result set it is clear that touch command
created a file called test1 in the present working directory.
*** ls is used to list the files in directory. This would be
discussed later.
7. mkdir - This command is used to create a folder in present
working directory.
Eg. mkdir Test1
It will create a folder Test1 in the present working
directory.
If you want to create the folder at any other location then
you have to specify the path accordingly.
Eg. mkdir Documents/Test2
This command will create a Test2 folder in Documents folder.
8. cd - cd command is used to change the directory.
Eg. cd Test1
It will change the present working directory to
home/Aditya/Test1
9. cat - cat command can be used to create a test file and
add content to it. Also, it can be used to read the contents of an already
existing text file. However, you have to use the > and < operators to use this command.
Eg. cat > test1
When cat command is used with a greater than symbol followed
by a file name, it allows you to add the contents to that file. As displayed in
above example, we added the content to file test1. In order to save the content
and get back to $ prompt, you have to use the keyword combination Ctrl+D.
In order to read the contents of a file you have to use <
sign.
Eg. cat < test1
cat command can also be used to merge the contents of two
files.
Eg. cat > test1
This is test1.
cat > test2
This is test2.
cat test1 test2 > test3
10. mv - mv command is used to rename a file or a folder.
Eg. mv test newtest
The above command renames a file called test with a new name
called newtest.
You can see from the above screenshot that the file called
test has been renamed as newtest.
11. rm - rm command is used to remove the files or
directories.
Eg. rm test1
In above example, rm removes a file called test1.
However, in order to remove a directory we have to use rm
with -r.
Eg. rm -r testdir
In above example we created a directory called testdir and
tried removing is with rm without using -r. we got an error message. Later we
tried to remove the same directory using rm with -r, then we successfully
removed testdir.
12. rmdir - This works same as that of rm -r.
Eg. rmdir testdir
As seen above rmdir and rm -r produces same result.
No comments:
Post a Comment