Basic Linux Commands
Basic Linux Commands
Options Description
ls -a list all files including hidden file starting with '.'.
ls -d list directories - with ' */'.
ls -l list with long format - show permissions.
ls -F Append indicator (one of */=>@|) to entries.
ls -lh This command will show you the file sizes in human readable format.
ls -r list in reverse order.
ls -i list file's inode(index) number.
ls -ltr View Reverse Output Order by Date.
ls -t sort by time & date.
ls -n It is used to print group ID and owner ID instead of their names.
ls -m A list of entries separated by commas should fill the width.
ls -g
This allows you to exclude the owner and group information columns.
3. Cd Change directory
4. Echo file name ---- to create the file
5. Cat > file name --- to write the contents , press ctrl+d to get
out
6. Touch- to create a file and change the timetamp of file with various
options
Touch filenew{1..10}
Touch filenew{a..e}
7. mkdir & rmdir — Use the mkdir command when you need to create a folder
or a directory.
For example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”.
Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can
type “mkdir DIY\ Hacking”.
8.Use rmdir to delete a directory. But rmdir can only be used to delete an empty
directory.
10. cp — Use the cp command to copy files through the command line.
The first is the location of the file to be copied, the second is where to copy.
11. mv — Use the mv command to move files through the command line.
We can also use the mv command to rename a file.
For example, if we want to rename the file “text” to “new”, we can use “mv text new”.
12. grep: The 'grep' command stands for "global regular expression print".
grep command filters the content of a file which makes our search easy.
It is a command-line utility to search plain-text data groups for lines that are the same
as a regular expression. The name "grep" comes from the command, i.e., ed, which
contains the same effect. Originally, grep was designed for the Unix operating system,
but it became available for every Unix-like system later and a few others like OS 9.
The grep filter finds a file for a specific character pattern and shows every line that
includes that pattern. Characters should be in quotation marks if they occur in the
pattern parameter with a special meaning for the shell. Usually, we must enclose the
whole pattern in one quotation mark if the pattern parameter is not a common string.
In an expression like [a-z], the minus sign (-) cml describes a range based on the current
collating order. A collating order may specify equivalent classes in character ranges for
use. The grep command assumes stdin when no files are mentioned.
The pattern is called the regular expression that is found inside the file. The pattern is
restricted regular expressions in the format of the egrep or ed command. The grep
command applies a solid non-deterministic algorithm. It comes in handy when we need
to filter large log files.
Example:
Syntax:
Example:
1. grep 9 marks.txt
grep options
o grep -vM: The 'grep -v' command displays lines not matching to the specified
word.
Syntax:
Example:
1. grep -v 9 marks.txt
13.
13. FIND : The find command is used to search for and locate
a list of files and directories based on the conditions you
specify, matching the arguments.
14. IFCONFIG : The ifconfig command prints an
output when executed without arguments or with the
interface name only. If used with arguments, there is no
output.
Chown command:
The main command for changing ownership is chown. It
allows users to change user and group ownership both
for files and for directories. We’ll go over the chown
syntax below:
chown [OPTION] OWNER[:GROUP] FILE(s)
e.g