Linux Basic Commands: ls, mkdir, rm, cd, pwd, cat, touch

ls  command will list all files and directory.

[[email protected] ~]# ls Downloads ks.cfg Pictures Templates
file25 localhost Public

ls -a will list all including hidden files.

[[email protected] ~]# ls -a
. chandu forloop1 Music sedfile
.. .config numbers server .cshrc hst.txt output .ssh
abu data .ICEauthority output1 tcp.txt

mkdir command will help us to create a directory.

[[email protected] ~]# mkdir test

To delete a directory use rm -rf command with directory name.

[[email protected] ~]# rm -rf test

cd <dir_name> command will change to named directory.

[[email protected] ~]# cd data

cd ~ command will change to home directory of current user.

[[email protected] ~]# cd ~
[[email protected] ~]# pwd

cd .. command will change to parent directory of present working directory.

[[email protected] ~]# cd ..
[[email protected] /]# pwd

pwd command will print present working directory

[[email protected] etc]# pwd

rm  command will remove file and it will ask for user confirmation.


[[email protected] ~]# rm file1
rm: remove regular empty file ‘file1’? y

To delete a file without user confirmation will use  -f  option.

[[email protected] ~]# rm -f file1

will use vi editor, cat and touch to create files. touch command will create empty files.

[[email protected] ~]# touch file1

will explain about vi editor in next post, because we have multiple operation to explain in vi editor and now will see cat command operations.

creating and reading file using cat command:

After entering your content to the file, press enter to go next line and then press  ctrl+c  to save and exit from the file.

For reading a file use cat <filename> syntax like below mentioned.

[[email protected] ~]# cat > file2
This is a test file
[[email protected] ~]# cat file2
This is a test file

use the below command to append one file content to another file. In this method it will not remove the existing contents from the file and it will just copy next to the last line.

Even if we doesn’t have file3, it will create automatically and copy the file2 content to the file3

[[email protected] ~]# cat file2 >> file3

using below command will copy the content from two file and will paste it in a single file. to paste the content in existing file use >> symbol instead of >, it will help to paste the two files content without deleting or modifying existing content.

[[email protected] ~]# cat file2 file3 > file4


Leave a Reply

Your email address will not be published. Required fields are marked *