You are on page 1of 5

LINUX COMMANDS

Linux Basic Commands

1. Ls
The command ls stands for (List Directory Contents), List the contents of the folder, be it file or
folder, from which it runs.

Syntax: ls [options] [names]

Options:-

Option Description
-a Displays all files
-b Displays nonprinting characters in octal
-c Displays files by timestamp
-C Displays files in a columnar format (default)
-d Displays only directories.
-f Interprets each name as a directory, not a file.
-F Flags filenames.
-g Displays the long format listing, but exclude the owner name.
-i Displays the inode for each file.
-l Displays the long format listing.
-L Displays the file or directory referenced by a symbolic link.
-m Displays the names as a comma-separated list.
-n Displays the long format listing, with GID and UID numbers.
-o Displays the long format listing, but excludes group name.
-p Displays directories with /
-q Displays all nonprinting characters as ?
-r Displays files in reverse order.
-R Displays subdirectories as well.
-t Displays newest files first. (based on timestamp)
-u Displays files by the file access time.
-x Displays files as rows across the screen.
-1 Displays each entry on a line.

Example : ls l (list the content of folder, in long listing fashion.)

1
G.Midhun Kumar
PAGE SOLUTIONS
LINUX COMMANDS

2. History
The history command stands for History (Event) Record, it prints the history of long list of
executed commands in terminal.

3. mkdir
The mkdir (Make directory) command create a new directory with name path. However is the
directory already exists, it will return an error message cannot create folder, folder already
exists.

4. Chmod

The Linux chmod command stands for (change file mode bits). chmod changes the file mode
(permission) of each given file, folder, script, etc.. according to mode asked for.

There exist 3 types of permission on a file (folder or anything but to keep things simple we will be
using file).

Read (r) = 4

Write (w) = 2

Execute (x) = 1

So if you want to give only read permission on a file it will be assigned a value of 4, for write
permission only, a value of 2 and for execute permission only, a value of 1 is to be given. For read
and write permission 4+2 = 6 is to be given, ans so on.

Now permission need to be set for 3 kinds of user and usergroup. The first is owner, then usergroup
and finally world.

5. Cat
The cat stands for (Concatenation). Concatenate (join) two or more plain file and/or print contents
of a file on standard output.

The operator > can be used to combine multiple files into one. The operator >> can be used
to append to an existing file.

2
G.Midhun Kumar
PAGE SOLUTIONS
LINUX COMMANDS

Syntax: cat [options] [files]

OPTIONS :-

Optio
Description
n

-e $ is printed at the end of each line. This option must be used with -v.

-s Suppress messages pertaining to files that do not exist.

Each tab will display as ^I and each form feed will display as ^L. This option must
-t
be used with -v.

-u Output is printed as unbuffered.

-v Display control characters and nonprinting characters


Examples: 1. cat a.txt b.txt c.txt d.txt abcd.txt

2. cat file1

3. cat file1 file2 > all

4. cat file1 >> file2

6. Grep

The grep command allows you to search one file or multiple files for lines that contain a
pattern. Exit status is 0 if matches were found, 1 if no matches were found, and 2 if errors
occurred.

Syntax: grep [options] pattern [files]

OPTIONS :-

Option Description

-b Display the block number at the beginning of each line.

3
G.Midhun Kumar
PAGE SOLUTIONS
LINUX COMMANDS

-c Display the number of matched lines.

-h Display the matched lines, but do not display the filenames.

-i Ignore case sensitivity.

-l Display the filenames, but do not display the matched lines.

-n Display the matched lines and their line numbers.

-s Silent mode.

-v Display all lines that do NOT match.

-w Match whole word.

Example: $ grep -i "the" demo_file

7. Tail:

The tail command displays the last ten lines of the file.

Syntax: tail [options] [file]

OPTIONS :-

Option Description

-f Follow the file as it grows.

-r Displays the lines in the reverse order.

-n[k] Displays the file at the nth item from the end of the file.

+n[k] Displays the file at the nth item from the beginning of the file.

Example: tail -r tech

8. Copy (cp)
The copy stands for (Copy), it copies a file from one location to another location

Example: cp /home/user/Downloads abc.tar.gz /home/user/Desktop

9. Move (mv)
4
G.Midhun Kumar
PAGE SOLUTIONS
LINUX COMMANDS

The mv command moves a file from one location to another location.

Example: mv /home/user/Downloads abc.tar.gz /home/user/Desktop

5
G.Midhun Kumar
PAGE SOLUTIONS

You might also like