Linuxcommands

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

1.

Id Syntax: id
Id command is used to find a user's UID (user ID) or GID (group ID) and other
information in Linux.
The main purpose of id command is to displays the system identifications of a
specified user.

2. Who Syntax: who


The who command prints information about all users who are currently logged in.

3. Who am i Syntax: who am i


The who am i command prints the user name (i.e., login name)
of the owner of the current login session on the monitor screen.

4. Date Syntax: date


Date command is helpful to display date in several formats.
It also allows you to set systems date and time. When you execute date command
without any option, it will display the current date and time.

5. Cal
Display a conveniently-formatted calendar from the command line.
i. Syntax: cal

If no options are given, cal displays the current month at the command line.

ii. Syntax: cal [year]

Display a calendar for that entire year.

Syntax: clear
Clear command is used to clear the screen. The clear command does not affect files
or jobs, it simply clears the clutter from your terminal screen. `CLEAR` doesn't
erase your terminal scroll buffer, so if you need to see something that was on your
screen a while ago, you can still use your mouse wheel to scroll back.

Syntax: pwd
‘pwd‘ stands for ‘Print Working Directory‘. As the name states, command ‘pwd‘
prints the current working directory or simply the directory user is, at present.
It prints the current directory name with the complete path starting from root (/).

Syntax: mkdir directory_name

It is a short for "make directory", mkdir is used to create directories on a file


system. If the specified DIRECTORY does not already exist, mkdir creates it.More
than one DIRECTORY may be specified when calling mkdir.

9. Cd
The cd command is used to change the current directory (i.e., the directory in
which the user is currently working) in Linux and other Unix-like operating
systems.

i. Syntax: cd [directory]

When a directory name is provided, cd changes the current directory to it. When
used without specifying any directory name, cd returns the user to the previous
current directory.

ii. Syntax: cd ..

This command helps the user to change to the parent of the current directory. On
LINUX like operating system parent directory of the current directory is
represented by two consecutive dots.

10. Rmdir
Syntax: rmdir directory_name

The rmdir command is used to remove empty directories in Linux. If a directory


contains files or sub directories, then the rmdir command fails.

Syntax: ls
This command is usually used to view the contents of current directory. So, when
you run this command,
the files and sub-directories included under the current directory will be listed
before you.

Ls: Lists the contents of a directory. List information about the Files (the
current directory by default).

Syntax: ls[OPTIONS]…[FILE]..

ls –a: List all files and folders including hidden file starting with ‘.‘.

ls –F: Using -F option with ls command, will add the ‘/’ Character at the end of
each directory.
ls –r: Using ls -r option with ls command will display files and directories in
reverse order.
2. Cat: The cat (short for “concatenate“) command is one of the most
frequently used command in
Linux/Unix like operating systems. cat command allows us to create single or
multiple files, view contain of file,
concatenate files and redirect output in terminal or files. Syntax: cat [options]
[filenames] [-] [filenames]
cat > filename: Typing the command cat followed by the output redirection operator
and a file name on the same line,
pressing ENTER to move to the next line, then typing some text and
finally pressing ENTER again causes the text to be written to that file. This
command create and open file in writing mode.

Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and
type ‘d‘) to exit.

cat filename: It is used to display the content of a file on the monitor screen.

cat file1 file2: This command is used to concatenate the contents of files. The
contents of each file will be displayed on the monitor screen
(which, again, is standard output, and thus the destination of the output in the
absence of redirection) starting on a new line and
in the order that the file names appear in the command.

tac file1 file2: This command is used to display the contents of files after
concatenating in the order that firstly the contents of last entered file will be
shown and the contents of first entered file will be shown at end.

3. Sort: sort is a simple and very useful command which will rearrange the
lines in a text file so that they are sorted, numerically and alphabetically. By
default, the rules for sorting are:

● lines starting with a number will appear before lines starting with a
letter;

● lines starting with a letter that appears earlier in the alphabet will
appear before lines starting with a letter that appears later in the alphabet;

● lines starting with a lowercase letter will appear before lines starting
with the same letter in uppercase.

Syntax: sort [OPTION]... [FILE]... sort filename: This command sort the contents
of the given file and display it on the monitor screen.

sort file1 file2: This command display the contents on the screen after sorting the
contents of both the files.

4. wc: The wc (word count) command in Unix/Linux operating systems is used to


find out number of newline count, word count, byte and characters count in a files
specified by the file arguments.
wc –l filename: Prints the number of lines in a file.

wc –w filename: Prints the number of words in a file.

wc –c filename: Displays the count of bytes in a file.

5. Head: Print the first 10 lines of each FILE to standard output. With more
than one FILE, precede each with a header giving the file name.

Syntax: head [OPTION]... [FILE]...

head –n filename: Print the first N lines instead of the first 10.

6. Tail: Print the last 10 lines of each FILE to standard output. With more
than one FILE, precede each with a header giving the file name.

Syntax: tail [OPTION]... [FILE]...

tail –n filename: Output the last N lines, instead of the last 10.

7. Grep: The grep command is used to search text or searches the given file for
lines containing a match to the given strings or words. By default, grep displays
the matching lines. Use grep to search for lines of text that match one or many
regular expressions, and outputs only the matching lines.

Syntax: grep [options] PATTERN [FILE...]

grep pattern filename: This command searches the named input FILEs (or standard
input if no files are named, or the file name -is given) for lines containing a
match to the given PATTERN. By default, grep prints the matching lines.

grep –v filename: -v option is used to print inverts the match; that is, it matches
only those lines that do not contain the given word.

You might also like