DEV Community

Sivakumar
Sivakumar

Posted on

Your Guide to Basic Linux Commands Day03

cp

This command allows you to copy one file content to another file in the terminal. you can even copy directories in the same method which copies all the source files.

This command also has multiple switches like:
cp -r = this allows you to even copy the subdirectories using recursive option.
cp -i = this switch asks you with a yes/no if there already exists a file with some content that is about to be rewritten by copying

example :
cp file01.txt fileo2.txt
cp -r dir01 dir02
cp -i file01.txt file02.txt

mv

To rename a file or move it to another location , you can use this mv command.you can also use this command to rename directories as well.

This command has a single switch -i that asks a yes/no before overwriting a file.

example:
mv -i demo.txt file01.txt

Working with file contents

The following commands we are going to take a look at will cover about performing actions on a file like reading, modifying, etc..

head

head command will show the first 10 lines of a file. You can also provide it with a n number to show that n number of lines of a line or -cn will show n number of bytes.

example:
head file01.txt
head -15 file01.txt
head -c15 file01.txt

tail

This command is very similar to that of the head command and will show the last ten lines of a file. This command has also the same switches.

example:
tail file86.txt
tail -15 file86.txt
tail -c15 file86.txt

Wrapping up

These are the commands I learned today. I will share about the cat command in the next blog since it contains so many different functions and variations

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.