0% found this document useful (0 votes)
11 views

Important Linux Commands

Uploaded by

blackpanther00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Important Linux Commands

Uploaded by

blackpanther00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Linux Commands

The command-line interface is one of the nearly all well built trademarks of Linux. There
exists an ocean of Linux commands, permitting you to do nearly everything you can be under
the impression of doing on your Linux operating system. Although, this to the end of time
creates a problem: by all of so copious commands accessible to manage, you don't comprehend
where and at which point to fly learning them, especially when you are learner. If you are facing
this problem, and are peering for a painless method to begin your command line journey in
Linux, you've come to the right place, as in this, we will launch you to a hold of well liked
and helpful Linux commands.

Description:

Display system date and time.

Command:

date

Description:

Display calendar.

1
Command:

cal

Description:

Display date, time and calendar.

Command:

date & cal

Description:

Display August month 2016 year calendar.

Command:

cal 8 2016

Description:

2
Used to clear the terminal window.

Command:

clear

Description:

Exit from the terminal window.

Command:

exit

Description:

Display free and used system memory.

Command:

free

3
Description:

Display free and used system memory in bytes.

Command:

free -b

Description:

Display free and used system memory in kilobytes.

Command:

free -k

Description:

Display free and used system memory in megabytes.

Command:

free -m

4
Description:

Change user password.

Command:

passwd

Description:

Power-off the machine.

Command:

shutdown

Description:

Power-off the machine immediately.

Command:

5
shutdown -h now

Description:

Power-off the machine after 10 minutes.

Command:

shutdown -h +10

Description:

Print current working directory.

Command:

echo $PWD

Description:

Print previous working directory.

6
Command:

echo $OLDPWD

Description:

Executes the 11th command in command history.

Command:

!11

Description:

Reveals your command history.

Command:

history

Description:

Power off or reboot the Operating system.

7
Command:

sudo reboot

Description:

Display the IP address of the host.

Command:

ip address

Description:

List the size of files and directories.

Command:

ls -s

Description:

8
View mounted file systems.

Command:

mount

Description:

Display the information of disk usage of files and directories.

Command:

du

Description:

Tells you how long the system has been running.

Command:

uptime

9
Description:

Set current date as 02 Nov 1988.

Command:

date -- set 1998-11-02

Description:

Set current time as 12:11:02 IST.

Command:

date -- set 12:11:02

Description:

View and change the configuration of the network interfaces on the system.

Command:

ifconfig

10
Description:

Lists all files and directories in the present working directory.

Command:

ls

Description:

Report the process information.

Command:

ps

Description:

Display disk usage.

Command:

11
df

Description:

Display disk usage in gigabytes, megabytes, or kilobytes.

Command:

df -H

Description:

Delete every file and every directory.

Command:

rm -r *

Description:

Provides a quick overview of the currently running processes.

12
Command:

top

Description:

The system performs an immediate reboot.

Command:

reboot

Description:

Terminate processes without having to log out or reboot.

Command:

kill

Description:

Change the current working directory.

13
Command:

cd

Description:

Create a new session on the system.

Command:

login

Description:

List open files.

Command:

lsof

Description:

14
List USB devices.

Command:

lsusb

Description:

Check the status of the network services.

Command:

service network status

Description:

Start the network service.

Command:

service network start

15
Description:

Stop the network service.

Command:

service network stop

Description:

Restart the network service.

Command:

service network restart

Description:

Report information about the users currently on the machine and their processes.

Command:

16
Description:

Display the current directory.

Command:

pwd

Description:

Displays CPU architecture information (such as number of CPUs, threads, cores,

sockets, and more).

Command:

lscpu

Description:

Displays the number of processing units available to the current process.

17
Command:

nproc

Description:

The system performs an immediate reboot.

Command:

init 6

Description:

Power-off the machine.

Command:

init 0

Description:

List files by date.

18
Command:

ls -lrt

Description:

Report information about storage devices such as hard disks, flash drives etc.

Command:

lsblk

Description:

Show exit status of previous command.

Command:

echo $?

Description:

19
Lists a few useful info commands.

Command:

info

Description:

Prints current year's calendar.

Command:

cal -y

Description:

Check the status of all the services.

Command:

service --status-all

20
Description:

Display time in hh:mm:ss.

Command:

date +%T

Description:

Tells when the user last logged on and off and from where.

Command:

last -1 username

Description:

Sort files and directories by extension name.

Command:

ls -X

21
Description:

Display the manual for the pwd command.

Command:

man pwd

Description:

Displays information about running processes in the form of a tree.

Command:

pstree

Description:

Resets your terminal.

Command:

22
reset

Description:

Displays What date is it this Friday.

