Important Linux Commands
Important 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:
Command:
date
Description:
Display calendar.
1
Command:
cal
Description:
Command:
Description:
Command:
cal 8 2016
Description:
2
Used to clear the terminal window.
Command:
clear
Description:
Command:
exit
Description:
Command:
free
3
Description:
Command:
free -b
Description:
Command:
free -k
Description:
Command:
free -m
4
Description:
Command:
passwd
Description:
Command:
shutdown
Description:
Command:
5
shutdown -h now
Description:
Command:
shutdown -h +10
Description:
Command:
echo $PWD
Description:
6
Command:
echo $OLDPWD
Description:
Command:
!11
Description:
Command:
history
Description:
7
Command:
sudo reboot
Description:
Command:
ip address
Description:
Command:
ls -s
Description:
8
View mounted file systems.
Command:
mount
Description:
Command:
du
Description:
Command:
uptime
9
Description:
Command:
Description:
Command:
Description:
View and change the configuration of the network interfaces on the system.
Command:
ifconfig
10
Description:
Command:
ls
Description:
Command:
ps
Description:
Command:
11
df
Description:
Command:
df -H
Description:
Command:
rm -r *
Description:
12
Command:
top
Description:
Command:
reboot
Description:
Command:
kill
Description:
13
Command:
cd
Description:
Command:
login
Description:
Command:
lsof
Description:
14
List USB devices.
Command:
lsusb
Description:
Command:
Description:
Command:
15
Description:
Command:
Description:
Command:
Description:
Report information about the users currently on the machine and their processes.
Command:
16
Description:
Command:
pwd
Description:
Command:
lscpu
Description:
17
Command:
nproc
Description:
Command:
init 6
Description:
Command:
init 0
Description:
18
Command:
ls -lrt
Description:
Report information about storage devices such as hard disks, flash drives etc.
Command:
lsblk
Description:
Command:
echo $?
Description:
19
Lists a few useful info commands.
Command:
info
Description:
Command:
cal -y
Description:
Command:
service --status-all
20
Description:
Command:
date +%T
Description:
Tells when the user last logged on and off and from where.
Command:
last -1 username
Description:
Command:
ls -X
21
Description:
Command:
man pwd
Description:
Command:
pstree
Description:
Command:
22
reset
Description:
Command:
date -d fri
Description:
Command:
du -a
Description:
23
Command:
acpi
Description:
Command:
cd ../..
Description:
Command:
cd -
Description:
24
Command:
help
Description:
Command:
last yourusername
Description:
Command:
mkdir myfiles
Description:
25
Remove the directory myfiles.
Command:
rmdir myfiles
Description:
Command:
passwd -d root1
Description:
Command:
sudo su root1
26
Description:
Command:
logout
Description:
Command:
useradd "root1"
Description:
Command:
passwd "root1"
27
Description:
Command:
!!
Description:
Command:
whoami
Description:
Command:
28
logname
Description:
Command:
uname
Description:
Command:
uname -v
Description:
29
Command:
uname -o
Description:
Command:
uname -m
Description:
Command:
uname --version
Description:
30
Command:
uname -r
Description:
Command:
uname -n
Description:
Command:
netstat -a
Description:
31
Display only TCP (Transmission Control Protocol) port connections.
Command:
netstat -at
Description:
Command:
netstat -au
Description:
Command:
netstat -I
32
Description:
Command:
netstat -It
Description:
Command:
netstat -lu
Description:
Reveal all the information about the current user (user id, username, group id,
Command:
33
id
Description:
Reveal all the information about the user "root1" (user id, username, group id,
Command:
id root1
Description:
Command:
arch
Description:
34
Command:
fc-list
Description:
Command:
Description:
Command:
Description:
35
install apache (Ubuntu).
Command:
Description:
Command:
Description:
Command:
36
Description:
Command:
Description:
Command:
Description:
Command:
date --help
37
Description:
Command:
ss -tup
Description:
Command:
ss -tupl
Description:
Command:
38
netstat -lx
Description:
Command:
ifconfig
Description:
Command:
ifconfig -a
Description:
39
Command:
Description:
Tells you how many lines, words, and characters there are in a file (1.txt).
Command:
wc 1.txt
Description:
Command:
gzip 1.txt
Description:
40
Command:
gunzip 1.txt
Description:
Command:
cat 1.txt
Description:
Display calendar.
Command:
ncal
Description:
41
Removes the file (1.txt).
Command:
rm 1.txt
Description:
Command:
mv 1.txt 0.txt
Description:
Command:
cp 1.txt 0.txt
42
Description:
Command:
touch test.txt
Description:
Command:
tail 1.txt
Description:
Command:
tail -n N 1.txt
43
Description:
Command:
wc -w 1.txt
Description:
Command:
wc -m 1.txt
Description:
Command:
44
wc -L 1.txt
Description:
Print information about usb ports, graphics cards, network adapters etc.
Command:
lspci
Description:
Command:
less 1.txt
Description:
45
Command:
cal -3
Description:
Compare the contents of three files (1.txt, 2.txt, 3.txt) line by line.
Command:
Description:
Command:
Description:
46
Command:
Description:
Prints the CRC checksum and byte count for the file "myfiles.txt".
Command:
cksum myfiles.txt
Description:
Command:
Description:
47
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
Description:
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
Description:
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
48
Shortcuts:
Description:
Writes contents of a file (0.txt) to output, and prepends each line with line
number.
Command:
nl 0.txt
Description:
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:
Command:
sudo fdisk -l
50
Description:
Displays the line (good morning) in which the string (good) is found in the file
(1.txt).
Command:
Description:
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt) using for loop.
Command:
Description:
51
Command:
find test*
Description:
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:
Command:
wget http://website.com/files/file.txt
Description:
Command:
hostid
Description:
Command:
file myfiles.txt
53
Description:
Command:
Description:
Command:
Description:
Command:
54
hostname -i
Description:
Command:
Description:
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:
Command:
whereis cal
Description:
57
Command:
ls /bin
Description:
List the files in the bin directory and the etc directory.
Command:
ls /bin /etc
Description:
Command:
mv test.txt ./newrepo
Description:
58
Command:
import os
os.system('ls')
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.
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
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)."
"Linux is a superbly polished copy of an antique - shinier than the original, perhaps, but still defined by it."
63