DEV Community

Aditya Rawas
Aditya Rawas

Posted on

Linux beginner to pro Commands Part 2

Welcome to another blog of Linux beginner to pro series.

1. Copying a file using cp command

1.1 We use cp command to copy file. Syntax to copy file goes like cp path_of_file path_of_target_file . In below example we are going to copy the file hello.txt to hello2.txt

$ cp hello.txt hello2.txt
Enter fullscreen mode Exit fullscreen mode

In above command content of hello.txt is copied to hello2.txt regardless to the existence of file. If file does not exist file will get generated.

1.2 If you want to copy all the files from the folder to another location use -r option as shown in following command

$ cp -r ~/Downloads/images /tmp/
Enter fullscreen mode Exit fullscreen mode

Above command will copy all the files from images folder and paste in into tmp folder

2. Renaming file / Moving file.

1.1 To move file from one location to another use syntax like mv path_of_file path_of_target_folder.

$ mv ~/Downloads/images/my.png ~/Downloads/
Enter fullscreen mode Exit fullscreen mode

Here in above command I managed to move my.png from images folder to Downloads folder.

1.2 If you want to rename file you can user mv command

$ mv target_file.txt not_target_file.txt
Enter fullscreen mode Exit fullscreen mode

Here I used mv command followed by name of file to rename that too followed by the desired new name of file.

3. echo command.

echo command is simply used to print desire text on terminal

$ echo "Aditya"
Aditya
Enter fullscreen mode Exit fullscreen mode

Event though it looks useless command it can be used with many other commands.
Like creating file. If you want to create file with any content in it you can use redirect > with echo
For example.

aditya@:test$ ls
aditya@:test$ echo "Hello World" > test.txt 
aditya@:test$ ls
test.txt
Enter fullscreen mode Exit fullscreen mode

In above example shows how we created test.txt with "Hello World" in it.

4. cat command

In above example we saw how we created a file with "Hello World" in it, here with cat command we can see the content in it, cat command is used to display content inside the file.
For example.

aditya@:test$ ls
aditya@:test$ echo "Hello World" > test.txt 
aditya@:test$ ls
test.txt
aditya@:test$ cat test.txt 
Hello World
Enter fullscreen mode Exit fullscreen mode

5. man pages

man shows the system’s manual pages. This is the command we use to view the help document (manual page) for
any command. The man pages are organized based on sections, and if the same command is found in many different
sections, only the first one is shown.
The general syntax is man section command. Example man 7 signal.
You can know about different sections below. Press q to quit the program.

6. Creating soft link to a file

Soft link or symbolic links are a special kind of file, which actually point to some other file using either related or
absolute paths. We can create soft links using ln -s command.

aditya@:test$ ln -s test.txt name.txt
aditya@:test$ ls -l
total 4
lrwxrwxrwx 1 aditya aditya  8 May 15 20:53 name.txt -> test.txt
-rw-rw-r-- 1 aditya aditya 12 May 15 19:55 test.txt
Enter fullscreen mode Exit fullscreen mode

7. Extracting a tar file

tar is used to craete and extract archive files to extract file fire following command

$ tar -xzvf archive.tar.gz
hi.txt
hello.java
Enter fullscreen mode Exit fullscreen mode

8. Creating a tar file

To archive files fire following command

aditya@:test$ ls
text1.txt  text2.txt  text3.txt  text4.txt  text.txt
aditya@:test$ tar -czvf  files.tar.gz text1.txt text2.txt text3.txt text.txt text4.txt 
text1.txt
text2.txt
text3.txt
text.txt
text4.txt
aditya@:test$ ls
files.tar.gz  text1.txt  text2.txt  text3.txt  text4.txt  text.txt
Enter fullscreen mode Exit fullscreen mode

9. Becoming root user

root is the superuser that has various access that common users don't to become root user fire following command

$ su -
Password:
Enter fullscreen mode Exit fullscreen mode

10 using sudo command

You can also use sudo privileges i.e root user privileges by add sudo before every command.

$ less /var/log/secure
/var/log/secure: Permission denied
$ sudo less /var/log/secure
[sudo] password for sudo:
... some output
Enter fullscreen mode Exit fullscreen mode

That's it for today! Did you liked this post.? If yes then this is not the end I am going to post more such beginner level command and then later going to go more in details this series is going to make you go from beginner to pro Linux administrator... !!! Stay tuned !!!!!

Aditya Rawas Coffee

Oldest comments (0)