Command:

date -d fri

Description:

Displays the size of each individual file.

Command:

du -a

Description:

Display information about the Advanced configuration and power Interface.

23
Command:

acpi

Description:

Takes you two folders back.

Command:

cd ../..

Description:

Takes you to the previous directory.

Command:

cd -

Description:

Displays a list of shell built-in commands.

24
Command:

help

Description:

Lists your last logins.

Command:

last yourusername

Description:

Create a new directory called myfiles.

Command:

mkdir myfiles

Description:

25
Remove the directory myfiles.

Command:

rmdir myfiles

Description:

Disable password for a specific user "root1".

Command:

passwd -d root1

Description:

Switch to user "root1".

Command:

sudo su root1

26
Description:

Exit from the terminal window.

Command:

logout

Description:

Creates a user "root1".

Command:

useradd "root1"

Description:

Assign password to user "root1".

Command:

passwd "root1"

27
Description:

Repeats the last command.

Command:

!!

Description:

Display Who you are logged in as.

Command:

whoami

Description:

Display the login name of the current user.

Command:

28
logname

Description:

Report the name of the kernel.

Command:

uname

Description:

Print the kernel version.

Command:

uname -v

Description:

Print the operating system.

29
Command:

uname -o

Description:

Report the machine hardware name.

Command:

uname -m

Description:

Print version information and exit.

Command:

uname --version

Description:

Print the kernel release.

30
Command:

uname -r

Description:

Report the network node hostname.

Command:

uname -n

Description:

Display all port connections (both TCP and UDP).

Command:

netstat -a

Description:

31
Display only TCP (Transmission Control Protocol) port connections.

Command:

netstat -at

Description:

Display only UDP (User Datagram Protocol) port connections.

Command:

netstat -au

Description:

Display all active listening ports.

Command:

netstat -I

32
Description:

Display all active listening TCP ports.

Command:

netstat -It

Description:

Display all active listening UDP ports.

Command:

netstat -lu

Description:

Reveal all the information about the current user (user id, username, group id,

group name etc.).

Command:

33
id

Description:

Reveal all the information about the user "root1" (user id, username, group id,

group name etc.).

Command:

id root1

Description:

Print the machine's architecture.

Command:

arch

Description:

Display the list of available fonts.

34
Command:

fc-list

Description:

Create two directories (myfiles, files).

Command:

mkdir myfiles files

Description:

install apache (CentOS).

Command:

yum install httpd

Description:

35
install apache (Ubuntu).

Command:

apt install httpd

Description:

upgrade apache (CentOS).

Command:

yum update httpd

Description:

upgrade apache (Ubuntu).

Command:

apt update httpd

36
Description:

uninstall apache (CentOS).

Command:

yum remove httpd

Description:

uninstall apache (Ubuntu).

Command:

apt remove httpd

Description:

Display usage summary for the command (date).

Command:

date --help

37
Description:

List active connections to/from system.

Command:

ss -tup

Description:

List internet services on a system.

Command:

ss -tupl

Description:

Display all active UNIX listening ports.

Command:

38
netstat -lx

Description:

Display all the active interfaces details.

Command:

ifconfig

Description:

Display information of all network interfaces.

Command:

ifconfig -a

Description:

Compare the contents of two files (1.txt, 2.txt).

39
Command:

diff 1.txt 2.txt

Description:

Tells you how many lines, words, and characters there are in a file (1.txt).

Command:

wc 1.txt

Description:

Compresses file (1.txt), so that it take up much less space.

Command:

gzip 1.txt

Description:

Uncompresses file (1.txt) compressed by gzip.

40
Command:

gunzip 1.txt

Description:

Examine the contents of the file (1.txt).

Command:

cat 1.txt

Description:

Display calendar.

Command:

ncal

Description:

41
Removes the file (1.txt).

Command:

rm 1.txt

Description:

Rename a file named 1.txt to 0.txt.

Command:

mv 1.txt 0.txt

Description:

Replace the contents of 0.txt with that of 1.txt.

Command:

cp 1.txt 0.txt

42
Description:

Create a empty file (test.txt).

Command:

touch test.txt

Description:

Print the last 10 lines of a file (1.txt).

Command:

tail 1.txt

Description:

Print N number of lines from the file (1.txt).

Command:

tail -n N 1.txt

43
Description:

Prints the number of words in a file (1.txt).

Command:

wc -w 1.txt

Description:

Prints the number of characters from a file (1.txt).

Command:

wc -m 1.txt

Description:

Prints the length of the longest line in a file (1.txt).

Command:

44
wc -L 1.txt

Description:

Print information about usb ports, graphics cards, network adapters etc.

Command:

lspci

