Basic Linux/Unix Commands We should know

Basic Linux/Unix Commands We should know:

 Background

I was a window user, I never thought to use Linux in my life time. But Suddenly it changed my world and I don’t want to go back to the windows because I fell in love with linux
I am not a system admin now but I work on few Linux distribution which made me realized that whoever is going to learn Linux, they should know these basic Linux commands, which will help them to save few times and practice.

1. mkdir:

mkdir stands for make directory i.e. this command is responsible to create directories.

Syntax:

mkdir [FILENAME]

Example:

2. ls:

ls stands for list i.e. list the names of files and directories in current working directory.

Example:

Syntax:

ls [OPTIONS]

There are various options which support ls command. Listing few of them in below.

  • ls -a : list all the files including hidden files. even though it include “.” and “..” files.

  • Example:

  • ls -A : list all the files including hidden files except “.” and “..” files.

Example:

  • ls -r: list the files in descending order name excluding hidden files.

Example:

  • ls -R: list the files recursively and it shows the files inside directories.

Example:

  • ls -l: list the files in long format i.e. name of each file, owner name, group name, size, index number, timestamp, permission etc.

Example:

  • ls -g: list the files in long format but without owner name.

Example:

  • ls -o: list the files in long format but without group name.

Example:

  • ls -s: list the files with their sizes.

Example:

  • ls -S: sort the files with their sizes.

Example:

  • ls -i: list the files with their index numbers.

Example:

  • ls -t: sort the files with time, latest should be at top.

Example:

  • ls -p: append “/” to directories.

Example:

  • ls -d */: list the directories

Example:

  • ls -ltr: we can merge the above command together based on requirements. This is representing that list of all the files in long format, sort the files with modification time, in descending order.

Example:

3. cd:

cd full form is change directory. so it’s used to change the shell directory.

Syntax:

cd [Directory Name]

But while going back to the parent directory of current directory, need to use below commands

cd ..

While going back to the parent’s of parent’s directory, need to use below commands.

cd ../..

Based on the requirements we can add more “..” and “/” after cd command.

Example:

4. lsof:

lsof stands for List Of Open File i.e. this command provide the information of list of opened files and opened for which process.

Syntax:

lsof [OPTIONS][USER NAME]

Example:

  • Provided $lsof -u [USER NAME] command to see the opened file for specific user.

5. watch:

It gives continuous output in full screen mode with 2.0s interval.

Syntax:

watch [command]

Example:

Provided command watch date in below example

5. df:

df stands for disk free i.e. it is used to show information about file system’s total space and available space.

Syntax:

df [OPTION]...[file]...

Example:

  • If no file name is provided then it displays space available and used on all current mounted file systems.

  • If file name is provided then it display space available and used on that particular file.

6. who:

Provides the details of currently logged in user information.

  • Login name of the users
  • Terminal Line Number
  • Login Time of the user
  • Remote hostname of the user

Syntax:

who [OPTIONS]...[FILE]...

Example:

7. wget:
Use to download the files from the server using HTTP,HTTPS,FTP protocols.

Syntax:

wget [OPTIONS]...[FILE]...

Example:

8. w:
Use to see the information of user who is logged in and what they are doing.

The header provide the information of current time, how long system is running, how many users logged in and load average for past 1, 5 and 15 mins.
Other than these it display each user- login name, tty, remote host, login time, idle time, JCPU , PCPU and the command line of their current process.

Syntax:

w [OPTIONS] USER ...

Example:

9. wc:

wc stands for word count i.e. it is used for counting purpose.
It counts the number of lines, number of words, number of characters.

Syntax:

wc [OPTIONS]... [FILE]...

Example:

First column represent number of lines present in specific file, second column represent the number of words present in specific file, third column represent number of character presents and fourth column represents the name of the file.

10. lshw:

lshw stands for list of hardware i.e. it displays details of system’s hardware information. To access this command we should be a super user.

Syntax:

lshw [FORMAT]... [OPTIONS]...

Here format can be html, xml, json, short, businfo.

Example:

  • It provides the full hardware information.

  • It list the hardware info in compact format.

11. man:

man stands for Manual i.e. it is used to display user manual for any command.
It provides details of command which includes : NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, NOTES, FILES, EXAMPLES, AUTHOR, REPORTING BUGS, COPYRIGHT and SEE ALSO.

Syntax:

man[OPTION]... [COMMAND NAME]...

Example:

  • Provided $man lshw command without option and shown the whole manual of the specified command name.

  • Provided $man -w [COMMAND NAME] command with option and shown the location of the manual page for the specified command name.

12. cat:

cat stands for concatenate. It reads data from the files and give their output. It also helps us to create file, view files, concatenate files.

Syntax:

cat[OPTION]... [FILE]...

Example:

  • Provided $cat [file_name] command to get the output whatever is inside the file.

  • Provided cat >[file_name] command to create the file and at the same time you can provide the text inside the file. After that you can exit using Ctrl+D.

13. rm:

rm stands for remove. remove commands can remove the files, directories etc. But by default it doesn’t remove directories. But Be careful of these commands.

Syntax:

rm[OPTION]... [FILE]...

Example:

  • Provided $rm [FILE NAME] command to remove specified file name.

  • $rm -r: remove directories recursively.

  • $rm -f: remove Read only file without permission.

  • $rm -rf. : Force deletion of Current folder and sub folders.

  • $rm -rf/ : Force deletion of Everything in root directory.

  • $rm -rf* : Force deletion of Everything in current directory.

  • $rm -rf [DIRECTORY NAME] : Force deletion of Specified Directory Name.

  • $rmdir [DIRECTORY NAME]: Remove the Specified Directory Name.

14. pwd:

pwd stands for Print Working Directory. It prints path of the working directory, starting from the root.

Syntax:

pwd [OPTION]

Example:

15. mv:

mv stands for Move i.e. it moves file or files or directories from one place to another place.

Syntax:

mv [OPTION] [Source] [Destination]

Example:

  • Provided $mv [file1] [file2] command, which is responsible to rename the file1 to file2 and override the file2 value with file1 value.

  • Provided $mv -b [file1] [file2] command, -b is responsible to take the backup of overridden file value(file2). It creates a backup file with tilde (~) character append with it.

NOTE: You can use --help option with any of the command to know more about the commands.

from Tumblr https://generouspiratequeen.tumblr.com/post/639095919670968320

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s