Basic Linux Commands
Tags: linux
Published: 2023-02-02 04:54:42


## sort

**sort command is used to sort the data inside the file.**<br>
If we don't mention any options it will sort the lines which begin with<br>
+ Empty Lines
+ Numerical Values
+ Alphabetical Order

Syntax of sort command
```
sort [ options ] filename
```

These are some of the options used along with sort command
-b &nbsp; &nbsp; &nbsp; &nbsp; To ignore leading spaces
-d &nbsp; &nbsp; &nbsp; &nbsp; To sort in dictionary order
-f &nbsp; &nbsp; &nbsp; &nbsp; Converts all lower case to upper case while comparing
-r &nbsp; &nbsp; &nbsp; &nbsp; To reverse sort
-M &nbsp; &nbsp; &nbsp; To sort according to months

Examples
```
sort -b filename
sort -db filename
```
&nbsp;

## date

**date command is used to display the date and time on the system and also to set the date and time.**

Syntax of date command
```
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
```

Example
To print the date and time

```
date
```

Options with date command
-s &nbsp; &nbsp; &nbsp; &nbsp; To set the date and time
-d &nbsp; &nbsp; &nbsp; &nbsp; To display time described by input string

&nbsp;

## tree

**tree command displays the directories and files in a tree like structure.**

Syntax
```
tree [options]
```

Example
To print the directories and files in tree like structure

```
tree
```

Options used with tree
-a &nbsp; &nbsp; &nbsp; &nbsp; All files are listed
-d &nbsp; &nbsp; &nbsp; &nbsp; Only directories are listed
-f &nbsp; &nbsp; &nbsp; &nbsp; Prints the full path for each file
-o &nbsp; &nbsp; &nbsp; &nbsp; Output to given file istead of stdout

&nbsp;

## wc

**wc command is used to count newlines, words and characters in a file**

Syntax
```
wc [OPTION] [FILE]
```

Example
To print the word count in a file
```
wc filename
```

Options used with wc command
-w &nbsp; &nbsp; &nbsp; &nbsp; Prints word counts
-c &nbsp; &nbsp; &nbsp; &nbsp; Prints character counts
-b &nbsp; &nbsp; &nbsp; &nbsp; Prints byte counts
-l &nbsp; &nbsp; &nbsp; &nbsp; Prints new line counts

&nbsp;

## ping

**ping command is used to check network connection between host and server/host.**
**Along with ping we use ip address of a host or url.**

Syntax
```
ping [options] <destination>
```

Options
-c &nbsp; &nbsp; &nbsp; &nbsp; Stop after count replies
-l &nbsp; &nbsp; &nbsp; &nbsp; Send preload number of packages while waiting replies
-s &nbsp; &nbsp; &nbsp; &nbsp; Use size as number of bytes to be sent
-W &nbsp; &nbsp; &nbsp; Time to wait for response

Example
```
ping -c 3 www.facebook.com
```
&nbsp;

## ifconfig

**Ifconfig  is  used  to  configure the kernel-resident network interfaces.**
**It is used at boot time to set up interfaces as necessary.**
**After that, it is usually only needed when debugging or when system tuning is needed.**

Syntax
```
ifconfig [-a] [-s] [interface]
```

Options
-a &nbsp; &nbsp; &nbsp; &nbsp; Displays all the interfaces available
-s &nbsp; &nbsp; &nbsp; &nbsp; Displays short list instead of details

Example
```
ifconfig -s
```
&nbsp;

## ssh

**ssh is a program for logging into a remote machine and for executing commands on a remote machine.**
**It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network.**

Syntax
```
ssh username host
```

+ username represents the account that is being accessed on the host.
+ host refers to the machine which can be a computer or a router that is being accessed.