Description:

View contents of a file (1.txt).

Command:

less 1.txt

Description:

Display calendar (last month, current month, and next month).

45
Command:

cal -3

Description:

Compare the contents of three files (1.txt, 2.txt, 3.txt) line by line.

Command:

diff3 1.txt 2.txt 3.txt

Description:

Compare two files (1.txt, 2.txt) line-by-line.

Command:

comm 1.txt 2.txt

Description:

Perform byte-by-byte comparison of two files (1.txt, 2.txt).

46
Command:

cmp 1.txt 2.txt

Description:

Prints the CRC checksum and byte count for the file "myfiles.txt".

Command:

cksum myfiles.txt

Description:

Append contents of files (1.txt, 2.txt) into one file (0.txt).

Command:

cat 1.txt 2.txt > 0.txt

Description:

47
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).

Command:

sed r 1.txt 2.txt 3.txt > 0.txt

Description:

Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).

Command:

sed h 1.txt 2.txt 3.txt > 0.txt

Description:

Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).

Command:

sed -n p 1.txt 2.txt 3.txt > 0.txt

48
Shortcuts:

| ctrl+c | Halts the current command |


| ctrl+z | Stops the current command |
| | |
| ctrl+d | Logout the current session |
| ctrl+w | Erases one word in the current line |
| | |
| ctrl+u | Erases the whole line |
| ctrl+r | Type to bring up a recent command |

Description:

Writes contents of a file (0.txt) to output, and prepends each line with line

number.

Command:

nl 0.txt

Description:

Create a empty file (test1.txt) inside a directory (test).

49
Command:

mkdir test
cd test
pwd
touch test1.txt

Description:

Gather information about hardware components such as CPU, disks, memory, USB
controllers etc.

Command:

sudo lshw

Description:

Gather information about file system partitions.

Command:

sudo fdisk -l

50
Description:

Displays the line (good morning) in which the string (good) is found in the file

(1.txt).

Command:

grep good 1.txt

Description:

Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt) using for loop.

Command:

for i in {1..3}; do cat "$i.txt" >> 0.txt; done

Description:

Search for files (test.txt, test1.txt, test2.txt, test.php, test.html) in a directory as

well as its sub-directories.

51
Command:

find test*

Description:

Displays status related to a file (1.txt).

Command:

stat 1.txt

###
| Command | Description |
|:-----------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| | |
| a =20; b =64; | |
| print (a + b); | |
| Hit Escape to return to Normal mode. |
| :w hello.py | Save text |
| :q | Quit |
| python hello.py |Print the output:84 |

52
Description:

Download the file (file.txt) from url "http: //website.com/files/file.txt".

Command:

wget http://website.com/files/file.txt

Description:

Display host's numeric ID in hexadecimal format.

Command:

hostid

Description:

Display file type of the file (myfiles.txt).

Command:

file myfiles.txt

53
Description:

Create a file (myfiles.txt) containing a text (Hello World).

Command:

echo 'Hello World' > myfiles.txt

Description:

Create a file (myfiles.txt) containing a text (Hello World).

Command:

printf 'Hello World' > myfiles.txt

Description:

Display IP address of the hostname.

Command:

54
hostname -i

Description:

Add a new line of text to an existing file (1.txt).

Command:

echo "Hello world!" >> 1.txt


echo "this is 2nd line text" >> 1.txt
echo "last line!" >> 1.txt

Description:

Displays a single line description about a command (cal).

Command:

whatis cal

###
| Command | Description |
|:-----------------|-------------: |

55
| vi | Open vi editor |
| i | Go to Insert mode |
| Type some text. | |
| Hit Escape to return to Normal mode. |
| :w test.txt | Save text |
| :q | Quit |
| :q! |Quit without saving |

###
| Command | Description |
|:-----------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| $name = "Paul"; | |
| print "$name"; | |
| Hit Escape to return to Normal mode. |
| :w hello.pl | Save text |
| :q | Quit |
| perl hello.pl |Print the output: Paul |

###
| Command | Description |
|:---------------------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| echo "What is your name?" | |
| read PERSON | |
| echo "Hello, $PERSON" | |
| Hit Escape to return to Normal mode. |
| :w hello.sh | Save text |
| :q | Quit |
| sh hello.sh | Output: |
| | What is your name? |
| | If you enter: Zara Ali |
| | Hello, Zara Ali |

56
Description:

Check the network connectivity between host (your connection) and server

(Google server).

Command:

ping google.com

Description:

Find the location of source/binary file of a command (cal).

Command:

whereis cal

Description:

List the files in the bin directory.

57
Command:

ls /bin

Description:

List the files in the bin directory and the etc directory.

Command:

