unix command
Linux Lists

Linux Basic Commands:

There are 7 terminals in linux ; 6 terminals are non-GUI and 1 is for GUI access. You can change terminals using Alt+Ctrl+F1- to-F7. Where

Alt+Ctrl+F1 or F7 – GUI

or $startx

Alt+Ctrl+F2

Alt+Ctrl+F3

Alt+Ctrl+F4

Alt+Ctrl+F5

Alt+Ctrl+F6

 

$cal:

  • To view calendar.

Syntax: $cal [option] [date]

Where options are preceded by – or — and used to modify tge behaviour of command.

Options:

-1            single month

-3            displays prev/cur/next monts

-y            current year.

$date:

  • Used to view the current date and time.

$ls:

  • To list out the files & dirs.

Syntax: $ls [options]

Options:               -a            shows hidden files.

-d            shows directories.

-l             list all with details

Eg: $ls –al

To check the particular file properties:

$ls –L <file name>

To check the particular dir properties:

$ls –ld <dir name>

 

$ll:

-views in detail.

Eg; $ll –R

-list recursively for subdirs.

$pwd:

  • Print working directory

$logout:

  • Logout from computer.

$reboot:

  • Restart the computer.

$poweroff:

  • Shutdown the pc.

 

Some points:

  • Linux files are in single root inverted tree structure.
  • File system begins with root ‘/’.
  • Cmds and names are case sensitive.
  • .. means parent dir and . means current dir.

Absolute path and Relative path:

Absolute:

-begins with ‘/’

– gives complete round map to file location.

Eg: /usr/share/doc/abc.htm

Relative:

  • do not begins with ‘/’.
  • Specifies locations relative to current working dirs.

 

Changing directories:

$cd:

Syntax: $cd <dir name>

$cd ..     – goes to previous dir.

$cd         – goes to root dir.

 

Making new directory:

$mkdir:

Syntax:  $mkdir  <dir name>

Eg:          $mkdir  nepal

 

$mkdir nepal india china .. to create multiple directories at a time.

 

To create file in linux:

Files can be created by using any of three methods:

$touch

$cat

$vi

 

$touch:

  • Used to create empty files.

Eg: $touch pkr           -creates file named pkr.

 

$touch /root/Desktop linuxfile_{1..100)        – creates 100 of files at once.

 

 

$cat:

  • is used to view the contents of file as well as create file.

To view content:

$cat <file name>

To create file:

$cat > filename

type the content

press ctrl+d to save file

$cat -n <file name>         To see the file contents with the line number.

#copying:

to copy files or dirs:

$cp [option] <source> <destination>

options

  • r recursively(to copy directories along with its contents)
  • v verbose(to chceck the background process)
  • P copy with permission.

$cp <file1> <file2> <file3>….       to copy multiple files.

#To remove files and directories:

$rmdir [option] <dir name>

  • to remove empty dirs.

$rm [option] <file name>

options:

  • r recursively
  • f forcefully
  • i interactively

$uname -m or $arch            to display the architecture.

$uname -r                                           to show used kernel version.

$file:

  • determine the file types.

Syntax: $file  <file name>

 

the file can be of two types:

#ASCII –               html, text, scripts,source codes.

#binary-               executables, images, videos etc.

 

$less:

  • used to view the long contents of a file according to the user’s wish.

Syntax: $less <file name>

or

$cat <file name> | less

navigation cmds:

g              – top of the file.

G             – bottom of the file.

/text      – search forward text.

?text     – search backward text.

n             –  repeat last search forward direction.

N             – repeat last search opp dir.

q             –  quit

Linux Shell:

shell is an environment or a program for interacting with an operating system. It is not a part of the kernel, but uses the system kernel to execute programs. A program that interprets commands. Allows users to execute cmds by typing them manually at a terminal, or automatically in programs called shell scripts. A shell is not O. S. It is a way to interface with the O.S. And run commands.

Eg: sh, ksh, bash etc.

bash stands for Bourne Again Shell.

Bash is a Unix shell written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (sh). Bash is the successor of ‘sh’. So it has all of the features of the original Bourne shell, plus additionals that make it easier to program with and use from the command line.

Since it is free software, it has been adopted as the default shell on most Linux systems.

 

# file Globbing

The shell is also responsible for file globbing (or dynamic filename generation).

 

  1. Create a test directory and enter it.

mkdir testdir; cd testdir

  1. Create files file1 file10 file11 file2 File2 File3 file33 fileAB filea fileA fileAAA file( file 2 (the last one has 6 characters including a space)

touch file1 file10 file11 file2 File2 File3 touch file33 fileAB filea fileA fileAAA touch “file(” touch “file 2”

  1. List (with ls) all files starting with file

ls file*

  1. List (with ls) all files starting with File

ls File*

  1. List (with ls) all files starting with file and ending in a number.

ls file*[0-9]

  1. List (with ls) all files starting with file and ending with a letter

ls file*[a-z]

  1. List (with ls) all files starting with File and having a digit as fifth character.

ls File[0-9]*

  1. List (with ls) all files starting with File and having a digit as fifth character and nothing else.

ls File[0-9]

  1. List (with ls) all files starting with a letter and ending in a number.

ls [a-z]*[0-9]

  1. List (with ls) all files that have exactly five characters.

ls ?????

  1. List (with ls) all files that start with f or F and end with 3 or A.

ls [fF]*[3A]

  1. List (with ls) all files that start with f have i or R as second character and end in a number.

ls f[iR]*[0-9]

  1. List all files that do not start with the letter F.

ls [!F]*

 

#Tab key

 

history:

bash stores the history of commands that can be used to repeat if needed.

$history

  • displays the list of cmds history.
  • Arrow can be used to recall the commands.
  • Also;

!c            – to repeat the last command started with c.

!!             – to repeat the last command.

!n            – to repeat the command by its number.

 

Shell variables:

in Linux shell there are two types of variables:

  • system variables: created by Linux developers(inbuilt)

defined in the upper case.

 

  • User-Defined variables: created by users.

    Defined in lower case.

Eg:          $echo $HOME

$echo $PATH

 

Getting help:

  • $info <cmd>

eg $info ls

  • $man <cmd>

eg: $man logout

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.