Day 2 Task: Basics linux command

Day 2 Task: Basics linux command

·

4 min read

What is Linux?

Linux is an operating system’s kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “Distros”.

  • Ubuntu Linux

  • Red Hat Enterprise Linux

  • Linux Mint

  • Debian

  • Fedora

Linux is mainly used in servers. Linux servers powers about 90% of the internet. This is because Linux is fast, secure, and free! The main problem of using Windows servers is their cost. Linux servers solve this problem. Most of the viruses in the world run on Windows, but not on Linux

Basic Commands

1. PWD command

Thepwdis short forPresent Working Directory. It's a command-line utility tool that returns the path to the directory you're in at that moment. The output contains the full system path of the current working directory. By default,pwdignores the symbolic links but with a proper option, you can look at the full physical path of the current working directory.

$ cd /home/dd/Pictures
$ pwd
/home/dd/Pictures

Use thePswitch to find the full physical path if you have traversed inside a directory which issymbolically linked.$ pwd -P /home/dd/Pictures/test_dir[cta_inline]

2. CD command

Thecdcommand stands for “change directory,” and it allows you to navigate from onedirectoryto another. To navigate to a particular folder withcdcommand, pass the folder path as the parameter, like so

$ cd /home/dd/Documents
$ pwd
/home/dd/Documents

With no options, thecdcommand changes the working directory to the user’s home directory.

$ cd
$ pwd
/home/dd

Another way of doing the same i.e to navigate to the home directory quickly is to use the~switch.

$ cd ~
$ pwd
/home/dd

You may want to navigate to the previous working directory without typing the entire folder path again.cd -does exactly that.

$ cd /home/dd/Documents
$ pwd
/home/dd/Documents
$ cd -
$ pwd
/home/dd

3. MV Command

Themvcommand is a utility command thatmoves files and folders from one location to another. Themvcommand can move a single file, multiple files, and directories. To move a single file usingmv, pass the name of the file that needs to be moved as a first parameter and the new file name as a second parameter. In this casemvcommandsrenamesthe filename.

$ mv a.txt b.txt
// renames the file a.txt to b.txt
$ mv some_directory new_directory
// renames the folder some_directory to new_directory

To move a group of files to a folder, pass the name of the files followed by the destination folder name withcdcommand.

$ mv a.txt b.txt c.txt some_directory
          OR
$ mv *.txt some_directory

By default themvcommand overwrites the destination file. To prompt before overwriting the destination file, use the-ioption.

$ mv -i a.txt b.txt
mv: overwrite 'b.txt' ?

4. RM Command

Thermcommand is short for "remove." It's used to delete files and directories.Be cautious when you use thermcommand because once a file or directory is deleted, you cannot recover it later.To delete a single file, just pass the name of the file along with thermcommand.

$ rm file.txt

It is also possible to delete multiple files at one go.

$ rm file1.txt file2.txt image.png

To delete a directory, use the-rswitch, which means to delete all files and folders recursively.

$ rm -r some_directory

To perform deletion safely and interactively, use the-iswitch, which prompts before each delete action is performed.

$ rm -i file.txt
rm: remove regular file ‘file.txt’? y

5. MKDIR command

mkdircommand is "make a directory." To create a directory, pass the name of the directory along withmkdircommand.

$ mkdir test_directory

Sometimes, you need to create a nested directory structure. Rather than creating directories one by one, use the-poption to create an entire directory structure.

$ mkdir -p dir1/dir2/dir3
$ tree dir1
dir1
└── dir2
    └── dir3

If you wantmkdirto give details of what operation it is performing in the process of creating directories, use the-vswitch.

$ mkdir -v -p dir_1/dir_2/dir_3
mkdir: created directory 'dir_1'
mkdir: created directory 'dir_1/dir_2'
mkdir: created directory 'dir_1/dir_2/dir_3'

6. LS Command

lsis thelistcommand in Linux, and it shows full list of files or contents of a directory. Just typelsand press theEnterkey. The entire contents of the directory will be shown.

$ ls

Use the-lswitch to show the list of files of the current directory in a long list format.

$ ls -l

In Linux, hidden files start with a.(dot) symbol and are invisible to the regular directory. The-aswitch will list entire contents of current directory including the hidden files.

$ ls -la

Sometimes you may want to get the details of a directory rather than its content. To get the details of a directory, use-doption. For example, if you usels -l /home, it will display all the files under/homedirectory. But if you want to display the information about the/homedirectory then use-ldoption as shown below.

$ ls -ld.