ls /bin /etc

Description:

Moves the file test.txt to the folder newrepo.

Command:

mv test.txt ./newrepo

Description:

Deletes all the lines in the test.txt containing tue word.

58
Command:

sed -i "/tue/d" test.txt

import subprocess import os

subprocess.call ('linux command') os.system('linux command')

import os

os.system('ls')

import subprocess List all the files and directories in the

current directory
subprocess.call ('ls')

59
What is Linux and why is it so popular?

Whether you know it or not you are already using Linux (the best-known and most-used open
source operating system) every day. From supercomputers to smartphones, the Linux operating
system is everywhere. As an operating system, Linux is a family of open source Unix-like
software based on the Linux kernel - that sits underneath all of the other software on a computer,
receiving requests from those programs and relaying these requests to the computer's hardware.
With regard to careers, it is becoming increasingly valuable to have Linux skills rather than just
knowing how to use Windows. In general, Linux is harder to manage than Windows, but offers
more flexibility and configuration options.

Every desktop computer uses an operating system. The most popular operating systems in use
today are: Windows, Mac OS, and LINUX. Linux is the best-known notoriously reliable and
highly secure open source portable operating system -- very much like UNIX -- that has become
very popular over the last several years -- created as a task done for pleasure by Linus Torvalds -
- computer science student at the University of Helsinki in Finland -- in the early 1990s and later
developed by more than a thousand people around the world.

Linux is fast, free and easy to use, that sits underneath all the other software on a computer −
runs your computer -- handling all interactions between you and the hardware i.e., whether
you're typing a letter, calculating a money budget, or managing your food recipes on your
computer, the Linux operating system (similar to other Operating Systems, such as Windows XP,
Windows 7, Windows 8, and Mac OS X) provides the essential air that your computer breathes.

Linux is the most important technology advancement of the twenty-first century and Licensed
under the General Public License (GPL) that Linux uses ensures that the software will always be
open to anyone and whose source code is open and available for any user to check, which makes
it easier to find and repair vulnerabilities and it power the laptops, development machines and

60
367
servers at Google, Facebook, Twitter, NASA, and New York Stock Exchange, just to name a
few. Linux has many more features to amaze its users such as: Live CD/USB, Graphical user
interface (X Window System) etc.

Why LINUX?

Although Microsoft Windows (which is the most likely the victim of viruses and malware) has
made great improvements in reliability in recent years, it considered less reliable than Linux.
Linux is notoriously reliable and secure and it is free from constant battling viruses and malware
(which may affect your desktops, laptops, and servers by corrupting files, causing slow downs,
crashes, costly repairs and taking over basic functions of your operating system) – and it keep
yourself free from licensing fees i.e., zero cost of entry ... as in free. You can install Linux on as
many reliable computer ecosystems on the planet as you like without paying a cent for software
or server licensing. While Microsoft Windows usually costs between $99.00 and $199.00 USD
for each licensed copy and fear of losing data.

Below are some examples of where Linux is being used today:

 Android phones and tablets


 Servers
 TV, Cameras, DVD players, etc.
 Amazon
 Google
 U.S. Postal service
 New York Stock Exchange

Linux Operating System has primarily three components:

61
368
 Kernel

Kernel is the core part of Linux Operating System and interacts directly with hardware. It is
responsible for all major activities of the Linux operating system.

 System Library

System libraries are special programs using which application programs accesses Kernel's
features.

 System Utility

System Utility programs are responsible to do specialized tasks.

Important features of Linux Operating System:

 Portable
 Open Source
 Multi-User
 Multiprogramming
 Hierarchical File System
 Security

Now Linux (successfully being used by several millions of users worldwide) has grown passed
the stage where it was almost exclusively an academic system, useful only to a handful of people
with a technical background. It provides more than the operating system: there is an entire
infrastructure supporting the chain of effort of creating an operating system, of making and
testing programs for it, of bringing everything to the users, of supplying maintenance, updates
and support and customizations, runs on different platforms including the Intel and Alpha
platform. Today, Linux is ready to accept the challenge of a fast-changing world to do various

62
369
types of operations, call application programs etc. Since the hiring focus is shifting more and
more toward DevOps type skills, a Linux skill set will be the types of things that will make you
very deployable.

"Linus Torvalds, the creator of Linux, is an expert of understatement in his leadership of Linux

development community. When eager programmers would ask him, ‘What part of Linux should I

work on?’ his answer would usually be, ‘Let me know when you find out’ (p.286)."

― Dan Woods, Wikis For Dummies

"Linux is a superbly polished copy of an antique - shinier than the original, perhaps, but still defined by it."

― Jaron Lanier, You Are Not a Gadget

63

You might also like