Basic Linux Command

9 November 2017

inux is a family of free and open-source software operating systems built around the Linux kernel. This blog includes some of the basic commands that are used in unix environment

Present Working Directly(PWD) in Linux

Use the below command to find the present working directory .

pwd

Path in Linux

A path is a unique location of path or directory in Linux .

Linux has two type of path.

Absolute path: It is the full path of a file or a directory from the root directory(/).

Relative Path: It is the path relative to the present working directory .

Listing the files and directories


 ```bash
hduser@Nemo:~/linuxtutorials$ ls
data  file1.txt
hduser@Nemo:~/linuxtutorials$

list all files and directories with Permissions, Date and Time

ls -l

hduser@Nemo:~/linuxtutorials$ ls -l
total 0
drwxrwxr-x 0 hduser hduser 512 Nov  9 18:14 data
-rw-rw-r-- 1 hduser hduser  20 Nov  9 18:12 file1.txt
hduser@Nemo:~/linuxtutorials$

Lists all directories

ls -d /

hduser@Nemo:~/linuxtutorials$ ls -d */
data/  docs/

Display files and directories of a relative path

ls /home
hduser@Nemo:~/linuxtutorials$ ls /home
hduser  nitendragautam

Displays all the files and direcories of home directory

ls ~

hduser@Nemo:~/linuxtutorials$ pwd
/home/hduser/linuxtutorials
hduser@Nemo:~/linuxtutorials$ ls ~
linuxtutorials   start_Apache_Hadoop.bash          

cd command is used to navigate in Linux/Unix system.

cd <directory_path>
cd ~
hduser@Nemo:~/linuxtutorials$ cd ~
hduser@Nemo:~$ pwd
/home/hduser

cd /

hduser@Nemo:~/linuxtutorials/data$ pwd
/home/hduser/linuxtutorials/data
hduser@Nemo:~/linuxtutorials/data$ cd /
hduser@Nemo:/$ pwd
/

Move to previous directory from current directory

cd ..

Move two directories back from current directory

cd ../..

Change from PWD to another directory

cd <Directory Name>

Files and Directory manipulations

Create a directory in Linux

mkdir <Directory Name>**

Create a directory recursively

mkdir -p <Directory1/Directory 2/Directory 3>

-p means progressively creating

mkdir -p /home/hduser/dir1   :Create multiple directory         

deletes file in current path

rm <file name>
:~$rm file1.txt

Forcefully removes everything(Files and directory) in the path

rm -rf <Directory
:~$rm -rf /home/hduser/dir1/dir2

Permissions and Ownership in Linux

Changing Mode in Linux

Below command can be used to change permission of file for protection

chmod {options} filename
  • Option u :user g:group o:other a:all r:read w:write(and delete) x:execute(and access directory) +:add permission -take away permission

Give executable permission to Linux Script

 #making the helloWorld.pl executables 
 hduser@Nemo:~/scriptingSample$ chmod a+x helloworld.pl

Changing file ownership

chown <file permission > <file name> 

VI text editor

~$vi file.txt :Creates File.txt or opens file.txt for editing

It has three modes 3 Modes : Esc mode-Esc button {by default this mode} Insert Mode - pressing ‘i’ button Colon mode -Pressing “Shift +:” Button

In colon mode when seeing : Press “Wq” to save file and exit :q! -for exiting without saving file

Deleting the content with vi or Vim editor

:%d
#where

#: tells vi to go in command mode
#% means all the line
#d : delete

Reference

Linux Tutorials

Share: Twitter Facebook Google+ LinkedIn
comments powered by Disqus