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
Thepwd
is 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,pwd
ignores 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 theP
switch 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
Thecd
command stands for “change directory,” and it allows you to navigate from onedirectoryto another. To navigate to a particular folder withcd
command, pass the folder path as the parameter, like so
$ cd /home/dd/Documents
$ pwd
/home/dd/Documents
With no options, thecd
command 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
Themv
command is a utility command thatmoves files and folders from one location to another. Themv
command 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 casemv
commandsrenamesthe 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 withcd
command.
$ mv a.txt b.txt c.txt some_directory
OR
$ mv *.txt some_directory
By default themv
command overwrites the destination file. To prompt before overwriting the destination file, use the-i
option.
$ mv -i a.txt b.txt
mv: overwrite 'b.txt' ?
4. RM Command
Therm
command is short for "remove." It's used to delete files and directories.Be cautious when you use therm
command 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 therm
command.
$ 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-r
switch, which means to delete all files and folders recursively.
$ rm -r some_directory
To perform deletion safely and interactively, use the-i
switch, which prompts before each delete action is performed.
$ rm -i file.txt
rm: remove regular file ‘file.txt’? y
5. MKDIR command
mkdir
command is "make a directory." To create a directory, pass the name of the directory along withmkdir
command.
$ mkdir test_directory
Sometimes, you need to create a nested directory structure. Rather than creating directories one by one, use the-p
option to create an entire directory structure.
$ mkdir -p dir1/dir2/dir3
$ tree dir1
dir1
└── dir2
└── dir3
If you wantmkdir
to give details of what operation it is performing in the process of creating directories, use the-v
switch.
$ 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
ls
is thelistcommand in Linux, and it shows full list of files or contents of a directory. Just typels
and press theEnter
key. The entire contents of the directory will be shown.
$ ls
Use the-l
switch 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-a
switch 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-d
option. For example, if you usels -l /home
, it will display all the files under/home
directory. But if you want to display the information about the/home
directory then use-ld
option as shown below.
$ ls -ld.