Basics of Linux Commands Parts – 1

Linux is operating system. It become more handy to use if you know the commands. If you command then it is piece of cake to use it and perform your task quickly. In this post we will learn few command to start Linux.

1. how to create directory/folder

Syntax: mkdir <directory_name>
Example: mkdir linux

2. how to create nested folder

Syntax: mkdir -p <folder1/folder2/..>
Example: mkdir -p linux/learn

We can create single folder also with above command

Syntax: mkdir -p <folder>
Example: mkdir -p linux

3. Remove empty folder/directory

Syntax: rmdir <folder_name>
Example: rmdir linux

If directory contains files or sub directory then it cannot be delete directly.

4. Remove non-empty directory

Syntax: rm -r <non_empty_dir>
assume linux/learn/rm  is our directory
Example: rm -r linux

We can delete also empty directory with this command rm -r <directory_name>

5. Remove a file

Syntax: rm <filename>
Example: rm abc.txt

To avoid any error while deletion of not exiting file or directory use -f along with command. rm -f abc.txt

6. Navigate b/w folder/directory:

-- One directory back:
cd ..
-- Two step back:
cd ../../
-- Go to particular directory:
cd <path_of_directory>
-- Go to home folder:
cd ~
-- Go to Root folder:
cd /

7. Listing in a directory:

-- List all directory and files:
ls
-- List hidden files along with directory and files:
ls -a
-- List all directory only:
ls -d */
-- Some other way to list with sorted by time:
ls -lt OR ls -lrt

8. Create file

1. Using touch:

touch command will create a empty file.

Syntax: touch <file_name>
Example: touch abcd.txt

2. Using cat

cat command will file if does not exist else append or overwrite the content of file base on command.

Syntax: cat > <file_name>
Example: cat > abc.txt
-- If file not present it will create a file called abc.txt and wait for input. If present
then open the file and overwrite the file with new input

If we want to append the content in file then use cat command with >>

Syntax: cat >> <file_name>
Example: cat >> abc.txt
-- If file not present it will create a file called abc.txt and wait for input. If present
then open the file and append the file content with new input

cat > abc.txt << end or cat >> abc.txt << end

Above command will take input until you enter “end”. Here “end” act eof of inputs, you use anything instead of “end

Leave a Reply