183 Basic Linux Commands For Beginners: Maczen Technologies
183 Basic Linux Commands For Beginners: Maczen Technologies
Maczen Technologies
Command Description
date date command is used to display the system date and time
date & cal date & cal command is used to display the system date, time and calendar
cal 8 2016 cal 8 2016 command is used to display the August month 2016 year calendar
free free command is used to display the free and used system memory
free -b free -b command is used to display the free and used system memory in bytes
free -k free -k command is used to display the free and used system memory in kilobytes
free -m free -m command is used to display the free and used system memory in megabytes
date -- set 1998-11-02 date -- set 1998-11-02 command is used to set current date as 02 Nov 1988
date -- set 12:11:02 date -- set 12:11:02 command is used to set current time as 12:11:02 IST
shutdown -h now shutdown -h now command is used to power-off the machine immediately
shutdown -h +10 shutdown -h +10 command is used to power-off the machine after 10 minutes
netstat -a netstat -a command is used to display all ports (both TCP and UDP)
netstat -at command is used to display only TCP (Transmission Control Protocol) port
netstat -at
connections
netstat -au command is used to display only UDP (User Datagram Protocol ) port
netstat -au
connections
netstat -I netstat -I command is used to display all active listening ports connections
netstat -It netstat -It command is used to display all active listening TCP ports
netstat -lu netstat -lu command is used to display all active listening UDP ports
netstat -lx netstat -lx command is used to display all active UNIX listening ports
ifconfig ifconfig command is used to display all the active interfaces details
man pwd man pwd command is used to display the manual for the pwd command
kill kill command is used to terminate processes without having to log out or reboot
du du command is used to display the information of disk usage of files and directories
top top command is used to provide a quick overview of the currently running processes
uname -o uname -o command is used to print the name of the operating system
uname --version uname --version command is used to print the version information and exit
logname logname command is used to report the login name of the current user
w command is used to report information about the users currently on the machine and
w
their processes
uptime uptime command is used to display how long the system has been running
ifconfig command is used to view and change the configuration of the network interfaces on
ifconfig
the system
last -1 username command is used to display when the user last logged on and off and
last -1 username
from where
last yourusername last yourusername command is used to list your last logins
date -d fri date -d fri command is used to display What date is it this Friday
date --help date --help command is used to display the usage summary for the date command
service --status-all service --status-all command is used to check the status of all the services
service network status service network status command is used to check the status of the network services
service network start service network start command is used to start the network service
service network stop service network start command is used to stop the network service
service network restart service network start command is used to restart the network service
echo $PWD echo $PWD command is used to print the current working directory
echo $OLDPWD echo $OLDPWD command is used to print the previous working directory
!11 !11 command is used to execute the 11th command in command history
date +%T date +%T command is used to display time in hh: mm: ss
nproc command is used to display the number of processing units available to the current
nproc
process
pstree command is used to display the information about running processes in the form of a
pstree
tree
acpi command is used to display the information about the advanced configuration and
acpi
power Interface
hostid hostid command is used to display the host's numeric ID in hexadecimal format
ss -tup ss -tup command is used to list the active connections to/from system
lsblk command is used to report the information about storage devices such as hard disks,
lsblk
flash drives etc.
lspci command is used to report the information about usb ports, graphics cards, network
lspci
adapters etc.
sudo fdisk -l sudo fdisk -l command is used to display the information about file system partitions
sudo lshw command is used to display the information about hardware components such
sudo lshw
as cpu, disks, memory, usb controllers etc.
echo $? echo $? command is used to display the exit status of previous command
id command is used to display all the information about the current user (user id, username,
id
group id, group name etc.)
whatis ls whatis ls command is used to display a single line description about ls command
cal -3 cal -3 command is used to display last month, current month, and next month calendar
sudo reboot sudo reboot command is used to power off or reboot the system
Command Description
ping google.com command is used to check the network connectivity between host (your
ping google.com
connection) and server (Google server)
useradd "lmartin" useradd "lmartin" command is used to create a new user named lmartin
passwd "lmartin" passwd "lmartin" command is used to assign password for user lmartin
passwd -d lmartin passwd -d lmartin command is used to disable password for user lmartin
factor 20 factor 20 command is used to print the prime factors of the number 20
id lmartin command is used to display all the information about the user "lmartin" (user id,
id lmartin
username, group id, group name etc.)
mkdir files mkdir files command is used to create a new directory named files
rmdir files rmdir files command is used to remove the directory named files
mkdir myfiles files mkdir myfiles files command is used to create two directories named myfiles & files
gzip test.php command is used to compress the file (test.php), so that it take up much less
gzip test.php
space
yum install httpd yum install httpd command is used to install apache in CentOS
apt install httpd apt install httpd command is used to install apache in Ubuntu
yum update httpd yum update httpd command is used to upgrade apache in CentOS
apt update httpd apt update httpd command is used to upgrade apache in Ubuntu
yum remove httpd yum update httpd command is used to uninstall apache in CentOS
apt remove httpd apt update httpd command is used to uninstall apache in Ubuntu
touch test.txt touch test.txt command is used to create a empty file named test.txt
tail test.html tail test.html command is used to print the last 10 lines from the file (test.html)
tail -n N test.html tail -n N test.html command is used to print N number of lines from the file (test.html)
cat test.html cat test.html command is used to examine the contents of the file (test.html)
diff test.html test.php command is used to compare the contents of files (test.html &
diff test.html test.php
test.php) line by line
comm test.html test.php command is used to compare two files (test.html & test.php) line by
comm test.html test.php
line
find test* command is used for searching files (test.txt, test.php, test.html, test.sql, test.js) in
find test*
a directory as well as in its sub-directories
cmp test.txt test.html command is used to perform byte-by-byte comparison of two files
cmp test.txt test.html
(test.txt & test.html)
printf 'Hello World' > test.txt command is used to create a file (test.txt) containing a text
printf 'Hello World' > test.txt
(Hello World)
Command Description
echo 'Hello World' > test.txt command is used to create a file (test.txt) containing a text
echo 'Hello World' > test.txt
(Hello World)
nl test.txt command is used to display the contents of a file (test.txt) and prepends each line
nl test.txt
with line number
stat test.txt stat test.txt command is used to display the detailed status of a file (test.txt)
gunzip test.php gunzip test.php command is used to uncompress the file (test.php) compressed by gzip
mv test.html text.html mv test.html text.html command is used to rename a file named test.html to text.html
cp test.html text.html command is used to copy the contents of test.html file to the text.html
cp test.html text.html
file. If the text.html file doesn't exist, then first it creates one and content is copied to it.
cat * > 0.txt command is used to append the contents of multiple files in a single directory
cat * > 0.txt
into one file (0.txt)
cat 1.txt 2.txt > 0.txt command is used to append the contents of files (1.txt & 2.txt) into one
cat 1.txt 2.txt > 0.txt
file (0.txt)
sed r 1.txt 2.txt 3.txt > 0.txt command is used to append the contents of files (1.txt, 2.txt &
sed r 1.txt 2.txt 3.txt > 0.txt
3.txt) into one file (0.txt)
sed h 1.txt 2.txt 3.txt > 0.txt command is used to append the contents of files (1.txt, 2.txt &
sed h 1.txt 2.txt 3.txt > 0.txt
3.txt) into one file (0.txt)
sed -n p 1.txt 2.txt 3.txt > sed -n p 1.txt 2.txt 3.txt > 0.txt command is used to append the contents of files (1.txt, 2.txt
0.txt & 3.txt) into one file (0.txt)
for i in {1..3}; do cat "$i.txt" for i in {1..3}; do cat "$i.txt" >> 0.txt; done command is used to append the contents of files
>> 0.txt; done (1.txt, 2.txt & 3.txt) into one file (0.txt) using for loop statement
less test.html less test.html command is used to view the contents of a file (test.html)
cksum test.txt command is used to print the CRC checksum and byte count for the file
cksum test.txt
(test.txt)
wc -w test.txt wc -w test.txt command is used to print the number of words in a text file (test.txt)
wc -m test.txt wc -m test.txt command is used to print the number of characters from a text file (test.txt)
wc -L test.txt wc -L test.txt command is used to print the length of the longest line in a file (test.txt)
:q! :q! command is used to quit the vi editor without saving the text
echo "Hello world!" >> 1.txt command is used to create a file (1.txt) containing a text (Hello
World)
echo "Hello world!" >> 1.txt echo "this is 2nd line text" >> 1.txt command is used to add a second line of text (this is 2nd
echo "this is 2nd line text" line text) to the file (1.txt)
>> 1.txt
echo "last line!" >> 1.txt echo "last line!" >> 1.txt command is used to add a third line of text (last line!) to the file
(1.txt)
Command Description
grep hello 1.txt command is used to search a file (1.txt) for a particular pattern of characters
grep hello 1.txt
(hello) and displays the line that contain that pattern
grep -c hello 1.txt command is used to print only a count of the lines that match a pattern of
grep -c hello 1.txt
characters (hello)
userdel lmartin userdel lmartin command is used to delete a user named lmartin
getent passwd command is used to list all local users (with their login name, encrypted
getent passwd password, numerical user ID, numerical group ID, user home directory etc.)
usermod -l martin lmartin command is used to change the name of the user from lmartin to
usermod -l martin lmartin
martin
sudo passwd lmartin sudo passwd lmartin command is used to change the password for a user (lmartin)
passwd -l lmartin passwd -l lmartin command is used to lock the password of a user (lmartin)
passwd -u lmartin passwd -u lmartin command is used to unlock the password of a user (lmartin)
wget wget http://website.com/files/1.txt command is used to download the file (1.txt) from the url
http://website.com/files/1.txt (http://website.com/files/1.txt)
mkdir files
cd files The following commands are used to create an empty file named 1.txt inside a directory
pwd named files
touch 1.txt
passwd -n 90 lmartin command is used to set 90 days for a user (lmartin) to change its
passwd -n 90 lmartin
password
echo $HOME echo $HOME command is used to display the path of the home directory
echo $PATH command is used to list which directories contain scripts for the command line
echo $PATH
to execute
chage -d 0 lmartin command is used to force immediate password expiration for the user
chage -d 0 lmartin
(lmartin)
Command Description
usermod -p "" lmartin command is used to assign a null password instead of an initial
usermod -p "" lmartin
password for the user (lmartin)
head 1.txt command is used to display the first 10 lines of the file (1.txt) to standard output
head 1.txt
eject eject command lets you eject removable media (typically, a CD ROM or floppy disk)
paste -s 1.txt paste -s 1.txt command is used to join all the lines of the file (1.txt)
which date command is used to locate the executable file associated with the date
which date
command
yes linux yes linux command outputs a string (linux) repeatedly until killed
time df command is used to display the disk usage and report how long it took for df
time df
command to execute
sleep 10 command is used to make your terminal pause for 10 seconds before returning
sleep 10
you to the command line
sleep 20s command is used to make your terminal pause for 20 seconds before returning
sleep 20s
you to the command line
sleep 1m command is used to make your terminal pause for 1 minute before returning you
sleep 1m
to the command line
sleep 2h command is used to make your terminal pause for 2 hours before returning you to
sleep 2h
the command line
sleep 2d command is used to make your terminal pause for 2 days before returning you to
sleep 2d
the command line
shutdown -h 18:00 shutdown -h 18:00 command is used to power-off the machine at 6PM
userdel -r lmartin userdel -r lmartin command is used to delete user (lmartin) with home directory
du -sh 1.txt du -sh 1.txt command is used to display the information of disk usage of file (1.txt)
sudo dmidecode -t 16 command is used to display the maximum RAM supported by the
sudo dmidecode -t 16
system
head -5 1.txt head -5 1.txt command is used to display the first 5 lines of the file (1.txt) to standard output
uniq 2.txt uniq 2.txt command is used to report or even delete repeated lines in a file (2.txt)
uniq -c 2.txt command is used to output the number of times a line is repeated in a file
uniq -c 2.txt
(2.txt)
zcat 2.txt.gz command is used to display the content of the gzip compressed text file
zcat 2.txt.gz
(2.txt.gz)